]> git.hungrycats.org Git - linux/commit
btrfs: do not write queued remap chunks as processed to the balance item
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:39 +0000 (00:32 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:39 +0000 (00:32 -0500)
commit5bd028df8cd1b1ecb2cd6789304f83a0ffc357fc
tree884a952bba1fd37c64ff4211f16cccca8e59ddbb
parentb3e77dc15afd8a273d24293f5ca7ba9406835848
btrfs: do not write queued remap chunks as processed to the balance item

The balance item gets the remaining limits after each processed chunk
(count_limited_chunk()).  METADATA_REMAP chunks are not processed in the
chunk walk: __btrfs_balance() queues them and balances them after the
walk, but should_balance_chunk() has already counted them down from the
metadata limit when it selected them.  Any limited chunk processed after
that writes the item with the queued chunks counted as done.  If the
balance stops before the end of the walk, by a pause, an unmount or a
crash, the queue is gone, and the balance resumed from the item has too
little left of its metadata limit to balance the chunks it never
balanced: with -mlimit=1..1 and the remap chunk selected as the one
metadata chunk, the resumed balance balances no metadata chunk.

Write the item with the queued chunks added back to the metadata limit
(limit, or limit_max of a range, as should_balance_chunk() counted them).
The in-memory limit is not changed: the walk needs it to stop selecting
chunks once the limit is used up.

Assisted-by: Claude:claude-opus-5-5
fs/btrfs/volumes.c