]> git.hungrycats.org Git - linux/commit
btrfs: give back the limit of queued remap chunks when balance bails out
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:31 +0000 (00:32 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:31 +0000 (00:32 -0500)
commit6cd032e84e26f78ae50022e4b885156cdca277cc
tree0c69da7bfa2317ef0a803d057f2693036476cfb9
parentf792c9df39fbcb95e764aa82c86b6c788cb9cef0
btrfs: give back the limit of queued remap chunks when balance bails out

__btrfs_balance() does not relocate METADATA_REMAP chunks in its chunk
walk: it queues them and balances them all after the walk, in
balance_remap_chunks().  should_balance_chunk() selects them as metadata
chunks, and a metadata limit filter counts them down when it selects
them, like any other chunk.

A pause request ends the walk at the error label, which drops the queue:
the queued chunks are not balanced, but the metadata limit still counts
them.  The balance control stays in memory for the resume, which then
sees the chunks again and finds the limit already used up for them.  For
example, with -mlimit=1 and the remap chunk selected as the one metadata
chunk, a balance paused while it relocates the data chunks below the
remap chunk relocates no metadata chunk at all after the resume.

Add the dropped chunks back to the metadata limit (limit, or limit_max of
a range, whichever should_balance_chunk() counted down) at the error
label.  For the other ways out through the label (cancel, errors) the
balance ends and the count does not matter.

Fixes: 81e5a4551c32 ("btrfs: allow balancing remap tree")
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/volumes.c