]> git.hungrycats.org Git - linux/commitdiff
btrfs: stripe_alloc: trace why padding declined, at the moment it declined
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sat, 19 Sep 2026 17:17:51 +0000 (13:17 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 23:37:48 +0000 (18:37 -0500)
The counters say how often padding refused and broadly why, but not what
the run looked like when it happened, and reconstructing that from the
extent tree afterwards cannot distinguish "the stripe was already
allocated when this write arrived" from "it was allocated shortly after".
Those want different fixes, so record the decision where it is made.

Also count the second refusal, which had no counter at all: the oracle can
allow padding and the sector walk still refuse, because a sector below the
frontier is not covered by this write.  That is the case where another
allocation shares the stripe and its data is not in this rbio -- a
different thing from the oracle finding the whole stripe allocated.

The tracepoint carries the stripe, how much of it this write covers, the
refusal reason, and the run's start/end/frontier/inflight, so a trace says
directly whether the frontier had already run past the stripe when the
write showed up.

[zygo: 7.3 port: 7.3 has no per-chunk stripe length (map->stripe_len,
map->stripe_shift, two-argument btrfs_stripe_nr_to_offset()), context
adjusted to BTRFS_STRIPE_LEN; the change itself is unchanged]

Assisted-by: Claude:claude-fable-5
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/fs.h
fs/btrfs/raid56.c
include/trace/events/btrfs.h

index 0365faa1c0cf15ccc1983db674b90efa335e066c..c512b2a30b52056c2c4de276ba369c48ce127892 100644 (file)
@@ -971,7 +971,8 @@ bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
  */
 bool btrfs_stripe_run_pad_start(struct btrfs_fs_info *fs_info,
                                u64 stripe_start, u64 stripe_len,
-                               u64 *pad_from)
+                               u64 *pad_from,
+                               struct btrfs_stripe_pad_info *info)
 {
        struct btrfs_block_group *bg;
        struct btrfs_open_stripe_run *run;
@@ -979,6 +980,11 @@ bool btrfs_stripe_run_pad_start(struct btrfs_fs_info *fs_info,
        unsigned long flags;
        bool ret = false;
 
+       if (info) {
+               memset(info, 0, sizeof(*info));
+               info->reason = BTRFS_STRIPE_PAD_NO_RUN;
+       }
+
        if (list_empty_careful(&fs_info->open_stripe_bgs)) {
                atomic64_inc(&fs_info->stripe_park_stats.pad_decline_no_run);
                return false;
@@ -993,6 +999,13 @@ bool btrfs_stripe_run_pad_start(struct btrfs_fs_info *fs_info,
        list_for_each_entry(run, &bg->open_stripe_runs, list) {
                if (stripe_start < run->start || stripe_start >= run->end)
                        continue;
+               if (info) {
+                       info->run_start = run->start;
+                       info->run_end = run->end;
+                       info->run_offset = run->offset;
+                       info->inflight_bytes = run->inflight_bytes;
+                       info->reason = BTRFS_STRIPE_PAD_OK;
+               }
                if (run->offset > stripe_start &&
                    run->offset < stripe_start + stripe_len) {
                        *pad_from = run->offset;
@@ -1004,9 +1017,13 @@ bool btrfs_stripe_run_pad_start(struct btrfs_fs_info *fs_info,
                         * and the write is waiting on a neighbour's data.
                         */
                        decline = &fs_info->stripe_park_stats.pad_decline_live;
+                       if (info)
+                               info->reason = BTRFS_STRIPE_PAD_LIVE;
                } else {
                        /* The frontier has not reached the stripe at all. */
                        decline = &fs_info->stripe_park_stats.pad_decline_unallocated;
+                       if (info)
+                               info->reason = BTRFS_STRIPE_PAD_UNALLOCATED;
                }
                break;
        }
index 8011c070891e7d09275a526b4e8531cce0c11b43..f3f5222b78fff325131d66a806e572f393b90759 100644 (file)
@@ -442,9 +442,30 @@ void btrfs_wake_open_stripe_waiters(struct btrfs_fs_info *fs_info);
 bool btrfs_stripe_in_open_run(struct btrfs_fs_info *fs_info, u64 logical);
 bool btrfs_stripe_run_range_usable(struct btrfs_block_group *bg,
                                   u64 run_start, u64 *run_len);
+/*
+ * Why padding could or could not proceed, and the run state it was decided
+ * against, for the pad-decline trace.
+ */
+enum btrfs_stripe_pad_reason {
+       BTRFS_STRIPE_PAD_OK = 0,
+       BTRFS_STRIPE_PAD_NO_RUN,        /* no open run covers the stripe */
+       BTRFS_STRIPE_PAD_LIVE,          /* frontier past the stripe: all allocated */
+       BTRFS_STRIPE_PAD_UNALLOCATED,   /* frontier has not reached the stripe */
+       BTRFS_STRIPE_PAD_UNCOVERED,     /* a sector below the frontier is not covered */
+};
+
+struct btrfs_stripe_pad_info {
+       u64 run_start;
+       u64 run_end;
+       u64 run_offset;                 /* the allocation frontier */
+       u64 inflight_bytes;
+       u8 reason;
+};
+
 bool btrfs_stripe_run_pad_start(struct btrfs_fs_info *fs_info,
                                u64 stripe_start, u64 stripe_len,
-                               u64 *pad_from);
+                               u64 *pad_from,
+                               struct btrfs_stripe_pad_info *info);
 int btrfs_stripe_alloc_check_support(struct btrfs_fs_info *fs_info);
 int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info);
 void btrfs_disable_stripe_alloc(struct btrfs_fs_info *fs_info);
index cf062f8aad12ddae2c57d81d1c6f9c2b3caa740b..c355e9c65da06c73e418f1e331137e86da6257df 100644 (file)
@@ -833,6 +833,12 @@ struct btrfs_fs_info {
                atomic64_t pad_decline_live;
                atomic64_t pad_decline_no_run;
                atomic64_t pad_decline_unallocated;
+               /*
+                * Oracle allowed padding, but a sector below the frontier is
+                * not covered by this write: another allocation shares the
+                * stripe.
+                */
+               atomic64_t pad_decline_uncovered;
        } stripe_park_stats;
        /*
         * Park deadlines, ms (sysfs); 0 disables parking for that class.  See
index 887ff3776ebd558c0ad5dcc15de4b83bf4aaea55..70c8f5a8625d596b7698d51391fe354d1be47cc2 100644 (file)
@@ -2742,20 +2742,40 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
        const u64 stripe_start = rbio->bioc->full_stripe_logical;
        const u32 sectorsize = fs_info->sectorsize;
        const u64 stripe_len = (u64)rbio->nr_data * BTRFS_STRIPE_LEN;
-       u64 pad_from;
+       struct btrfs_stripe_pad_info info;
+       const u32 total = rbio->nr_data * rbio->stripe_nsectors;
+       u64 pad_from = 0;
+       u32 covered = 0;
        int i;
 
        if (!btrfs_test_opt(fs_info, STRIPE_ALLOC))
                return false;
        if (!btrfs_stripe_run_pad_start(fs_info, stripe_start, stripe_len,
-                                       &pad_from))
+                                       &pad_from, &info)) {
+               trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
+                                              stripe_len, pad_from, 0, total,
+                                              info.run_start, info.run_end,
+                                              info.run_offset,
+                                              info.inflight_bytes,
+                                              info.reason);
                return false;
+       }
 
        /* Populate bio_paddrs so covered sectors are visible below. */
        index_rbio_pages(rbio);
 
-       /* Every data sector this rbio does not cover must be paddable. */
-       for (i = 0; i < rbio->nr_data * rbio->stripe_nsectors; i++) {
+       /*
+        * Every data sector this rbio does not cover must be paddable.  A
+        * sector below the frontier is allocated to someone else and this
+        * write does not carry its data, so padding would destroy it: that
+        * is a distinct refusal from the oracle's, and it is the one that
+        * says another writer's allocation shares this stripe.
+        */
+       for (i = 0; i < total; i++)
+               if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
+                       covered++;
+
+       for (i = 0; i < total; i++) {
                const int stripe_nr = i / rbio->stripe_nsectors;
                const int sectornr = i % rbio->stripe_nsectors;
                u64 logical = stripe_start + stripe_nr * BTRFS_STRIPE_LEN +
@@ -2763,8 +2783,19 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
 
                if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
                        continue;
-               if (logical < pad_from)
+               if (logical < pad_from) {
+                       atomic64_inc(&fs_info->stripe_park_stats.pad_decline_uncovered);
+                       info.reason = BTRFS_STRIPE_PAD_UNCOVERED;
+                       trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
+                                                      stripe_len, pad_from,
+                                                      covered, total,
+                                                      info.run_start,
+                                                      info.run_end,
+                                                      info.run_offset,
+                                                      info.inflight_bytes,
+                                                      info.reason);
                        return false;
+               }
        }
 
        if (alloc_rbio_data_pages(rbio) < 0)
index e1af4dd8287cec1423da5889e4bb0aca84627400..db541d70e964098279fec6e51b1fe6cbcf186117 100644 (file)
@@ -3299,6 +3299,50 @@ DEFINE_EVENT(btrfs__space_info_update, update_bytes_stripe_unusable,
        TP_ARGS(fs_info, sinfo, old, diff)
 );
 
+TRACE_EVENT(btrfs_stripe_pad_decline,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info, u64 full_stripe,
+                u64 stripe_len, u64 pad_from, u32 covered, u32 total,
+                u64 run_start, u64 run_end, u64 run_offset, u64 inflight,
+                u8 reason),
+
+       TP_ARGS(fs_info, full_stripe, stripe_len, pad_from, covered, total,
+               run_start, run_end, run_offset, inflight, reason),
+
+       TP_STRUCT__entry_btrfs(
+               __field(        u64,    full_stripe     )
+               __field(        u64,    stripe_len      )
+               __field(        u64,    pad_from        )
+               __field(        u64,    run_start       )
+               __field(        u64,    run_end         )
+               __field(        u64,    run_offset      )
+               __field(        u64,    inflight        )
+               __field(        u32,    covered         )
+               __field(        u32,    total           )
+               __field(        u8,     reason          )
+       ),
+
+       TP_fast_assign_btrfs(fs_info,
+               __entry->full_stripe    = full_stripe;
+               __entry->stripe_len     = stripe_len;
+               __entry->pad_from       = pad_from;
+               __entry->run_start      = run_start;
+               __entry->run_end        = run_end;
+               __entry->run_offset     = run_offset;
+               __entry->inflight       = inflight;
+               __entry->covered        = covered;
+               __entry->total          = total;
+               __entry->reason         = reason;
+       ),
+
+       TP_printk_btrfs(
+"full_stripe=%llu len=%llu covered=%u/%u reason=%u pad_from=%llu run=[%llu,%llu) frontier=%llu inflight=%llu",
+                 __entry->full_stripe, __entry->stripe_len,
+                 __entry->covered, __entry->total, __entry->reason,
+                 __entry->pad_from, __entry->run_start, __entry->run_end,
+                 __entry->run_offset, __entry->inflight)
+);
+
 DECLARE_EVENT_CLASS(btrfs_raid56_bio,
 
        TP_PROTO(const struct btrfs_raid_bio *rbio,