Click to See Complete Forum and Search --> : Problems with OS X swap file script


i was dchakrab
10-06-2004, 01:29 AM
Ok...I'm realising this is most likely a problem with the script, so I'm posting script exerpts here instead of my original post in the OS forum.

I'm trying to switch my swap file to a different volume from my OS, to get better performance out of my OS X.3 powerbook.

Ok, here are the scripts I've been using...

From /etc/rc, here's the part dealing with virtual memory:

echo "Starting virtual memory"

swapdir=/private/var/vm

#swap mod

if [ -f /etc/rc.swapfile ]; then . /etc/rc.swapfile; fi # inserted locally


if [ "${netboot}" = "1" ]; then
sh /etc/rc.netboot setup_vm ${swapdir}
fi

# Make sure the swapfile exists
if [ ! -d ${swapdir} ]; then
echo "Creating default swap directory"
mount -uw /
mkdir -p -m 755 ${swapdir}
chown root:wheel ${swapdir}
else
rm -rf ${swapdir}/swap*
fi

Then here's the /etc/rc.swapfile code it should be inserting:


##
# After the line in the system startup script /etc/rc
#
# swapdir=/private/var/vm
#
# insert the line
#
# if [ -f /etc/rc.swapfile ]; then . /etc/rc.swapfile; fi # inserted
# locally
##

swapvolume=swap

if [ ! -d /Volumes/${swapvolume}/.Trashes ]; then
swapcount=1
ConsoleMessage "Waiting for ${swapvolume} to mount"
while [ "$swapcount" -le 30 ]; do
sleep 1
if [ -d /Volumes/${swapvolume}/.Trashes ]; then
ConsoleMessage "${swapvolume} mounted after $swapcount seconds"
break
fi
swapcount=`expr $swapcount + 1`
done
fi

if [ -d /Volumes/${swapvolume}/.Trashes ]; then
ConsoleMessage "Using ${swapvolume} for swapfile"
if [ -f ${swapdir}/swapfile0 ]; then
rm -rf ${swapdir}/swap*
fi
swapdir=/Volumes/${swapvolume}/.vm
else
ConsoleMessage "Unable to use ${swapvolume} for swapfile"
fi

This results in a console log that tells me how long it took to mount my swap volume, and claims my intended swap volume loaded fine. However, loading a bunch of applications results in ActivityMonitor showing a larger swap file size than my swap partition, and Finder shows my partition as being virtually empty, so I'm assuming the script is reporting a false-positive somehow.

Ideas?

-D.

This script is based entirely on a tutorial found here, (http://www.math.columbia.edu/~bayer/OSX/swapfile/) in case anyone's interested (and to give credit where credit is due).