image
image

Go Back   macosx.com > Mac Help Forums > HOWTO & FAQs

Reply
 
Thread Tools
  #1  
Old January 20th, 2003, 02:13 AM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
Moving the swapdir in Jaguar

Many techniques were developed for moving the swap directory in OS X 10.1.x and several applications were even written for that expressed purposes. None of those techniques or applications work very cleanly in OS X 10.2.x (resulting in .vm 1 or duplicate mounts and other oddities); but that's okay, because moving the swap file in Jaguar is easier than it has ever been. [No fstabs, no StartupItems, etc.]. This technique merely requires the editing of a single system file to make the configuration change.

The first step is to back up your /etc/rc, as we will be editing it and want to preserve a backup copy to fallback on in case things go awry:
sudo cp -p /etc/rc /etc/rc.default

Here is the relevant latter half of /etc/rc, which is all that needs to be edited to move the swap location in Jaguar:
Quote:
(... more precedes this portion of the script; this is just the latter half)
##
# update flushes the cached blocks from the filesystem using
# the sync system call every 30 seconds. This ensures the
# disk is reasonably up-to-date in the event of a system crash.
##

update

##
# Start the virtual memory system.
##

ConsoleMessage "Starting virtual memory"

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

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

dynamic_pager -H 40000000 -L 160000000 -S 80000000 -F ${swapdir}/swapfile



##
# Start daemon to fix incorrectly-prebound binaries
##
if [ -x /usr/libexec/fix_prebinding ]; then
/usr/libexec/fix_prebinding
fi


##
# Clean up and reset files and devices.
##
. /etc/rc.cleanup


##
# Early start for any startup items for performance reasons
##
configd


##
# pre-heat support for working set profiles
##
appprofiledir=/private/var/vm/app_profile

if [ ! -d ${appprofiledir} ]; then
if [ -f ${appprofiledir} ]; then
mv -f ${appprofiledir} "${appprofiledir}_"
fi
mkdir -p -m 711 ${appprofiledir}
chown root:wheel ${appprofiledir}
fi


##
# Insert BootCache prefetch tag
##
if [ "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
${BootCacheControl} tag
fi



##
# Start System Services
##

# Set language from CDIS.custom - assumes this is parse-able by sh
. /var/log/CDIS.custom
export LANGUAGE

SystemStarter -g ${VerboseFlag} ${SafeBoot}

exit 0
You might think that changing swapdir=/private/var/vm is all you need to do, but of course Apple didn't make it that easy on us! Not only do you have to change the location of the swapdir by changing the argument, but you also have to move the relevant VM section to the end, just before the exit 0, in order to allow for the pre-heat and other essential sections to run first; also we'll add a mount -a command for an extra margin of safety, just before establishing the swap location (in the example below, the swap directory is moved to a separate partition, /Volumes/.vm:
Quote:
(... more precedes this portion of the script; this is just the latter half)
##
# pre-heat support for working set profiles
##
appprofiledir=/private/var/vm/app_profile

if [ ! -d ${appprofiledir} ]; then
if [ -f ${appprofiledir} ]; then
mv -f ${appprofiledir} "${appprofiledir}_"
fi
mkdir -p -m 711 ${appprofiledir}
chown root:wheel ${appprofiledir}
fi

##
# Insert BootCache prefetch tag
##
if [ "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
${BootCacheControl} tag
fi

##
# Start System Services
##

# Set language from CDIS.custom - assumes this is parse-able by sh
. /var/log/CDIS.custom
export LANGUAGE

SystemStarter -g ${VerboseFlag} ${SafeBoot}

##
# Start the virtual memory system.
##

ConsoleMessage "Starting virtual memory"

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

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

dynamic_pager -H 40000000 -L 160000000 -S 80000000 -F ${swapdir}/swapfile


exit 0
(If you're very daring, you can try out different pager settings, but I don't necessarily recommend it, unless you are trying to squeeze every drop of performance out of a server machine or something. Apple has given us good general defaults in this regard. Change them at your own risk.)

Upon the next reboot, first confirm that the volume has mounted successfully with df:
Quote:
gatorparrots% df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/disk0s2 40018068 31444868 8317200 79% /
devfs 1 1 0 100% /dev
fdesc 1 1 0 100% /dev
<volfs> 512 512 0 100% /.vol
/dev/disk2s9 9424512 172944 9251568 2% /Volumes/.vm
And then run an ls /Volumes/.vm for good measure to confirm the swapfiles are being written to that partition:
Quote:
gatorparrots% ls /Volumes/.vm
total 78136
0 drwxrwxrwx 9 gator staff 306 Jan 19 13:07 ./
0 drwxrwxrwt 7 root wheel 238 Jan 19 16:58 ../
0 d-wx-wx-wx 3 root staff 102 Dec 26 13:01 .Trashes/
4 -rw-r--r-- 1 root staff 1024 Dec 26 13:00 Desktop DB
4 -rw-r--r-- 1 root staff 2 Dec 26 12:59 Desktop DF
0 drwxrwxrwt 4 gator staff 136 Jan 9 14:54 Temporary Items/
78128 -rw------T 1 root staff 80000000 Jan 19 13:07 swapfile0
If everything looks good, you should be able to sudo rm -f /private/var/vm/swap* to clear the old swap files.
WARNING: Do not execute this command until AFTER rebooting (per the instructions). You are asking to crash your Mac hard if you remove active swap files in use by the OS. It will very likely result in a kernal panic if you do.

Last edited by gatorparrots; January 23rd, 2003 at 04:22 PM.
Reply With Quote
  #2  
Old January 22nd, 2003, 03:49 AM
slur's Avatar
Geek / Hedonist
 
Join Date: Dec 2000
Location: Florence, MA
Posts: 542
Thanks: 0
Thanked 0 Times in 0 Posts
slur is on a distinguished road
Yep, just don't be a fool like me and delete the swapfiles while they're still in use. That's very very bad.
__________________
|
| slur was here
|

check out my creative music software
Reply With Quote
  #3  
Old January 23rd, 2003, 04:19 PM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
Yes, that was very, very bad. You will almost assuredly cause a kernel panic if you delete the swap files while they are still in use by the OS.

That's why I wrote "Upon your next reboot..."
Maybe I should have made a clearer warning, especially regarding the removal command...
Reply With Quote
  #4  
Old January 23rd, 2003, 09:05 PM
wiz wiz is offline
Registered User
 
Join Date: Jul 2002
Location: Sol
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
wiz is on a distinguished road
what is a swapdir? and what is it used for?
Reply With Quote
  #5  
Old January 23rd, 2003, 10:07 PM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
The swap directory is the location where OS X writes swapfiles (virtual memory pageouts). Swapfiles are created 80MB at a time by the system, and only when needed. If these are written to the same disk as everything else, your main disk will become fragmented after significant use (even though the swap files are cleared with a reboot, they leave behind an 80MB 'hole' that often is not filled on your disk). Further, if the free space on your drive does not occur in 80MB chunks (i.e. different block allocation size), your swapfiles will have to be fragmented. This will increase the amount of seek time when your system starts to page data between RAM and disk -- when you run out of 'real' RAM, you will notice a significant decrease in performance.

It is most advantageous if you can dedicate an entire hard drive as a swap disk. Failing that, a second partition (preferably the first partition on the disk for fastest access) is acceptable. This way you can access data faster if you're getting it from two disks -- while the system is paging data between RAM and hard disk, you downloads to another disk or application launch or large file read isn't taking a big performance hit. This dedicated disk/partition doesn't have to be very large, 500MB to 1GB should be plenty. An old SCSI drive would be ideal because they're fast (assuming you can get it to work with OS X). Failing that, a 2 or 4GB IDE drive would do the trick.
Reply With Quote
  #6  
Old January 26th, 2003, 03:07 PM
Registered User
 
Join Date: Jun 2002
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
keyizm is on a distinguished road
i'll be getting an extra 7GB or 10GB ide drive. i was going to create a partition to use for swap. how much should i allocate? i've heard that you should allocate at least as much as you have phyiscal ram in your machine (i've got 1GB of RAM). so ... would creating a 1GB partition be enough or should i make it bigger? i was going to create another partition on the disk and move all my user directories over leaving only the OS and Applications on my main disk.
Reply With Quote
  #7  
Old January 26th, 2003, 10:14 PM
~departed~
 
Join Date: Jul 2002
Location: Kansas City, MO
Posts: 457
Thanks: 0
Thanked 0 Times in 0 Posts
gatorparrots is on a distinguished road
1GB should be more than plenty. If you have 1GB of physical RAM, you often won't need more than 80MB allocated for swap space (for the default single swap file). You would have to do some serious pageouts to achieve an additional 1GB of virtual memory. If you have the disk space to spare, go for it.
Reply With Quote
  #8  
Old February 2nd, 2003, 11:31 AM
Registered User
 
Join Date: Aug 2002
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
DMCrimson is on a distinguished road
hmm, I'm considerin doing this. I've already partitioned my drive so that there's a 500 MB partition called Swap, but some things concern me: on www.bombich.com , there are directions on how to do this feat, but it also incorporates meddling with fstabs, is this necessary?
__________________
Sawtooth G4 @ 1.4GHz, Club3d Radeon 8500LE (full 8500 when flashed), Pioneer DVR-A05
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[HOWTO] - Cool Keyboard/Mouse Combos zootbobbalu HOWTO & FAQs 45 October 8th, 2003 07:36 AM
10.3 Panther Screenshot (For Real!!) Stridder44 Apple News, Rumors & Discussion 58 June 23rd, 2003 06:21 PM
blurry screen on iMacG3 using Jaguar mfox Hardware & Peripherals 3 October 3rd, 2002 01:32 PM
First impressions of Jaguar FrankH Mac OS X System & Mac Software 1 August 27th, 2002 03:22 PM
new member with Jaguar questions kendall Mac OS X System & Mac Software 3 August 19th, 2002 12:18 AM


All times are GMT -5. The time now is 11:41 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.