#!/bin/sh
# DF-0207 run - demonstrate the clist_alloc_cblocks memory leak.
# The leak is observed via `vmstat -m | grep ttys` (M_TTYS MemUse) which is a
# root-readable kernel slab counter.  The TRIGGER (kldload) is root here because
# the only live ccmax-change path on this QEMU guest is the sio serial console
# (root-only); the bug itself is reachable wherever a clist is resized.
set -e
cd "$(dirname "$0")"

echo "== BEFORE (M_TTYS slab) =="
vmstat -m | grep -i ttys

echo "== Loading df0207_harness.ko (3000 resize iterations) =="
kldload ./df0207_harness.ko

echo "== AFTER (M_TTYS slab) =="
vmstat -m | grep -i ttys
echo "(on the UNPATCHED kernel MemUse jumps ~143K -> ~29M; on the FIXED kernel it stays ~flat)"

kldunload df0207_harness 2>/dev/null || true
