]> git.hungrycats.org Git - linux/commit
btrfs: stripe_alloc: back off stripe reclaim after repeated ENOSPC
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 08:02:52 +0000 (04:02 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:16:29 +0000 (21:16 -0500)
commitc42db3e3fd32cba1496e91508bc185fc18cfcddd
tree605548667d20c1e6e7292c368f1d23b819ef21b9
parent7cb7aa4bdf12740eee4bb7f7ef501e64e0a12a04
btrfs: stripe_alloc: back off stripe reclaim after repeated ENOSPC

The reclaim worker backs off a space_info after repeated -ENOSPC failures.
Under stripe_alloc two more paths queue trapped groups, the commit-time
rescan and the cleaner tick, every five minutes each; have them honour the
backoff too, and have the reclaim predicate require room for relocation's
up-front metadata reservation as well.  A stripe_reclaim_now request is
still tried during a backoff.

It showed in two ways:

 - The octopus P1 pass (raid5 6 x 3 GiB, misc-next, bhive 2026-10-20):
   with the data space fully allocated and ~2 GiB trapped, reclaim held the
   exclusive operation for over an hour of fsstress and long after it,
   "error relocating chunk ...: -28" repeating (28 attempts, 13 errors in
   one loop), so a resize could not start and the replace failed.  The
   worker sat in a metadata reservation (btrfs_block_rsv_refill under
   relocate_block_group): metadata had no room either.

 - reclaim-futile-test.sh (raid5 6 x 1 GiB at the edge, fsstress churn):
   226 reclaim errors in 600 s.  Of the -28 returns, relocation's data
   reservation lost the claimable stripes the room check had counted to
   the concurrent writers.

The room check (claimable stripes in the other groups) is an estimate
taken when the group is queued, and it did not cover metadata: it now
also requires room for relocation's up-front metadata reservation (512
tree blocks, twice RELOCATION_RESERVED_NODES), which the octopus failure
needed.

Tested: reclaim-futile-test.sh measured 226 reclaim errors in 600 s on the
lane without the backoff (the fill-edge shape that loops; it does not loop
on every run).  With it no run logged more than 5 errors per 600 s; in one,
five relocations failed with -ENOSPC and reclaim backed off once
(reclaim_backoffs +1), then resumed.  stripe-reclaim-test and
stripe-reclaim-now-test pass.

Assisted-by: Claude:claude-opus-5-5
fs/btrfs/block-group.c
fs/btrfs/free-space-cache.c