From 95f4aa5bdb240e662428379040099f2f7c4b5f4c Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sat, 19 Sep 2026 13:17:43 -0400 Subject: [PATCH] btrfs: raid56: expose parking statistics in sysfs /sys/fs/btrfs//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 | 14 ++++++++++++++ fs/btrfs/raid56.c | 16 ++++++++++++++++ fs/btrfs/sysfs.c | 24 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 528982e1d6ec7..874e62bf289b4 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -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; diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index bdb858859c22c..2faea2718dc44 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -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. diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index b03d35fd53adb..2d10ad6e2d5e9 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -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, }; -- 2.53.0