btrfs: calculate correct amount of space for delayed reference when evicting
authorFilipe Manana <fdmanana@suse.com>
Tue, 21 Mar 2023 11:13:56 +0000 (11:13 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Apr 2023 16:01:20 +0000 (18:01 +0200)
When evicting an inode, we are incorrectly calculating the amount of space
required for a single delayed reference in case the free space tree is
enabled. We have to multiply by 2 the result of
btrfs_calc_insert_metadata_size(). We should be calculating according to
the size update and space release of the delayed block reserve logic at
btrfs_update_delayed_refs_rsv() and btrfs_delayed_refs_rsv_release().

Fix this by using the btrfs_calc_delayed_ref_bytes() helper at
evict_refill_and_join() instead of btrfs_calc_insert_metadata_size().

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index 912d5f4aafbc19b169a8c85acd18f5134398c39b..2e181a0a6f372f33abbd1722055d0038976b0d91 100644 (file)
@@ -5230,7 +5230,7 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root,
 {
        struct btrfs_fs_info *fs_info = root->fs_info;
        struct btrfs_trans_handle *trans;
-       u64 delayed_refs_extra = btrfs_calc_insert_metadata_size(fs_info, 1);
+       u64 delayed_refs_extra = btrfs_calc_delayed_ref_bytes(fs_info, 1);
        int ret;
 
        /*