Why would I disable swap file in Mac OS X?

I came across a thread about installing an SSD drive in MacBook Pro.
Someone in the comments also recommended to disable the swap file but didn't say why:

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
sudo rm /private/var/vm/swapfile*

I wonder why one would want to disable the swap file in Mac OS X.
Does it increase performance? Stability?
Any downsides?

Finally, does it make any sense to disable swap file when not using SSD?


Solution 1:

wonder why one would want to disable the swap file in Mac OS X. Does it increase performance? Stability? Any downsides?

I suppose people would do it for an SSD drive because those drives don't have the same lifetime as standard magnetic spinning-disk drives. There are a more limited number of write cycles, so presumably using them with a swap file would use up these cycles more quickly.

Finally, does it make any sense to disable swap file when not using SSD?

If you have a lot of RAM, this would possibly speed up performance, but it's not a good idea in general. If you do run up against the memory ceiling, things are going to get flaky.

Also, wired memory isn't released when it becomes invalid, it is only released when a page out event is triggered, which won't happen if Virtual Memory is disabled. So it won't take long for all your memory to be gobbled up even if it is no longer used.

Solution 2:

The reason they disabled the swap file is likely paranoia about SSDs having a maximum number of writes per block. Swap files can be written to frequently, possibly causing disk fragmentation (as well as file system fragmentation) and, eventually, possibly causing the disk to fail sooner.

That said, this is definitely a case of premature optimization. It is almost always a HORRIBLE, HORRIBLE idea to disable your swap file. The swap file is there for when your running programs consume more memory than you have physically installed. If you disable it, you may not be able to run as many programs at the same time (and the limit is far lower than you'd expect) or you may have issues (like freezing and having to hard-reboot the machine) when you run out of memory.

The latter I've experienced (with the swap file enabled) when running out of disk space. I had a 120 gig drive with ~3 gigs free. While playing Civilization IV (a large, full-screen game), the system ran out of hard drive space (~50 megs free) and presented the "kill apps now" window. This was hiding behind the full-screen game, so the system just locked up. If I hadn't been able to ssh in from another Mac to kill several apps remotely, I'd have had to hold down the power button.