image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets


Files are in Stuffit 5 or greater format.
Free download.

Tell us about a bad link.

Thank You!


Running
without a restart.

Using a Dedicated Swapfile Partition to Speed Up MacOS X by Andy Moraitis

One of my biggest gripes with MacOS X is that although the Aqua interface is beautiful, it requires tons of overhead and a very fast processor to keep things moving along. While there are a few tactics that work well in speeding up MacOS X including turning off Finder zoom rects, adding more physical RAM, regularly defragmenting the drive and reducing display colors to thousands, the single most effective procedure I have come across is to dedicate a partition to the vitrual memory swap file used by the BSD subsystem.

In order to keep installation simple, MacOS X installs the swapfile among the data files by default. The problem with this is that the swapfile can sometimes become buried, especially if a user frequently opens and quits programs. The OS is then forced to look for the vitrual memory swap among all the pieces of data files present on the drive, thus making system performance sluggish, which is fine unless you LIKE staring at that little colored wheel. As the data on the drive becomes more fragmented, performance suffers even further.

Before you stop in your tracks and cringe because you have no idea as to how to use a command line, keep in mind that until I purchased MacOS X a few weeks ago, that I was new at this too. This guide is designed for as a step by step method in increasing your Mac’s performance in a big way. Where it’s necessary, I have included terminal text dumps so you have an idea as to what you should see on screen.

Methods:

There are basically two ways to accomplish the swapfile partition setup. You can either dedicate a piece of another hard drive (preferred) or use a partition on your existing boot volume. For users of single hard drive systems such as iBooks, PowerBooks and iMacs the single drive method applies. Since I have a G4, I added a separate 20 gig drive to complement my existing 30 gig drive that shipped with the unit. Either method will work well, but if you have the option to use a partition on a second drive, please do so as it is even faster than the single drive method. Either way, you WILL see measurable performance gains.

As far as swap partition size, this is something that I have played around with extensively. While Linux based systems prefer a 1:1 ratio or a maximum of 2:1 (swap to physical RAM), I have tried different combinations with MacOS X such that I am convinced that the size of the partition is not the greatest issue, but the fact that it is separate from the data files. While I would like to give you a concrete formula, I really can’t, but I can vouch for the fact that I have used 384 and 500 meg partitions and even the entire drive with no real difference in results. Since the vm swap is written in 80 meg blocks, it will be rare for even the most power hungry setup to need more than 500 meg of swap space, but if you would like to allocate more, please feel free to do so and let me know if you think it helped.

What follows is my exact setup procedure on my two drive system starting from scratch.

Step 1. Back Up Your Data!

Make sure to back up all of your relevant data files irrespective of which method you will be using. Also ensure that you back up copies of those custom files that you’ve worked on such as your HIToolbox.rsrc and all software updaters if you have upgraded from MacOS X 10.0 to 10.0.3.

Step 2: Set Up the Target Drive

Format and partition the target drive. I did this by starting from the MacOS 9.1 CD (hold down the “c” key as the CD boots) and using Drive Setup. I prefer to set up my drive up from MacOS 9.1 since I can tweak the partitions to any size that I want. The MacOS X Drive Setup Utility limited me to 1.5 gig on the swap partition and although I have plenty of drive space, anything in excess of a 500 meg swap partition seemed to be a waste.

I partitioned my drives as follows:

Main Boot Volume:

9 Gig MacOS 9.1 Partition HFS+ Format (named G4/OS9)
9 Gig MacOS X Partition HFS+ Format (named G4/MacOS X)
9 Gig MacOS X Developer Tools Partition HFS+ Format (named G4/Dev)

Second Volume:

500 Meg Swap Partition HFS+ Format (named Swap)
19.5 Gig Empty Partition HFS+ Format (named G4/Backup)

As soon as you have quit Drive Setup, name your drives from the finder and proceed to the next step which is to install fresh system software. Please note that I formatted my drives as listed above since it is much easer for an OS to find relevant data files on a 9 gig partition than on a 30 gig partition.

Step 3: Install Fresh System Software

I installed MacOS 9.1 on the OS 9.1 partition and did the same with MacOS X on the dedicated MacOS X partition. Following some minor tweaks to the preferences to get the system back to the way I liked, and a data restore of my applications and files, I opened up a terminal session in MacOS X.

Note: in order to perform the file editing we are about to delve into, it is necessary to have root access. If you have not already enabled root, you can do so by going to the “NetInfo” application in your MacOS X Utilities Folder. For more help on setting root access, use MacHelp from the Help Menu.

(Note: Be sure to have the Developer tools installed. Not only will this make root acces easier, it provides the terminal text editor pico -MC)

Step 4: Determining the Swap Partition Location

Open a terminal session (stop shaking already all you new users!) and use the df -k command at the prompt to list the components of your file systems. Here’s a screen dump of my df -k command.

[localhost:~] acm% df -k

Filesystem   1K-blocks  Used    Avail  Capacity Mounted on
/dev/disk0s10 9992892 1627520  8365372     16%      / 
devfs              37      37        0    100%      /dev 
/dev/disk1s9   511928   86220   425708     16%      /Volumes/Swap 
fdesc               1       1        0    100%      /dev
<volfs>           512     512        0    100%      /.vol
/dev/disk0s9  9998508  112764  9885744      1%      /Volumes/G4:OS9
/dev/disk0s11 10013796   8676 10005120      0%      /Volumes/G4:Dev
/dev/disk1s10 19496100   9100 19487000      0%      /Volumes/G4:Backup

[localhost:~] acm% 

/ - indicates that this is the boot volume:G4/MacOS X
/Volumes/Swap - my new vm swap partition on the second drive:Swap
/Volumes/G4:OS9 - my OS 9.1 boot partition:G4/OS9
/Volumes/G4:Dev - my Developer’s Tools partition on the primary drive:G4/Dev
/Volumes/G4:Backup - my empty partition on the second drive:G4/Backup

Take a look at the fourth line down. The drive listed at /dev/disk/1s9 is the swap partition created with Drive Setup. This is the drive we’ll use to set up the new home for the actual swap partition. Please note that the number of your partition may vary since 0 indicates a boot drive and 1 indicates a secondary drive. It is helpful to write down the number of the partition and the path (i.e./dev/disk1s9) since we’re going to be using it next.

Step 5: Using Pico to Create the /etc/fstab file

For the remainder of the work, we’ll need to gain root access to modify two main system files by using the a text editor called pico. These files are /etc/fstab and /etc/rc. From the command prompt, enable the root user.

[localhost:~] acm% su (Gain root access)
Password: ****** (Enter your root password)
[localhost:/Users/acm] root# pico /etc/fstab 
(Opens Pico to create the /etc/fstab file)

You’ll see a blank space on the screen (pretty much an empty canvas) and some command listings on the bottom that we’ll use to create our new fstab file.

At the terminal prompt, type the following and use the drive device information you wrote down from the df -k command that relates to your swap partition. Here’s what I typed and remember that your device may vary! Also make sure to include the spaces in the exact manner as listed and be careful not to add any spaces where they don’t belong as the swapfile setup will not work.

Use a carriage return after you enter this line and then use Control-X. You will be prompted to save the file. Type “y” for yes at the prompt and hit enter.

Step 6: Using Pico to Modify the /etc/rc file

While still in the terminal, type the following at the command prompt

[localhost:~] acm% pico /etc/rc


The /etc/rc file is fairly large and rather than scroll through the whole thing looking for the swapfile comments, the easiest method is to use the Control-W command to perform a search. Enter the word “swap” with no quotes and Pico will automatically bring you to the line to be modified. I have marked this line in bold and underlined it so you can see which one it is.

In order to make our new system work, we must comment out or deactivate the existing swapdir line by inserting the pound sign or “#” Since Pico does not require any special insert commands and your cursor is already on the appropriate line, simply add the # symbol to the beginning of the line. Hang in there because we’re almost done!

Since we’ve now told the OS not to use the existing swapfile setup, we will need to insert our new comment line directly underneath.This will direct the OS to check for the swapfile in the new location established in the /etc/fstab file. Press the down arrow key to move down one line and type the following:

swapdir=/Volumes/swap/vm (enter another carriage return at the end of the line)

Your modified /etc/rc file will now look like the one pictured above.

This will tell the etc/rc script to use this new location for the vm swapfile. Once again, use the Control-X combination to quit and type “y” for yes to save the file. Press enter one more time and you’ll exit pico and be brought back to the command line prompt. You can either close your terminal session and reboot from the finder, or reboot from the command line.

Step 7: Verifying Your Results

After the system restarts, there are two ways to verify that the swapfile was created properly. If you would like to use the command line, open a terminal session and type the following (root access is NOT required) at the command prompt.

[localhost:~] acm% cd /Volumes/swap/vm 
(Change your directory to the location of the swapfile)
[localhost:/Volumes/swap/vm] acm% ls

swapfile0

The results of the ls command should be the same as mine. A single file should be present called “swapfile0”. If this is what you see, then congratulate yourself on a job well done, quit the terminal and start enjoying your new system. You may even wish to howl like a banshee (then again, you may not!)

If you see a file called “swapfile1” this indicates that the /etc/fstab file probably has an error in the device comment line and that the current location appeared to be occupied when the system initialized the mountpoint, thereby forcing the creation of a new swapfile. Be sure to check for extra spaces or grammatical errors in the /etc/fstab and /etc/rc files where the modifications were made.

You can also verify your results from the desktop by opening your drive entitled “swap” and looking inside the “vm” folder. You should see a file called swapfile0. Again if your file is named swapfile1, check it for errors and correct them as necessary. If you have misgivings about using Pico to edit the files, then simply trash them from the finder, open a terminal session and start the procedure over from step 3 as listed above. There is no need to reformat or re-partition the drive since this has already been done.

How It Works in the Real World:

I’ve been using this type of swapfile arrangement for the last few days and I can feel a definite difference in performance. Whereas the disk would go through intense “thrashing” while swapping out VM, this no longer occurs. My system is pretty vanilla (a G4/466 Sawtooth with 384 Meg RAM) and this modification has made MacOS X that much more user friendly. As I write this, the following programs and actions are taking place (thank God for the ASM app switcher!)

  1. IE 5.1.1 is taking down a large download from the Apple site
  2. Mail app is open.
  3. iTunes is jamming some BT with the visuals on (no skipping!)
  4. QT5 Pro is looping a 5 minute Titanium PowerBook Movie
  5. The Terminal is open.
  6. Photoline 32XL is open.
  7. Moneydance is open.
  8. Preview is checking out a 7 meg PDF file on YellowDog Linux.
  9. TexEdit is open (and I’m typing away)
  10. iCab is is loading the ResEx home page.
  11. Classic is running (yuck!)
  12. System Preferences is open.
  13. ASM is running
  14. Internet Connection is active.
  15. GraphicConverter is running.

Keep in mind that these are just the user processes that are running while the BSD susbsystem executes it’s own work behind the scenes. Now this is a TON of work that could be amplified even more if I started a large database sort or query, however the system is handling them all very smoothly and transparently. There is no jumpiness or twitchiness in the graphics display or in any page rendering and iTunes hasn’t missed a beat.

I did an ls command from the terminal to check my swap partition in /Volumes/swap/vm directory and the file size is only 160 meg (or two 80 meg vm blocks) which leads me to believe that 500 meg is plenty.

So you know, I have also experimented with different configurations in setting up MacOS 9 and MacOS X and the current partition scheme that I use works the best since it speeds disk access by using smaller partitions instead of one large one. I always recommend separating your different operating systems with the size of each partition based on your particular needs.

This modification gives any user an opportunity to obtain increased speed AND use a gorgeous interface. A simple caveat: if you’re expecting your machine to fly like it has MacOS 9.1 loaded, then forget about it. This is MacOS X after all and there’s a price to be paid for all of that newfound power under the hood and the eye candy on screen. Please feel free to drop me a line and let me know how this worked for you or if you need help doing the terminal work.

Good Luck and Enjoy!

Comments from Michael Coyle:

Since I already have a swap partition on my drive for Linux, I would love to be able to use it for MacOS X too, but I can't mount an ext2 filesystem in MacOS X. If you have any tips on how this may be possible, please email me.

If you're in a pinch, the swap partition can still be used as normal drive. For example, to keep fragmentation to a minimum, you could archive seldom used files on that partition. Just be sure to leave at least 80 meg free for the minimum swap size.

UPDATED (6-4-01):

Andy's article on seting up another drive or partition for use with MacOS X generated a lot of email. Let me touch on some of the topics.

Matt Holmes was the first to point out this excellenct Linux article on how to use a Mac HFS partition for swap, and then convert it back again. Written by Andrew Arthur from iMacLinix, the article outlines how to modify two scripts, one for startup that converts an HFS partition to swap, and the other to reformat it for HFS at shutdown. Since the HFS partition is obviously getting reformated on every boot, you can't use it for much - but it's perfect for a shared swap partition!

The article's notes are based on the Debian PPC distribution. Below are my additions to make it work with LinuxPPC.

The startup script to modify is: /etc/rc.d/rc.sysinit. Look for the following two sections:

# Start up swapping.
action "Activating swap partition" swapon -a

swapon -a >/dev/null 2>&1
action "Enabling swap space" /bin/true

and change them to:

# Start up swapping.

action "Creating Swap Disk..." mkswap -f /dev/hda16 2> /dev/null
action "Activating swap partition" swapon -a

action "Creating Swap Disk..." mkswap -f /dev/hda16 2> /dev/null
swapon -a >/dev/null 2>&1
action "Enabling swap space" /bin/true

Be sure to put in your partition numbers for the /dev.

The shutdown script is /etc/rc.d/init.d/halt. It reformats and renames the swap partition to HFS for use in MacOS X. Find the following:

# Unmount file systems, killing processes if we have to.
sig=
retry=3

And place just before it:

echo -n "Creating MacOS X Swap"
hformat /dev/hda16 2> /dev/null
hrename "Untitled:" "Swap:" 2> /dev/null

# Unmount file systems, killing processes if we have to.
sig=
retry=3

Again, be sure to put in your partition numbers for the /dev!

These script modifications worked great for me. You'll need to be sure the swap partition is at least 80M for the MacOS X swap file to be created.

After launching the above two dozen applications (plus the Classic Environment), MacOS X created 4 swapfiles using a total of 320M of disk space. I have 256M of real RAM. The system was very sluggish. Under LinuxPPC, I did the same, launching Mac-On-Linux and over two dozen applications. The system remained snappy and I only have a 64M swap partition. It appears Apple has a little more work to do in this area.

What is the correct size for swap files/partitions? Matt Wolanski, an IBM certified systems specialist, says IBM recommends the following formula for the calculation of swapfile space:

((RAM - 256MB) x 1.25) + 512MB

Readers have also asked about deleting the old swapfile to regain at least 80M of drive space. To do this, gain root access in a terminal and type:

rm -Rf /private/var/vm/

More information of swapfiles under MacOS X (based on NextStep) can be found in this article sent by Patpro (who also wrote this article on the topic).

Given all this (sometimes contridictory) information on swapfiles, it seems virtual memory may replace SCSI as the black magic of computers!

Also see: MacOS X VM Swapfile Benchmark Results

Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]