]> git.hungrycats.org Git - linux/commitdiff
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)
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

index 1176b643c8b886805586d0265a4cd150642b6be1..3636b7b9605b420bbd74485676c2850464a9764e 100644 (file)
@@ -4617,7 +4617,8 @@ again:
                 */
                if (((chunk_type & BTRFS_BLOCK_GROUP_DATA) &&
                                        count_data < bctl->data.limit_min)
-                               || ((chunk_type & BTRFS_BLOCK_GROUP_METADATA) &&
+                               || ((chunk_type & (BTRFS_BLOCK_GROUP_METADATA |
+                                                  BTRFS_BLOCK_GROUP_METADATA_REMAP)) &&
                                        count_meta < bctl->meta.limit_min)
                                || ((chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) &&
                                        count_sys < bctl->sys.limit_min)) {