Thanks to Tom Hageman, I have an improved version of Pagerwatch. He
turned several calls to awk into one sed.

#!/bin/bash
# Bug: We really need to fetch and add free, active, and inactive.
#  Wired isn't accurate.

sleep 11

# free=`vm_stat |     egrep     ' free' | awk '{print $NF}' | sed s,\\\\.,,`
# active=`vm_stat |   egrep   ' active' | awk '{print $NF}' | sed s,\\\\.,,`
# inactive=`vm_stat | egrep ' inactive' | awk '{print $NF}' | sed s,\\\\.,,`

eval `vm_stat | sed -n '/^Pages /{;s///;s/: */=/;s/\.$//;s/[- ]/_/g;p;}'`

# This gives us something like
# free=20201 active=17816 inactive=1526 wired_down=33461
copy_on_write=6896496 zero_filled=37844331 reactivated=53808

freeTrig=4000
availTrig=8000
totalTrig=16000
reportTrig=25000

total=$(($free + $inactive + $active))
available=$(($free + $inactive))

[ $total -lt $reportTrig ] && echo "Debug: Free, Inactive, Active,
Total: $free ($freeTrig) $inactive ($availTrig) $active $total
($totalTrig)"


if  [ ! -f /tmp/startSwap ] ;
then {
        # Don't run dynamic pager if we have enough free space.
        [ $free -gt $freeTrig ] && exit 0 ;
        [ $available -gt $availTrig ] && exit 0 ;
        [ $total -gt $totalTrig ] && exit 0 ;
} ;
fi

# Remember: When pager isn't running, wired has all the private data, while
# active has the code pages (replacable from disk) still in use.
# "Free" and "inactive" are both immediately available.
# "Active" is "thrashing" space.

# Ok, we're tight on space, start pager and trade disk space for speed.
mkdir /tmp/swapFiles
launchctl start com.apple.dynamic_pager
launchctl remove michael.pager-watch


-- 
Political and economic blog of a strict constitutionalist
http://StrictConstitution.BlogSpot.com
_______________________________________________
MacOSX-talk mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-talk

Reply via email to