btrfs: retry block group reclaim without infinite loop
authorBoris Burkov <boris@bur.io>
Fri, 7 Jun 2024 19:50:14 +0000 (12:50 -0700)
committerDavid Sterba <dsterba@suse.com>
Thu, 13 Jun 2024 18:43:45 +0000 (20:43 +0200)
commit4eb4e85c4f818491efc67e9373aa16b123c3f522
treedd2d04a3cadfbc2fd52d050e8b473d4c8ddddbaf
parentf3a5367c679d31473d3fbb391675055b4792c309
btrfs: retry block group reclaim without infinite loop

If inc_block_group_ro systematically fails (e.g. due to ETXTBUSY from
swap) or btrfs_relocate_chunk systematically fails (from lack of
space), then this worker becomes an infinite loop.

At the very least, this strands the cleaner thread, but can also result
in hung tasks/RCU stalls on PREEMPT_NONE kernels and if the
reclaim_bgs_lock mutex is not contended.

I believe the best long term fix is to manage reclaim via work queue,
where we queue up a relocation on the triggering condition and re-queue
on failure. In the meantime, this is an easy fix to apply to avoid the
immediate pain.

Fixes: 7e2718099438 ("btrfs: reinsert BGs failed to reclaim")
CC: stable@vger.kernel.org # 6.6+
Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c