Skip to content

Commit

Permalink
ARC statistics reset
Browse files Browse the repository at this point in the history
Fixes openzfs#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 <g.danti@assyoma.it>
  • Loading branch information
shodanshok committed Aug 13, 2024
1 parent d4b5517 commit 6ed47fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions man/man4/zfs.4
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
26 changes: 26 additions & 0 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -7166,6 +7176,19 @@ arc_kstat_update(kstat_t *ksp, int rw)
as->arcstat_abd_chunk_waste_size.value.ui64 =
wmsum_value(&arc_sums.arcstat_abd_chunk_waste_size);

/* reset ARC statistics */
if (zfs_arc_stats_reset) {
printk (KERN_INFO "bad: %llu - sum: %llu\n", as->arcstat_l2_cksum_bad.value.ui64, wmsum_value(&arc_sums.arcstat_l2_cksum_bad));
ARCSTAT_INCR(arcstat_l2_cksum_bad, -(as->arcstat_l2_cksum_bad.value.ui64));
as->arcstat_l2_cksum_bad.value.ui64 = 0;
printk (KERN_INFO "nad: %llu - num: %llu\n", as->arcstat_l2_cksum_bad.value.ui64, wmsum_value(&arc_sums.arcstat_l2_cksum_bad));
zfs_arc_stats_reset = 0;
//wmsum_add(&arc_sums.arcstat_l2_cksum_bad, as->arcstat_l2_cksum_bad.value.ui64*-1);
//as->arcstat_l2_cksum_bad.value.ui64 = 0;
//as->arcstat_l2_io_error.value.ui64 = 0;
//wmsum_init(&arc_sums.arcstat_l2_io_error, 0);
}

return (0);
}

Expand Down Expand Up @@ -10817,3 +10840,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");

0 comments on commit 6ed47fc

Please sign in to comment.