Skip to content

btrfs: add persistent scrub lifetime and session counters

Torstein Eide linux-btrfs 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5btrfs: uapi: introduce on-disk scrub stats iteminclude/uapi/linux/btrfs_tree.h+34 -00 replies
2/5btrfs: add in-memory scrub lifetime and session fieldsfs/btrfs/fs.h fs/btrfs/volumes.h+84 -00 replies
3/5btrfs: persist scrub lifetime stats to the device treefs/btrfs/disk-io.c fs/btrfs/transaction.c fs/btrfs/volumes.c+248 -20 replies
4/5btrfs: hook scrub session tracking into btrfs_scrub_dev()fs/btrfs/scrub.c+16 -00 replies
5/5btrfs: expose scrub lifetime and session counters via sysfsfs/btrfs/sysfs.c fs/btrfs/sysfs.h+589 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] btrfs: add persistent scrub lifetime and session counters

From: Torstein Eide <[email protected]>

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(-)
Signature · 1 line
2.48.1