Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/5] btrfs: add persistent scrub lifetime and session counters
@ 2026-04-19 14:26 Torstein Eide
  2026-04-19 14:26 ` [PATCH 1/5] btrfs: uapi: introduce on-disk scrub stats item Torstein Eide
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Torstein Eide @ 2026-04-19 14:26 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Torstein Eide

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-19 14:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 14:26 [PATCH 0/5] btrfs: add persistent scrub lifetime and session counters Torstein Eide
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox