]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: fix periodic reclaim condition
authorSun YangKai <sunk67188@gmail.com>
Wed, 14 Jan 2026 03:47:02 +0000 (11:47 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Feb 2026 06:54:37 +0000 (07:54 +0100)
commit19eff93dc738e8afaa59cb374b44bb5a162e6c2d
treeec33beb52718f96974d9e9ef7129b1dea8379056
parentde62f138f95eacd71121d9fdc4815cb90a56ccbd
btrfs: fix periodic reclaim condition

Problems with current implementation:

1. reclaimable_bytes is signed while chunk_sz is unsigned, causing
   negative reclaimable_bytes to trigger reclaim unexpectedly

2. The "space must be freed between scans" assumption breaks the
   two-scan requirement: first scan marks block groups, second scan
   reclaims them. Without the second scan, no reclamation occurs.

Instead, track actual reclaim progress: pause reclaim when block groups
will be reclaimed, and resume only when progress is made. This ensures
reclaim continues until no further progress can be made. And resume
periodic reclaim when there's enough free space.

And we take care if reclaim is making any progress now, so it's
unnecessary to set periodic_reclaim_ready to false when failed to reclaim
a block group.

Fixes: 813d4c6422516 ("btrfs: prevent pathological periodic reclaim loops")
CC: stable@vger.kernel.org # 6.12+
Suggested-by: Boris Burkov <boris@bur.io>
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Sun YangKai <sunk67188@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/space-info.c