From: Torstein Eide <torsteine@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Torstein Eide <torsteine@gmail.com>
Subject: [PATCH 0/5] btrfs: add persistent scrub lifetime and session counters
Date: Sun, 19 Apr 2026 16:26:12 +0200 [thread overview]
Message-ID: <20260419142618.3147763-1-torsteine+linux@gmail.com> (raw)
From: Torstein Eide <torsteine@gmail.com>
btrfs currently exposes scrub progress only via ioctl which returns a
snapshot of a running scrub and nothing once it finishes. There is no
persistent record of what previous scrubs found and no sysfs interface
for monitoring.
This series adds per-device scrub statistics that survive across
unmounts and are exposed via sysfs. A new on-disk item
(BTRFS_SCRUB_STATS_OBJECTID, BTRFS_PERSISTENT_ITEM_KEY, devid) stores
14 __le64 lifetime counters per device in the device tree, following
the same dirty-counter/flush-at-commit pattern as btrfs_dev_stats.
Each device gains an in-memory session snapshot (reset at scrub
start, populated at scrub end) for the most recent run.
The sysfs layout under /sys/fs/btrfs/<UUID>/ and devinfo/<devid>/:
scrub/lifetime/<counter> accumulated totals across all runs
scrub/session/<counter> snapshot of the most recent run
scrub/session/status idle | running | finished | canceled
scrub/session/duration_seconds
scrub/reset write "1" to zero lifetime counters
plan is explaned her: https://github.com/kdave/btrfs-progs/issues/1108
tested with xfstests.
## Result
Bellow is table with results of a destrutive test, with two passes, one `dd` per devices, scrub repeat.
| FILE | Total | Device 1 | Device 2 |
| | Lifetime | Session | Lifetime | Session | Lifetime | Session |
|-----------------------|------------|------------|------------|------------|------------|------------|
| corrected_errors | 28736 | 13120 | 15616 | 0 | 13120 | 13120 |
| csum_discards | 0 | 0 | 0 | 0 | 0 | 0 |
| csum_errors | 28736 | 13120 | 15616 | 0 | 13120 | 13120 |
| data_bytes_scrubbed | 6174015488 | 3087007744 | 3087007744 | 1543503872 | 3087007744 | 1543503872 |
| data_extents_scrubbed | 94208 | 47104 | 47104 | 23552 | 47104 | 23552 |
| duration_seconds | | 1 | | 1 | | 1 |
| last_physical | | | | 2147483648 | | 2126643200 |
| malloc_errors | 0 | 0 | 0 | 0 | 0 | 0 |
| no_csum | 0 | 0 | 0 | 0 | 0 | 0 |
| read_errors | 0 | 0 | 0 | 0 | 0 | 0 |
| status | | finished | | finished | | finished |
| super_errors | 0 | 0 | 0 | 0 | 0 | 0 |
| t_end | | 1776595754 | | 1776595754 | | 1776595754 |
| tree_bytes_scrubbed | 6946816 | 3473408 | 3473408 | 1736704 | 3473408 | 1736704 |
| tree_extents_scrubbed | 424 | 212 | 212 | 106 | 212 | 106 |
| t_start | | 1776595753 | | 1776595753 | | 1776595753 |
| uncorrectable_errors | 0 | 0 | 0 | 0 | 0 | 0 |
| unverified_errors | 0 | 0 | 0 | 0 | 0 | 0 |
| verify_errors | 0 | 0 | 0 | 0 | 0 | 0 |
Torstein Eide (5):
btrfs: uapi: introduce on-disk scrub stats item
btrfs: add in-memory scrub lifetime and session fields
btrfs: persist scrub lifetime stats to the device tree
btrfs: hook scrub session tracking into 'btrfs_scrub_dev()'
btrfs: expose scrub lifetime and session counters via sysfs
fs/btrfs/disk-io.c | 6 +
fs/btrfs/fs.h | 5 +
fs/btrfs/scrub.c | 16 +
fs/btrfs/sysfs.c | 586 ++++++++++++++++++++++++++++++++
fs/btrfs/sysfs.h | 3 +
fs/btrfs/transaction.c | 3 +
fs/btrfs/volumes.c | 239 ++++++++++++-
fs/btrfs/volumes.h | 79 +++++
include/uapi/linux/btrfs_tree.h | 34 ++
9 files changed, 969 insertions(+), 2 deletions(-)
--
2.48.1
next reply other threads:[~2026-04-19 14:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-19 14:26 Torstein Eide [this message]
2026-04-19 14:26 ` [PATCH 1/5] btrfs: uapi: introduce on-disk scrub stats item Torstein Eide
2026-04-19 14:26 ` [PATCH 2/5] btrfs: add in-memory scrub lifetime and session fields Torstein Eide
2026-04-19 14:26 ` [PATCH 3/5] btrfs: persist scrub lifetime stats to the device tree Torstein Eide
2026-04-19 14:26 ` [PATCH 4/5] btrfs: hook scrub session tracking into btrfs_scrub_dev() Torstein Eide
2026-04-19 14:26 ` [PATCH 5/5] btrfs: expose scrub lifetime and session counters via sysfs Torstein Eide
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260419142618.3147763-1-torsteine+linux@gmail.com \
--to=torsteine@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox