Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Moving swap in 10.2 revisited System
I tried every method I could find online to get the swap on a separate drive and either they locked up the system before boot or they made a new folder hence the "swap 1" link was created im sure most who have tried know this problem.

Methods I tried before worked in 10.1, but 10.2 seems a lot more problematic when trying to switch swap drives. The recent post here that describes copying the "drives" startup script into the rc file ended up making 10.2 unbootable. Other methods would create a folder "swap" in volumes and "swap" drive would mount as "swap 1;" it was stubborn like that.

Trying the most basic method, I created the fstab file with the mount point and edited only the location of the swap directory in the rc file:
After that didn't work, I then added the other method's "mount -a" before the above line. Well that didn't help either. I even listed the explicit mount point with the fstab information with no success.

[Editor's note: I haven't tested this myself ... also, I'm testing a new method of posting long code snippets; I hope you find it as nice an improvement over the old method as I do! Read the rest of the article to see the new method.]

After looking over the way the rc file is set up now in 10.2, I noticed there were certain system calls that seemed to be key which occurred after the swap code. I thought I'd try moving the entire modified swap code section to the end of the file, hoping the other system calls would allow the drives to mount and bingo it worked! I spent a lot of determined time to get that to work. Here's how the new end of my rc file looks:

# Start System Services

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

SystemStarter -g ${VerboseFlag} ${SafeBoot}

# Start the virtual memory system.

ConsoleMessage "Starting virtual memory"

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

# 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}
rm -rf ${swapdir}/swap*

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

exit 0

I still haven't tested whether the fstab file or the "mount -a" line are necessary. I'm tired of messing with it, and I'm just glad it works. Maybe someone else can test that theory and post the simplest solution.
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)

Moving swap in 10.2 revisited | 30 comments | Create New Account
Click here to return to the 'Moving swap in 10.2 revisited' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Authored by: Mike Klein on Oct 16, '02 10:49:20AM

The hint the other day worked beautifully for me. On my home machine, I have
two internal drives. I put Application and Swap on the second drive. You need to
do the Labels= business to defice the mount point and then an niload to make it
active. After this the entry for swapdir should look like /Swap/.vm.

[ Reply to This | # ]
Authored by: norby on Nov 05, '02 02:57:09PM

1) the LABELS=business stuff that is covered in the fstab and autodismmount man page unfortunately breaks mount (i.e. mount -vat hfs).

2) There is no such thing as a raw swap partition (for the person who suggested it in another thread) in darwin at this point (perhaps there used to be, but there is no longer. There is no swapon command to enable it, and very little mention of it in man pages, OS headers, etc.

3) Given that you are relying on autodiskmount to mount your volume as /Swap, it seems to me that you might as well let it mount as /Volumes/Swap and just symlink /Swap to /Volumes/Swap for your edification.

4) Seems that the flat file (fstab) controls everything. If that file is there w/ the LABEL stuff, mount -vat hfs breaks. If you move that file aside (even after loading these into NetInfo), autodiskmount does not mount the partition as desired. So ...

5) That is all :)

[ Reply to This | # ]
RE: why bother in the year 2002?
Authored by: BraindeadMac on Oct 16, '02 10:54:55AM

You know back when RAM cost about $500 per megabyte and a 10 MB hard drive cost about the same we used to really worry about optimizing virtual memory performance because it really did make a difference--like in the 500-1000% performance improvement difference for compute intensive tasks. But the performance benefit you get with modern hard disks and the huge amounts of RAM and disk space available makes all of this pretty much mental masturbation for doing this on OS X. People report all sorts of subjective improvements, but the actual numbers provided by proponents of this technique are amazingly short of impressive. To get a "real" benefit you ought to be putting the vm space on a 0 striped LVD SCSI array which costs a whole lot more than just buying RAM. And that real benefit will only buy you a handful of percentage points improvement. I'm sure people are wasting more time trying to do this than they are actually gaining.

[ Reply to This | # ]
RE: why bother in the year 2002?
Authored by: jlneemidge on Oct 17, '02 01:09:29AM

For most users, raw VM performance is a secondary reason to move your swap space (i.e. if you're doing it just to get better performance, you're probably wasting your time). The real reason to move swap is to get it into an area where there's no competition. You can't run out of swap space if something goes nuts and fills up your boot partition, you can't get a fragmented swap file because your boot partition is fragmented, etc. It makes your swap space behavior consistent and predicatable, and that's a good thing.

[ Reply to This | # ]
RE: why bother in the year 2002?
Authored by: barrysharp on Oct 17, '02 10:33:43AM

The answer to all of this is to AVOID swapping all together.

Now I know that it's not possible to eliminate swapping all together but one can get very close to this. By installing as much RAM as is needed for running the machine's workload swapping can be minimised.

Memory is much more affordable today so this should be possible for most everyone today.

I have 1gig RAM in my iMac and I run for weeks at a time and swapping is practically zero. Over past two weeks my pageouts total about 350.

I've yet to encounter any program or OS created scenario that causes swap space to expand without bounds as the previous poster was refering to as a potential hazard. That's not to say it can't happen -- simply I'm stating I've not encountered it and hope that it never will.

I've been managing large UNIX VM systems for over 20 years and having to configure swap space is very wasteful because my goal has been to never overcommitt the system' physical memory resource. If this can be achieved (and it can if care is taken with managing incoming workload) there really is no reason to have swap space -- a total waste of disk and cost IMO. One must configure swap space in some systems as system dumps write to this area when system panics etc.

Regards... Barry Sharp

[ Reply to This | # ]
RE: why bother in the year 2002?
Authored by: WillyT on Oct 17, '02 10:32:27AM

I have 1.2 GB ram and I still get pageouts (91595(0)). With the swap on an separate drive I don't see the spinning lolipop very often as opposed to several second waits here and there without moving swap. Besides pageins require a read of the swapfile thus causing some minor thrashing. Pageouts require reads and writes causing thrashing.

Put it on a separate disk and all that is just a distant memory.
The only time I need to worry about mount order is during a reboot. Come up in single-user fsck and fsck_hfs everybody and exit. If everything looks good for fsck_hfs then the swap will come up right. If fsck_hfs -y /dev/disk0s10 shows something other than Swap then just reboot again. My uptime is nine days right now (would be more if shutdown now worked) so you see I don't worry about this every day.

[ Reply to This | # ]
RE: why bother in the year 2002?
Authored by: barrysharp on Oct 17, '02 11:06:11AM

From your swapping activity I would venture to say you're overloading your system and/or you're using programs that employ poor memory management strategies.

I guess it's possible you launch programs that you use infrequently. This means that once they or a portion of them reside in physical memory and they lay dormant they have to be swapped out (paged out in bits and pieces) to make room for other programs you launch.

If you aren't going to use a program for some time then simply quit it and release the valuable memory resources it's consuming back to the system for reuse by other more important and *frequently* used programs you use.

Quitting a program will also protect it from a system crash in that if it's still memory resident or active at the time the system crashes there's danger that some of it's data hasn't made it to disk for permanent safe keeping.

I also think a large fast HD dedicated to scratch files is of benefit as i/o is more likely to find big contiguous chunks of space to speed up data transfers. However, many programs don't provide the option to direct their scratch data to specific HD locations. Yes, there are some exceptions to this such as PS but many still remain that don't offer this.

My experience has told me to avoid swapping like the plague.

Now, as we start having the option of using multi processor machines such as Apple is deploying today in their G4 tower line the question of swapping becomes a little more interesting. With these systems it matters little if swapping is occuring so long as the CPUs aren't being starved because of such action or because of the swappin interferring with outher non-swapping activities. Having a separate HD for swapping may be a more worthwhile endeavor under these circumstances.

Regards... Barry Sharp

[ Reply to This | # ]
RE: why bother in the year 2002?
Authored by: robh on Nov 09, '02 04:23:55PM

Don't worry about pageins and pageouts unless you're getting lots of them while apps are running.

Chances are, you're getting them when starting apps or bringing them to the foreground after a long period of inactivity.

Now if you are running apps and you see tons of pageins/outs then you probably are very short of physical memory and hammering swap space. In these cases, throw a few bucks at the problem and add more RAM, it'll have a massively greater effect on the problem than moving the swapspace.

IMO, moving the swapspace on an OSX box is a complete waste of time and effort.

[ Reply to This | # ]
Authored by: jasonxz on Oct 16, '02 12:04:51PM

During the boot up process, I see the phrase "Starting Virtual Memory" twice - once near the beginning and once at the end. Anyways, how can I check where the swap is being created?

Searching the forums, I tried a command that someone posted:

ps -ax | grep dynamic_pager

However, it did not state a location, just a bunch of numbers.

[ Reply to This | # ]
New Format Bites
Authored by: Frederico on Oct 16, '02 03:05:46PM


I understand your desire to create a new method of displaying CLI text, but this new method bites.

One, it won't print properly (prints a 'snapshot' of random text from the box'); two, it's a total PITA to try to select any portion, let alone all the text in the box for editing, pasting, reading, etc.; three, it's incredibly small and faded-looking, i.e., terribly hard to read without magnification, which makes the rest of the page ridiculously large and distorted.

I'd rather deal with line wraps.

Thanks for trying, anyway.


[ Reply to This | # ]
I Agree
Authored by: jasonxz on Oct 16, '02 03:47:11PM

It was very tedious to select the text so I could copy/paste it.

[ Reply to This | # ]
Authored by: robg on Oct 16, '02 09:10:40PM

Two positives in email, two negatives in comments! I hadn't considered the printing issue; that's definitely a problem.

I'll have to see what else might be possible; thanks for the feedback.


[ Reply to This | # ]
I Agree - a PREF maybe?
Authored by: Thom on Oct 16, '02 11:33:55PM

seconded. I always drag, from top to bottom, the entire contents of a hint I want to save in my personal knowledge base (bunch of folders, different categories, under 'howto' :)

maybe this could be a preference for a user's account.

[ Reply to This | # ]
Not easily a pref...
Authored by: robg on Oct 17, '02 08:47:32AM

The story has to be stored in the database with the formatting in place for however it's going to be displayed. To change this to support two different display methods on retrieval would take coding that's well beyond my time and skill available! ;-)

So we're going to have to just find one that works reasonably well for everyone...


[ Reply to This | # ]
I Disagree
Authored by: gxw on Oct 16, '02 11:10:40PM

Dont' know about the printing issue - not going to try it.

Selecting the text was a breeze in Mozilla (Also using an M$ wheel mouse - did not have to touch the scroll wheel to select either. Just had to click and drag). The text box looks okay here as well - very readable.

[ Reply to This | # ]
New Format Bites
Authored by: Yaso on Oct 18, '02 11:16:32AM

I agree. Don't use it.

Can't print properly,
Nos quick copy/paste method are allowed in IE,
Can't read it...

Nice try. Keep the good work.

[ Reply to This | # ]
New Format Bites
Authored by: GaelicWizard on Oct 20, '02 06:57:03PM

It works great for me!


[ Reply to This | # ]
Authored by: Indiecn on Oct 16, '02 04:29:26PM

I used swapcop, I haven't really check wether it really created the vm on the other drive or not, but it does feel faster after using swapcop. I will to verify where the .vm is created.

[ Reply to This | # ]
Authored by: metiure on Oct 16, '02 05:18:50PM

SwapCop does the job!

[ Reply to This | # ]
It Shouldn't...
Authored by: jasonxz on Oct 16, '02 06:39:30PM
According to SwapCop's developer, "It's not designed to work for OS X 10.2," but they do seem to indicate that they working on making a compatible version.

[ Reply to This | # ]
It Shouldn't...
Authored by: gxw on Oct 16, '02 11:01:37PM

It does though.
I now have a 76 meg swap file on my swap volume.

[ Reply to This | # ]
moving swap tutorial
Authored by: Drake on Nov 09, '02 04:08:43AM
I've been messing around with the swapfile, and finally got it to work with a tutorial from lostboi. This guy made a how to move your swap file on jaguar. .Drake

[ Reply to This | # ]
Authored by: jasonxz on Nov 09, '02 01:26:22PM

I did "ls -l /dev/" in the Terminal and it returned nearly 100 lines of info. Unlike the tutorial writer, I have two disks each with two partitions; however, I'm uncertain what diskXsX the second disk's second partition is just from the Terminal output. Is there some way to display the partition names along with its diskXsX info?

[ Reply to This | # ]
Volumes/.Swap & .../vm/app_profile
Authored by: Sneeuwitje on Nov 12, '02 05:18:12AM

I put the swap on a hidden volume ".Swap"; never to bother about knuckle-heads saving on that volume again. Works beautifully for me.

sudo pico /etc/rc

in the virtual memory settings change:

#OLD# swapdir=/private/var/vm

in the pre-heat support section change:

#OLD# appprofiledir=/private/var/vm/app_profile

NOTE: if you moved the vm specification use the full path to /Volumes/.Swap/vm instead of ${swapdir}

If you're not installing a new system here's how to rename it to ".Swap":
- log out of your system and log on as root, (You have to enable root in NetInfo Manager)
- open Disk Utility
- select the drive you want to swap on (max 2 x total memory)
- erase it with the new name ".Swap"
- reboot and see: there's no swap drive
- you can check if it worked in the terminal by issuing:

ls /Volumes/.Swap/vm

it should at least return:

app_profile swapfile0

if it checks out o.k., to clean up /private/var issue:

sudo rm -rf /private/var/vm

don't be happy with your system, let your system be happy with you

=; )

[ Reply to This | # ]
use df -k instead
Authored by: brising on Nov 17, '02 02:49:23PM

If you use df -k, it will give a nice, short list, including the names of mounted disks.

[ Reply to This | # ]
sizing swapfiles to match physical RAM
Authored by: mblakele on Dec 13, '02 02:37:34AM

If you like the idea of having swapfiles sized to match physical RAM, here's how to do it. In /etc/rc, find the line that starts dynamic_pager. Comment it out, and add this code:

# this give us physical RAM in hex
RAMSIZE=`/usr/sbin/nvram ram-size | /usr/bin/cut -d x -f 2-`
# convert to decimal
VM_SIZE=`/bin/echo "ibase=16; $RAMSIZE" | /usr/bin/bc`
# high-water mark is 40MB (arbitrary)
# low-water mark is high-water + VM_SIZE + 1
VM_LOW=`expr $VM_HIGH + $VM_SIZE + 1`
dynamic_pager -H $VM_HIGH -L $VM_LOW -S $VM_SIZE -F ${swapdir}/swapfile

Depending on Apple's pager implementation, there may be some advantage in having one large swapfile vs. several small ones. My ibook (384MB) and imac (256MB) seem snappier with these settings, but that may be my imagination.

Note that the above code uses programs found in /usr/bin, /usr/sbin, and /bin, so it should be safe to run as long as /usr is on your boot volume.

[ Reply to This | # ]
lostboi tutorial
Authored by: Drake on Jan 10, '03 11:06:20AM
I received an email from a Dean yesterday commenting on my tutorial on how to move the swapfile in Jaguar. He had problems with the swap after doing a forced reboot. I tried it myself and it seems that Darwin starts-up the swap system before it checks and repairs the not properly unmounted disks, which you get after a forced reboot. Now there were some suggestions in the forums about placing the "Virtual memory system" at the end of the rc file. Not only didn't it work for me, apple must have a good reason how the rc file if ordered. Anyway i was pocking around in the /etc/rc.netboot file and found the following. Darwin autodiskmount it's devices before it actually mounts them, it uses (autodiskmount -F). So put this command before the mount session in the rc file and all your swap file worries are over.. at least they did for me on my G4 QS with 2 ide drives and mac os 10.2 (without any updates). If you need any help, i've updated my tutorial on moving the swap file at my website, any comments or suggestions are welcome. grtz lars. > move swap tutorial

[ Reply to This | # ]
lostboi tutorial
Authored by: muumi on Jan 26, '03 09:24:45PM

After reading loads of more or less controversial information on moving swap files, I decided to give lostboi's tutorial a go.
I ended up not being able to boot into Jaguar anymore. Was my mistake though. I wanted to put the swap file onto the same partition as OS 9, as I don't want to repartition my drive, and the OS9 partition is almost never used, and it's the first partition.
The reason why I could no longer boot after editing my rc file was that my OS9 partiton was called "Mac OS 9". The spaces caused the problem. I'm not sure if using a backslashes before the spaces would have resolved the problem. I guess it might, but I didn't try. Instead I renamed the partition to "Mac_OS_9", re-edited the rc file, and it worked like a charm!
So anyone trying this, make sure not to have blanks in your target's name.
I notice a percievable performance boost, and I can start loads of applications before getting pageouts now.
I use a PB G3 333mhz with 320Mb RAM, so any extra performance I can get is welcome, and this does give some, no matter what some people say. I can see it right in front of me, and I haven't even put the swap file onto a dedicated partition, let alone a separate drive.
I wonder why apple doesn't do this as standard.....
Thanks for the tutorial, lostboi ! :-)

[ Reply to This | # ]
lostboi tutorial
Authored by: muumi on Jan 26, '03 09:31:23PM
Oh BTW, I had forgotten to mention in the previous post, the link in Drake's post doesn't work. forgot the t in lostboi. here's the one that gets you there: swap tutorial

Reply to This | # ]
Moving swap in 10.2 revisited
Authored by: cluth on Sep 01, '03 08:37:26AM

I'm trying to undo moving the swapfiles to a second volume. I've changed my /etc/rc file to reflect swapdir=/private/var/vm instead of /Volumes/swap/.vm, but it still creates swapfiles on my Swap partition! I have no clue where it's getting that path from -- it seems I've been in every rc.* file and removed any trace of /Volumes/swap/.vm.

Any ideas?


P.S. It may help if I can capture the text displayed in a verbose boot. Someone told me I can read it in /var/logs/system.log, but only some of the text is reflected there, and it's missing the detailed VM startup results. Is there a place I can view the full text displayed in a verbose boot? That may help...

[ Reply to This | # ]