diff --git a/cmd/zarcstat.in b/cmd/zarcstat.in index 8ffd2048116..ad0e12e9fbf 100755 --- a/cmd/zarcstat.in +++ b/cmd/zarcstat.in @@ -565,10 +565,10 @@ def init(): update_hdr_intr() - # check if L2ARC exists + # check if L2ARC exists; fall back to l2_size for older kernels that + # do not export l2_ndev snap_stats() - l2_size = cur.get("l2_size") - if l2_size: + if cur.get("l2_ndev") or cur.get("l2_size"): l2exist = True if desired_cols: diff --git a/cmd/zarcsummary b/cmd/zarcsummary index 24a129d9ca7..5b6e35465ea 100755 --- a/cmd/zarcsummary +++ b/cmd/zarcsummary @@ -856,7 +856,10 @@ def section_l2arc(kstats_dict): # The L2ARC statistics live in the same section as the normal ARC stuff arc_stats = isolate_section('arcstats', kstats_dict) - if arc_stats['l2_size'] == '0': + # Skip the section only when no cache device is attached. Fall back to + # l2_size for older kernels that do not export l2_ndev. + if arc_stats.get('l2_ndev', '0') == '0' and \ + arc_stats['l2_size'] == '0': print('L2ARC not detected, skipping section\n') return diff --git a/include/sys/arc_impl.h b/include/sys/arc_impl.h index dbe712e2e73..8fde5c4fe50 100644 --- a/include/sys/arc_impl.h +++ b/include/sys/arc_impl.h @@ -832,6 +832,8 @@ typedef struct arc_stats { * due to ARC_FLAG_UNCACHED being set. */ kstat_named_t arcstat_uncached_evictable_metadata; + /* Number of L2ARC devices currently attached across all pools. */ + kstat_named_t arcstat_l2_ndev; kstat_named_t arcstat_l2_hits; kstat_named_t arcstat_l2_misses; /* diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 053314db185..22b189d5bb8 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -586,6 +586,7 @@ arc_stats_t arc_stats = { { "uncached_metadata", KSTAT_DATA_UINT64 }, { "uncached_evictable_data", KSTAT_DATA_UINT64 }, { "uncached_evictable_metadata", KSTAT_DATA_UINT64 }, + { "l2_ndev", KSTAT_DATA_UINT64 }, { "l2_hits", KSTAT_DATA_UINT64 }, { "l2_misses", KSTAT_DATA_UINT64 }, { "l2_prefetch_asize", KSTAT_DATA_UINT64 }, @@ -7440,6 +7441,7 @@ arc_kstat_update(kstat_t *ksp, int rw) aggsum_value(&arc_sums.arcstat_dnode_size); as->arcstat_bonus_size.value.ui64 = wmsum_value(&arc_sums.arcstat_bonus_size); + as->arcstat_l2_ndev.value.ui64 = l2arc_ndev; as->arcstat_l2_hits.value.ui64 = wmsum_value(&arc_sums.arcstat_l2_hits); as->arcstat_l2_misses.value.ui64 =