From 49f204be223b8bae5dd3d99f86c1ea649ce58aab Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Fri, 17 Oct 2025 16:32:47 +0100 Subject: [PATCH] btrfs: bail out earlier from need_preemptive_reclaim() if we have tickets 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 Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba --- fs/btrfs/space-info.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 53677ecb8c15a..bd206fc300e7f 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -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. -- 2.47.3