From fca50874ec2d4978ec70b0aeeba775d2a5214a70 Mon Sep 17 00:00:00 2001 From: Gionatan Danti Date: Tue, 13 Aug 2024 17:29:03 +0200 Subject: [PATCH] ARC statistics reset Fixes https://github.com/openzfs/zfs/issues/16437 This patch introduces a means to reset some ARC statistics without rebooting the machine or reimporting the zfs module. Please note that it currently only resets l2_cksum_bad and l2_io_error Signed-off-by: Gionatan Danti --- man/man4/zfs.4 | 4 ++++ module/zfs/arc.c | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/man/man4/zfs.4 b/man/man4/zfs.4 index 45b6c338aa..96cda6f2d4 100644 --- a/man/man4/zfs.4 +++ b/man/man4/zfs.4 @@ -843,6 +843,10 @@ The target number of bytes the ARC should leave as free memory on the system. If zero, equivalent to the bigger of .Sy 512 KiB No and Sy all_system_memory/64 . . +.It Sy zfs_arc_stats_reset Ns = Ns Sy 0 Ns | Ns 1 Pq int +Reset ARC statistics. +Note: it currently resets L2ARC bad checksum and error stats only. +. .It Sy zfs_autoimport_disable Ns = Ns Sy 1 Ns | Ns 0 Pq int Disable pool import at module load by ignoring the cache file .Pq Sy spa_config_path . diff --git a/module/zfs/arc.c b/module/zfs/arc.c index d01bf0947d..506d881e21 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -944,6 +944,9 @@ static uint64_t l2arc_trim_ahead = 0; static int l2arc_rebuild_enabled = B_TRUE; static uint64_t l2arc_rebuild_blocks_min_l2size = 1024 * 1024 * 1024; +/* zfs_arc_stats_reset : reset ARC statistics */ +static int zfs_arc_stats_reset = 0; + /* L2ARC persistence rebuild control routines. */ void l2arc_rebuild_vdev(vdev_t *vd, boolean_t reopen); static __attribute__((noreturn)) void l2arc_dev_rebuild_thread(void *arg); @@ -6919,6 +6922,13 @@ arc_kstat_update(kstat_t *ksp, int rw) if (rw == KSTAT_WRITE) return (SET_ERROR(EACCES)); + /* reset ARC statistics */ + if (zfs_arc_stats_reset) { + ARCSTAT_INCR(arcstat_l2_cksum_bad, -(as->arcstat_l2_cksum_bad.value.ui64)); + ARCSTAT_INCR(arcstat_l2_io_error, -(as->arcstat_l2_io_error.value.ui64)); + zfs_arc_stats_reset = 0; + } + as->arcstat_hits.value.ui64 = wmsum_value(&arc_sums.arcstat_hits); as->arcstat_iohits.value.ui64 = @@ -10817,3 +10827,6 @@ ZFS_MODULE_PARAM(zfs_arc, zfs_arc_, evict_batch_limit, UINT, ZMOD_RW, ZFS_MODULE_PARAM(zfs_arc, zfs_arc_, prune_task_threads, INT, ZMOD_RW, "Number of arc_prune threads"); + +ZFS_MODULE_PARAM(zfs_arc, zfs_arc_, stats_reset, INT, ZMOD_RW, + "Reset ARC statistics");