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

Move your swap space onto a disk image System
hello everybody, I was reading a ResExcellence article about improving app run times (and minimising pageouts), but it required one to start up from the OS 9 disk (ugh!) and format the existing hard drive (ugh! ugh!). So I created an alternative method.

I have the information up here, but I'll copy and paste the steps here. Read the rest of the article for the step-by-step instructions.

[Editor's note: I have no idea if this works nor the implications of trying it. There are other tips posted here with info on moving swap to another hard drive, but this seemed interesting enough to merit posting as an independent alternative. As with anything like this, make sure you have a good backup before you start changing the system files!]

  1. Unmount all disk images.
  2. Create a 500MB disk image formatted with Mac OS Extended (in this example I will use the Desktop) and image name vm.
  3. Move the disk image to the root directory /
  4. chmod both the .dmg file and the disk image to 700 as a security measure (or any other value that would be relavant to your usage)
  5. Note the path name of the disk (mine is /dev/disk2s9)
  6. Get root access with su and enter: pico /etc/fstab
  7. Enter this: /dev/disk2s9 /vm.dmg hfs rw 1 2 (NOTE: you should change this to suit your device)
  8. With root access open /etc/rc with pico /etc/rc (see footnote)
  9. Scroll down a bit and locate the line which starts with swapdir=/private/var/vm
  10. Replace the line with swapdir=/Volumes/vm/vm
  11. Reboot the computer.
Of course, there will be a disk image icon on your desktop, which would waste unnecessary space (or look plain ugly). If you have the Developer Tools installed, the disk can be hidden. So, following steps from Mac OS X Hints, do this: sudo /Developer/Tools/SetFile -a V /Volumes/vm/ and (if you want) sudo /Developer/Tools/SetFile -a V /wm.dmg (this information from a previous Mac OS X Hints hint).

Does it work? Well, it does. Pageouts are less (but not zero), and iTunes starts within three bounces the first time round on my iBook 333MHz (which is a miracle). Subsequent times iTunes launches in one or two bounces. System Prefs is launched from 8 to 3. IE launches in three bounces, from five. Terminal launches in 8 from 13 bounces.

Enjoy.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[6,302 views]  

Move your swap space onto a disk image | 13 comments | Create New Account
Click here to return to the 'Move your swap space onto a disk image' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Interesting exercise but silly to do
Authored by: chabig on Dec 26, '01 11:45:52AM

Sometimes it's fun to play with your system and see what you can do or make it do. But I am suspicous about these claims of increased performance. Here's why:

When you create a 500MB disk image, you are really just creating a 500MB file on your hard disk. If the system needs more memory than you have RAM, it's going to swap memory to the disk image file on the hard disk. Now this is exactly what OS X's virtual memory system does! It swaps memory to the hard disk. You haven't gained any advantage. In either case, memory contents are going to go to the hard disk. All that you've done by creating a disk image is generated an extra layer of overhead for the system to deal with.

Another way to look at this is this...UNIX virtual memory has been around for a long long time. Computer scientists study this stuff to death to find more efficient ways to do it. I think you are fooling yourself if you think you can improve on the time tested algorithms they come up with. Do you think tuning the VM system is not in Apple's best interest?

The best thing you can do to improve the performance of your system is to add RAM. At today's prices, you should just max out your RAM and forget about it.



[ Reply to This | # ]
Interesting exercise but silly to do
Authored by: barrysharp on Dec 26, '01 02:20:12PM

I absolutely agree with this position.

If any swap config changes need making then do so by placing swap on its own small 1gig HD with it's own i/o data path.

Best soln is to avoid swapping altogether (not really possible but can be greatly minimised) by adding RAM -- problem solved.



[ Reply to This | # ]
Interesting
Authored by: Anonymous on Dec 26, '01 06:46:07PM

I am amazed this actually works.

I have a 7 gig hard drive (slot-loading iMac) with only one
partition. If this helps avoiding disk fragmentation I am going to
use it for now. I can always change it back to the default if I
need to.

I also have an iBook DV with a partition each for X, 9, and swap. And it
works fine there as I only have 128 RAM. The fact that I can get by with that setup with the minimum of RAM speaks well for setting a dedicated space for swap.

Thanks for the tip.



[ Reply to This | # ]
Bad
Authored by: bhines on Dec 27, '01 01:49:19AM
Here's what they said on the darwin-dev list about this idea. Sounds pretty bad. " One of the worst ideas i've ever heard of" to use his words.
From: Shantonu Sen Date: 2001-12-24 09:44:42 Subject: Re: vm and performance improvements ------------------------------------------------------------------------ > I would like to ask why relocating the vm directory (which contains the > swapfile) to another drive partition or a mounted disk image (on > startup) improves application relaunch times. Can you provide data on how much launch time improves? What about other file access performance? How much RAM do you have? Do your "improvements" work on machines with 64MB RAM? 128MB? (boot with your boot-args OF var set to maxmem=64). > Is there any specific reason why Darwin does not implement such an idea? Because they're terrible ideas, and just move the performance issues elsewhere. Putting swap on a disk image is one of the worst ideas i've ever heard of. Disk images under Mac OS X (which are not in Darwin, but I will address it anyway) are backed by user level processes using the IOKit user client API. Just imagine if your system gets low on memory and has to swap out 10 pages from hdid (the user client process). The filesystem write goes to the bsd dev to IOKit and then BACK OUT TO HDID. If critical pages were in the process of being swapped out, suddenly they're needed again immediately. Mixing VM at the mach level and disk images at the IOKit+userland level is a terrible idea. Any performance you think you're seeing is probably because the underlying disk image being cached by UBC. I'm guessing you have a lot of RAM and this works for you, great. You should try just disabling dynamic_pager and seeing if you see the same performance (I would expect you would). Check out the darwin-dev and darwinos-users archives at www.darwinfo.org and search for "swap" for some more discussions. Shantonu


[ Reply to This | # ]
This entire thing is moronic...
Authored by: Anonymous on Dec 27, '01 03:59:41PM

Moving the swapfile doesn't make a damn bit of difference! What's the difference to the system between volumes? An inch or so of drive head movement. On modern drives that distance takes MILLISECONDS to move. Besides, the system is smart enough to grab a contiguous 80MB chunk when it builds a new file. If it can find one, that is; and if it doesn't your drive is so horribly fragmented that performance is now no longer a VM issue. And the VM system uses chunky allocation anyway - the most efficient way to allocate space. The ONLY time this hack would help is if you were badly thrashing (totally out of memory, swapping entire processes out), and even then it would be much too little much too late.

Moving the swapfile does absolutely NOTHING to reduce pageouts! The pageouts still occur normally - the hack claims to reduce only the time needed to execute the paging.



[ Reply to This | # ]
Sorry about double post!
Authored by: Anonymous on Dec 27, '01 04:04:43PM

OmniWeb was being odd and wouldn't load the page after I clicked post, so I stopped and hit post again. Stupid thing to do. ;D



[ Reply to This | # ]
This entire thing is moronic...
Authored by: Anonymous on Dec 27, '01 04:02:46PM

Moving the swapfile doesn't make a damn bit of difference! What's the difference to the system between volumes? An inch or so of drive head movement. On modern drives that distance takes MILLISECONDS to move. Besides, the system is smart enough to grab a contiguous 80MB chunk when it builds a new file. If it can find one, that is; and if it doesn't your drive is so horribly fragmented that performance is now no longer a VM issue. And the VM system uses chunky allocation anyway - the most efficient way to allocate space. The ONLY time this hack would help is if you were badly thrashing (totally out of memory, swapping entire processes out), and even then it would be much too little much too late.

Moving the swapfile does absolutely NOTHING to reduce pageouts! The pageouts still occur normally - the hack claims to reduce only the time needed to execute the paging.



[ Reply to This | # ]
Not a silly thing, but dangerous.
Authored by: Scott Byer on Apr 12, '02 04:06:00PM

Head movement time on disk drives is still significant, as is dealing with fragmentation. HFS+ still fragments reasonably quickly, so a dynamically grown swapfile can still suffer performance issues related to that.

The best thing to have is a small, fast drive dedicated to swapping. Second best is a dedicated partition, but thrashing of the disk head can negate those gains if the physical disk that partition is on is not partitioned "wisely".

Swap files are accessed frequently, and often in very small chunks (system VM page size), and if the system isn't and can't coalesce the I/Os from the swap file, other heavy activity on the same physical disk can significantly impact performance.

!!!BUT!!! This is a dangerous area if you're not familiar with start-up init states, especially related to mounting volumes.

There is a GUI program I saw somewhere (swapcop?) which definitely does some incorrect things when moving the swap, which can really mess up a system.



[ Reply to This | # ]
HELP HELP HELP !! SwapCop messed it up !!
Authored by: pagmac2001 on Apr 13, '02 08:49:38AM

On my ibook 600, I already had a 2Gb part with MacOs X and the rest of the disk allocated to my files and Macos 9. As I just had 128 Mb of RAM which makes the system a sluggish, I wanted to give a try to SwapCop (without really knowing that it would be that buggy).

So I moved the swap file from the system's one to the large one. Funny enough I really saw some performance improvements (maybe it was just me, but I felt the system's responsiveness was better). But then I wasn't able to delete or move any file contained in the disk where I put the swap file, as if it was owned by another user. Interesting, huh ??!!

So I moved it back to its original place using swapcop, but nothing changed.

So my question is simple. Is there any means to avoid reinstalling the whole system, which I've just done 2 weeks ago.

If anyone can help.

Pagmac2001



[ Reply to This | # ]
HELP HELP HELP !! SwapCop messed it up !!
Authored by: Alex281 on Apr 13, '02 02:56:36PM
There are to things to try here: 1) Show info on the files partition and under priviledges check "ignore priviledges on this volume" then log out and in again. 2) If you are sure that there are onlyfiles and os9 files on this partition then open a terminal and type:
 sudo chown -R "shortname":staff /volumes/"yourpartition" 
where "shortname" is your short user name and "yourpartition" is the name of your partition in question, without the quotes of course. Then you will be prompted for your admin password. This changes the owner of all files on that partition to you, and the group to a group you belong to.

[ Reply to This | # ]
HELP HELP HELP !! SwapCop messed it up !!
Authored by: pagmac2001 on Apr 13, '02 03:59:54PM

Thanx !!! It worked perfectly. For now at least because I just tested it and I may encounter further hidden problems later. But now at least I can modify my files normally.

Cheers



[ Reply to This | # ]
HELP HELP HELP !! SwapCop messed it up !!
Authored by: pagmac2001 on Apr 13, '02 04:01:45PM

Thanx !!! It worked perfectly. For now at least because I just tested it and I may encounter further hidden problems later. But now at least I can modify my files normally.

Cheers



[ Reply to This | # ]
Sorry for the double post
Authored by: pagmac2001 on Apr 13, '02 04:05:28PM

Still this dial-up connection bug which disconnected me.



[ Reply to This | # ]