]> git.hungrycats.org Git - linux/commitdiff
btrfs: raid56: expose parking statistics in sysfs
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sat, 19 Sep 2026 17:17:43 +0000 (13:17 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 23:37:45 +0000 (18:37 -0500)
/sys/fs/btrfs/<uuid>/stripe_park_stats reports lifetime counters for
the parking machinery: rbios parked, bytes merged into parked rbios,
and how each park ended (filled to a full stripe, kicked by a waiter or
a settle/retire flush, or expired at its deadline), plus how many
flushed writes were padded to full stripes versus still needing the
RMW read phase.  The filled/kicked/expired split shows directly whether
the deadlines are sized right for a given system -- expired parks that
later reappear as rmw_reads are the batching the window failed to
capture -- so any future retuning (or an adaptive deadline) can argue
from measurements instead of taste.

Assisted-by: Claude:claude-fable-5
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/fs.h
fs/btrfs/raid56.c
fs/btrfs/sysfs.c

index 528982e1d6ec7233dd499c21dd7fa8d041aafd42..874e62bf289b4c62bef82c921fd991e2ee6028b2 100644 (file)
@@ -795,6 +795,20 @@ struct btrfs_fs_info {
        u32 data_chunk_allocations;
        u32 metadata_ratio;
 
+       /*
+        * raid56 parking observability (see rbio_try_park()): lifetime
+        * counters exposed through sysfs stripe_park_stats.
+        */
+       struct {
+               atomic64_t parked;
+               atomic64_t merged_bytes;
+               atomic64_t filled;
+               atomic64_t expired;
+               atomic64_t kicked;
+               atomic64_t rmw_reads;
+               atomic64_t padded;
+       } stripe_park_stats;
+
        /* Private scrub information */
        struct mutex scrub_lock;
        atomic_t scrubs_running;
index bdb858859c22c5fe8c026de6051b8aa5fcf1720b..2faea2718dc44ffba1c665c61157c82b0a1278e1 100644 (file)
@@ -62,6 +62,9 @@
  */
 #define RBIO_BATCH_DONE_BIT    6
 
+/* Set at park time and never cleared: this rbio once parked (stats). */
+#define RBIO_WAS_PARKED_BIT    7
+
 #define RBIO_CACHE_SIZE 1024
 
 #define BTRFS_RBIO_PARK_TIMEOUT_MS     100
@@ -494,6 +497,9 @@ static void steal_rbio(struct btrfs_raid_bio *src, struct btrfs_raid_bio *dest)
 static void merge_rbio(struct btrfs_raid_bio *dest,
                       struct btrfs_raid_bio *victim)
 {
+       if (test_bit(RBIO_PARKED_BIT, &dest->flags))
+               atomic64_add(victim->bio_list_bytes,
+                            &dest->bioc->fs_info->stripe_park_stats.merged_bytes);
        bio_list_merge_init(&dest->bio_list, &victim->bio_list);
        dest->bio_list_bytes += victim->bio_list_bytes;
        /* Also inherit the bitmaps from @victim. */
@@ -823,6 +829,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
 
        spin_lock(&table->parked_lock);
        set_bit(RBIO_PARKED_BIT, &rbio->flags);
+       set_bit(RBIO_WAS_PARKED_BIT, &rbio->flags);
        rbio->park_deadline = jiffies + msecs_to_jiffies(timeout_ms);
        /*
         * Take a reference of our own before publishing: once parked_lock is
@@ -834,6 +841,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
        refcount_inc(&rbio->refs);
        list_add_tail(&rbio->parked_node, &table->parked);
        spin_unlock(&table->parked_lock);
+       atomic64_inc(&fs_info->stripe_park_stats.parked);
        queue_delayed_work(system_percpu_wq, &table->parked_work,
                           msecs_to_jiffies(BTRFS_RBIO_PARK_SCAN_MS));
 
@@ -879,6 +887,7 @@ static void unpark_full_rbio(struct btrfs_raid_bio *rbio)
        }
        rbio_unpark_locked(rbio);
        spin_unlock(&table->parked_lock);
+       atomic64_inc(&rbio->bioc->fs_info->stripe_park_stats.filled);
        start_async_work(rbio, rmw_rbio_work_locked);
 }
 
@@ -912,6 +921,7 @@ void btrfs_flush_parked_rbios(struct btrfs_fs_info *fs_info, u64 start,
 
        list_for_each_entry_safe(rbio, tmp, &flush, parked_node) {
                list_del_init(&rbio->parked_node);
+               atomic64_inc(&fs_info->stripe_park_stats.kicked);
                start_async_work(rbio, rmw_rbio_work_locked);
        }
 }
@@ -941,6 +951,7 @@ static void parked_rbios_timeout_work(struct work_struct *work)
 
        list_for_each_entry_safe(rbio, tmp, &flush, parked_node) {
                list_del_init(&rbio->parked_node);
+               atomic64_inc(&rbio->bioc->fs_info->stripe_park_stats.expired);
                start_async_work(rbio, rmw_rbio_work_locked);
        }
        if (rearm)
@@ -2781,6 +2792,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
        spin_lock(&rbio->bio_list_lock);
        bitmap_set(&rbio->dbitmap, 0, rbio->stripe_nsectors);
        spin_unlock(&rbio->bio_list_lock);
+       atomic64_inc(&fs_info->stripe_park_stats.padded);
        return true;
 }
 
@@ -2833,6 +2845,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
         */
        if (!rbio_is_full(rbio) && !rmw_try_pad_full(rbio) &&
            need_read_stripe_sectors(rbio)) {
+               /* A parked-then-flushed write that still had to read. */
+               if (test_bit(RBIO_WAS_PARKED_BIT, &rbio->flags))
+                       atomic64_inc(&rbio->bioc->fs_info->
+                                    stripe_park_stats.rmw_reads);
                /*
                 * Now we're doing sub-stripe write, also need all data stripes
                 * to do the full RMW.
index b03d35fd53adbc278e4f9c5c91312c5e843ab55e..2d10ad6e2d5e9c0a022dfaf46b48c3c1f99bd493 100644 (file)
@@ -1223,6 +1223,29 @@ static ssize_t btrfs_commit_stats_store(struct kobject *kobj,
 }
 BTRFS_ATTR_RW(, commit_stats, btrfs_commit_stats_show, btrfs_commit_stats_store);
 
+static ssize_t btrfs_stripe_park_stats_show(struct kobject *kobj,
+                                           struct kobj_attribute *a, char *buf)
+{
+       struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+
+       return sysfs_emit(buf,
+               "parked %lld\n"
+               "merged_bytes %lld\n"
+               "filled %lld\n"
+               "kicked %lld\n"
+               "expired %lld\n"
+               "padded %lld\n"
+               "rmw_reads %lld\n",
+               atomic64_read(&fs_info->stripe_park_stats.parked),
+               atomic64_read(&fs_info->stripe_park_stats.merged_bytes),
+               atomic64_read(&fs_info->stripe_park_stats.filled),
+               atomic64_read(&fs_info->stripe_park_stats.kicked),
+               atomic64_read(&fs_info->stripe_park_stats.expired),
+               atomic64_read(&fs_info->stripe_park_stats.padded),
+               atomic64_read(&fs_info->stripe_park_stats.rmw_reads));
+}
+BTRFS_ATTR(, stripe_park_stats, btrfs_stripe_park_stats_show);
+
 static ssize_t btrfs_clone_alignment_show(struct kobject *kobj,
                                struct kobj_attribute *a, char *buf)
 {
@@ -1592,6 +1615,7 @@ static const struct attribute *btrfs_attrs[] = {
        BTRFS_ATTR_PTR(, read_policy),
        BTRFS_ATTR_PTR(, bg_reclaim_threshold),
        BTRFS_ATTR_PTR(, commit_stats),
+       BTRFS_ATTR_PTR(, stripe_park_stats),
        BTRFS_ATTR_PTR(, temp_fsid),
        NULL,
 };