zfs_arc_max reads 0 by default, so the fallback never fired and the ARC section divided by zero

This commit is contained in:
Gmer4Lfe
2026-08-06 22:39:54 -04:00
parent 1b46033584
commit ba1979a662
+11 -2
View File
@@ -261,8 +261,17 @@ echo "━━━ $ICON_ZFS ARC Statistics ━━━"
if [[ ! -f /proc/spl/kstat/zfs/arcstats ]]; then
warn "ZFS arcstats not available — skipping ARC section"
else
ARC_MAX=$(cat /sys/module/zfs/parameters/zfs_arc_max 2>/dev/null || \
awk '/^c_max / {print $3}' /proc/spl/kstat/zfs/arcstats)
# zfs_arc_max reads 0 when it has been left at the default, which is a value rather than a
# failure — so the || fallback never fires for the case that actually needs it, exactly like a
# grep -c that prints 0 and exits 1. Zero here would reach the ARC_PCT division below, and awk
# treats division by zero as fatal: it prints nothing, ARC_PCT comes back empty, and the whole
# ARC section reports blanks. c_max is the cap the kernel is really enforcing either way.
ARC_MAX=$(cat /sys/module/zfs/parameters/zfs_arc_max 2>/dev/null || echo 0)
ARC_MAX="${ARC_MAX//[^0-9]/}"
if [[ "${ARC_MAX:-0}" -eq 0 ]]; then
ARC_MAX=$(awk '/^c_max / {print $3}' /proc/spl/kstat/zfs/arcstats 2>/dev/null)
ARC_MAX="${ARC_MAX:-0}"
fi
ARC_SIZE=$(awk '/^size / {print $3}' /proc/spl/kstat/zfs/arcstats)
ARC_META_USED=$(awk '/^arc_meta_used / {print $3}' /proc/spl/kstat/zfs/arcstats)