]> git.hungrycats.org Git - linux/commitdiff
btrfs: stripe_alloc: log compaction and trapped bytes in the reclaim log
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 20 Oct 2026 17:04:19 +0000 (13:04 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 23:38:00 +0000 (18:38 -0500)
Say in the reclaim debug lines whether a stripe group is being compacted
or relocated, with the trapped bytes the reclaim trigger counted, and
whether it was compacted or relocated.  Without that, stripe-reclaim-test,
which counts reclaims in the log, could not tell automatic compaction from
relocation, and an octopus replace stalled behind a reclaim the log did not
explain.

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

index 9f20424a2d5aaad33ef4adfff9a907d55d20ff6c..0270ff6312c49c5a1eb3b8e8ea80b6bb22791b21 100644 (file)
@@ -4316,8 +4316,10 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
        u64 used;
        u64 reserved;
        u64 old_total;
+       u64 trapped;
        int ret = 0;
        bool compact = false;
+       bool compacted = false;
 
        /*
         * A stripe_alloc group's live extents can only move into
@@ -4463,16 +4465,17 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
        spin_lock(&bg->lock);
        used = bg->used;
        reserved = bg->reserved;
+       /* Trapped as the reclaim trigger counts it. */
+       trapped = bg->stripe_unusable -
+                 min(bg->stripe_unusable, bg->stripe_stranded);
        spin_unlock(&bg->lock);
 
        trace_btrfs_reclaim_block_group(bg);
        btrfs_debug(fs_info,
-"reclaim: relocating block group %llu flags 0x%llx length %llu used %llu reserved %llu",
-                   bg->start, bg->flags,
-                   bg->length, used, reserved);
+"reclaim: %s block group %llu flags 0x%llx length %llu used %llu reserved %llu trapped %llu",
+                   compact ? "compacting" : "relocating", bg->start, bg->flags,
+                   bg->length, used, reserved, trapped);
        if (compact) {
-               bool compacted;
-
                ret = btrfs_compact_chunk(fs_info, bg->start, &compacted);
                /*
                 * Compacted, the group stays: drop our read-only hold.  It
@@ -4511,8 +4514,8 @@ static int btrfs_reclaim_block_group(struct btrfs_block_group *bg, int *reclaime
        spin_unlock(&space_info->lock);
        if (!ret) {
                (*reclaimed)++;
-               btrfs_debug(fs_info, "reclaim: relocated block group %llu",
-                           bg->start);
+               btrfs_debug(fs_info, "reclaim: %s block group %llu",
+                           compacted ? "compacted" : "relocated", bg->start);
        }
 
        return ret;