From d2ca55d6f9ccc681663992fb5eafbc8a71d202a3 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sat, 5 Sep 2026 13:55:33 -0400 Subject: [PATCH] btrfs: stripe_alloc: do not re-queue a trapped group for reclaim every commit The reclaim trigger runs at every commit-time rescan, so a group that stayed above the threshold because its relocation could not get space (or was still in progress) was handed to the worker again and again: 258 "relocating block group" messages in 24 minutes on one filesystem while the trapped total moved once. Remember when a group was last queued and leave it alone for five minutes. Assisted-by: Claude:claude-fable-5 --- fs/btrfs/block-group.h | 2 ++ fs/btrfs/free-space-cache.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index dcd418d81c355..44eee7e5e740d 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -292,6 +292,8 @@ struct btrfs_block_group { * (honest f_bavail); the reservation layer is deliberately unchanged. */ u64 stripe_unusable; + /* jiffies when the reclaim trigger last queued this group (stripe_alloc) */ + unsigned long stripe_reclaim_jiffies; /* * Directly measured claimable supply: bytes of fully free, aligned * whole stripes in the free space cache -- exactly what diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index d0657e86c533e..e2ff73e5f46cb 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -3509,6 +3509,8 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg) * move; the worker re-checks with should_reclaim_block_group(). */ if (thresh > 0 && !bg->ro && + (!bg->stripe_reclaim_jiffies || + time_after(jiffies, bg->stripe_reclaim_jiffies + 5 * 60 * HZ)) && bg->stripe_unusable >= mult_perc(bg->length, thresh) && bg->used < mult_perc(bg->length, thresh)) { /* @@ -3532,6 +3534,7 @@ void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *bg) spin_unlock(&ctl->tree_lock); kvfree(freep); if (reclaim) { + bg->stripe_reclaim_jiffies = jiffies ?: 1; spin_lock(&bg->lock); btrfs_mark_bg_to_reclaim(bg); spin_unlock(&bg->lock); -- 2.53.0