]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: bail out earlier from need_preemptive_reclaim() if we have tickets
authorFilipe Manana <fdmanana@suse.com>
Fri, 17 Oct 2025 15:32:47 +0000 (16:32 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:08:46 +0000 (22:08 +0100)
Instead of doing some calculations and then return false if it turns out
we have queued tickets, check first if we have tickets and return false
immediately if we have tickets, without wasting time on doing those
computations.

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 53677ecb8c15ad236c413c56a2f8daf0439ee37b..bd206fc300e7fb5b1416e8f1d3543791450b36cc 100644 (file)
@@ -937,10 +937,17 @@ static bool need_preemptive_reclaim(const struct btrfs_space_info *space_info)
        u64 thresh;
        u64 used;
 
-       thresh = mult_perc(space_info->total_bytes, 90);
-
        lockdep_assert_held(&space_info->lock);
 
+       /*
+        * We have tickets queued, bail so we don't compete with the async
+        * flushers.
+        */
+       if (space_info->reclaim_size)
+               return false;
+
+       thresh = mult_perc(space_info->total_bytes, 90);
+
        /* If we're just plain full then async reclaim just slows us down. */
        if ((space_info->bytes_used + space_info->bytes_reserved +
             global_rsv_size) >= thresh)
@@ -960,13 +967,6 @@ static bool need_preemptive_reclaim(const struct btrfs_space_info *space_info)
        if (used - global_rsv_size <= SZ_128M)
                return false;
 
-       /*
-        * We have tickets queued, bail so we don't compete with the async
-        * flushers.
-        */
-       if (space_info->reclaim_size)
-               return false;
-
        /*
         * If we have over half of the free space occupied by reservations or
         * pinned then we want to start flushing.