]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
btrfs: only reserve metadata_size for inodes
authorJosef Bacik <josef@toxicpanda.com>
Thu, 22 Aug 2019 19:14:34 +0000 (15:14 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:13 +0000 (14:59 +0200)
Historically we reserved worst case for every btree operation, and
generally speaking we want to do that in cases where it could be the
worst case.  However for updating inodes we know the inode items are
already in the tree, so it will only be an update operation and never an
insert operation.  This allows us to always reserve only the
metadata_size amount for inode updates rather than the
insert_metadata_size amount.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/delalloc-space.c
fs/btrfs/delayed-inode.c

index 62aa18b38a085eae64556949af2cffe81eb4e0ed..391dcb2170985b5aebca46033582e546cc815d6e 100644 (file)
@@ -255,9 +255,16 @@ static void btrfs_calculate_inode_block_rsv_size(struct btrfs_fs_info *fs_info,
 
        lockdep_assert_held(&inode->lock);
        outstanding_extents = inode->outstanding_extents;
-       if (outstanding_extents)
+
+       /*
+        * Insert size for the number of outstanding extents, 1 normal size for
+        * updating the inode.
+        */
+       if (outstanding_extents) {
                reserve_size = btrfs_calc_insert_metadata_size(fs_info,
-                                               outstanding_extents + 1);
+                                               outstanding_extents);
+               reserve_size += btrfs_calc_metadata_size(fs_info, 1);
+       }
        csum_leaves = btrfs_csum_bytes_to_leaves(fs_info,
                                                 inode->csum_bytes);
        reserve_size += btrfs_calc_insert_metadata_size(fs_info,
@@ -282,10 +289,16 @@ static void calc_inode_reservations(struct btrfs_fs_info *fs_info,
 {
        u64 nr_extents = count_max_extents(num_bytes);
        u64 csum_leaves = btrfs_csum_bytes_to_leaves(fs_info, num_bytes);
+       u64 inode_update = btrfs_calc_metadata_size(fs_info, 1);
 
-       /* We add one for the inode update at finish ordered time */
        *meta_reserve = btrfs_calc_insert_metadata_size(fs_info,
-                                               nr_extents + csum_leaves + 1);
+                                               nr_extents + csum_leaves);
+
+       /*
+        * finish_ordered_io has to update the inode, so add the space required
+        * for an inode update.
+        */
+       *meta_reserve += inode_update;
        *qgroup_reserve = nr_extents * fs_info->nodesize;
 }
 
index de87ea7ce84d97ffe52c44d07f3c16b233e502b7..9318cf761a07b81e6c66e0ee3d32c2b34781aaa2 100644 (file)
@@ -612,7 +612,7 @@ static int btrfs_delayed_inode_reserve_metadata(
        src_rsv = trans->block_rsv;
        dst_rsv = &fs_info->delayed_block_rsv;
 
-       num_bytes = btrfs_calc_insert_metadata_size(fs_info, 1);
+       num_bytes = btrfs_calc_metadata_size(fs_info, 1);
 
        /*
         * btrfs_dirty_inode will update the inode under btrfs_join_transaction