]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: fix periodic reclaim condition
authorSun YangKai <sunk67188@gmail.com>
Wed, 14 Jan 2026 03:47:02 +0000 (11:47 +0800)
committerSasha Levin <sashal@kernel.org>
Wed, 4 Mar 2026 12:21:21 +0000 (07:21 -0500)
commit25afd2a1ee4d2d5470dc0945ff412e2625eb867a
treeaf0c2e5e66176fff87edc43345668ca04dc148d7
parentda86ca15d7389ee0b5df08e8f70c39354e6b8a4b
btrfs: fix periodic reclaim condition

[ Upstream commit 19eff93dc738e8afaa59cb374b44bb5a162e6c2d ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/block-group.c
fs/btrfs/space-info.c