]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: increment loop count outside critical section during metadata reclaim
authorFilipe Manana <fdmanana@suse.com>
Fri, 17 Oct 2025 15:54:12 +0000 (16:54 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:09:14 +0000 (22:09 +0100)
In btrfs_preempt_reclaim_metadata_space() there's no need to increment the
local variable that tracks the number of iterations of the while loop
while inside the critical section delimited by the space_info's spinlock.
That spinlock is heavily used by space reservation and flushing code, so
it's desirable to have its critical sections as short as possible.
So move the loop count incremented outside the critical section.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.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/space-info.c

index bd206fc300e7fb5b1416e8f1d3543791450b36cc..2dd9d4e5c2c22cb3f4ea1e369ffed26bf2bdab8c 100644 (file)
@@ -1264,8 +1264,6 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work)
                u64 to_reclaim, block_rsv_size;
                const u64 global_rsv_size = btrfs_block_rsv_reserved(global_rsv);
 
-               loops++;
-
                /*
                 * We don't have a precise counter for the metadata being
                 * reserved for delalloc, so we'll approximate it by subtracting
@@ -1311,6 +1309,8 @@ static void btrfs_preempt_reclaim_metadata_space(struct work_struct *work)
 
                spin_unlock(&space_info->lock);
 
+               loops++;
+
                /*
                 * We don't want to reclaim everything, just a portion, so scale
                 * down the to_reclaim by 1/4.  If it takes us down to 0,