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 fca5087
Show file tree
Hide file tree
Showing 2 changed files with 17 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
13 changes: 13 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 */

Check failure on line 6925 in module/zfs/arc.c

View workflow job for this annotation

GitHub Actions / checkstyle

indent by spaces instead of tabs
if (zfs_arc_stats_reset) {
ARCSTAT_INCR(arcstat_l2_cksum_bad, -(as->arcstat_l2_cksum_bad.value.ui64));

Check failure on line 6927 in module/zfs/arc.c

View workflow job for this annotation

GitHub Actions / checkstyle

line > 80 characters
ARCSTAT_INCR(arcstat_l2_io_error, -(as->arcstat_l2_io_error.value.ui64));

Check failure on line 6928 in module/zfs/arc.c

View workflow job for this annotation

GitHub Actions / checkstyle

line > 80 characters
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 @@ -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");

0 comments on commit fca5087

Please sign in to comment.