]> git.hungrycats.org Git - linux/commit
btrfs: count METADATA_REMAP chunks as metadata in the balance limit_min check
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:48 +0000 (00:32 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 11 Nov 2026 05:32:48 +0000 (00:32 -0500)
commit41d5a067d433488dd126dbf744817c2064ea0987
treecceb7e0863d3dbafe1f92256b4c428081f5ffbdc
parent0cfefdef3bcd6581c48de9b736e0673c25fdd9e1
btrfs: count METADATA_REMAP chunks as metadata in the balance limit_min check

should_balance_chunk() already treats a METADATA_REMAP chunk as a
metadata chunk: the metadata type flag selects it, the metadata filters
apply to it, and it is charged against the metadata limit or limit_max
when it is selected, so the remap chunks queued by __btrfs_balance()
stay within the MAX of -mlimit=MIN..MAX.  The counting pass of
__btrfs_balance() also counts it in count_meta.

The limit_min check in the second pass is the only place that tests the
raw METADATA bit, which a METADATA_REMAP chunk does not have.  With
-mlimit=MIN..MAX and fewer than MIN matching metadata chunks, the
balance skips every METADATA chunk, as asked, but still relocates the
METADATA_REMAP chunk.

Test the METADATA_REMAP bit in that check as well, so that remap chunks
count as metadata in both passes and the limit bounds the total number
of block groups relocated.

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