Apple - Why would I disable swap file in Mac OS X?
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.
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.
You have two great answers that explain why this is a bad idea in almost all cases where the system can write to a storage device.
The reason you can disable swap is so the system can run on read only media such as a CD, DVD, locked network image using NetBoot or a read only USB fob like the new Lion installer or recovery fob that ships with some macs that lack optical drives.
Having virtual memory means that the system can run substantially faster and use less RAM when many programs use the same common library code. Each program thinks it has a private copy of all the code it needs, but when virtual memory exists, the system has a nice way to map the same physical RAM to different programs.
Disabling swap prevents the mac from using a tiny portion of your drive as a cache for some memory that has been calculated but the program wasn't smart enough to write those results itself to a proper cache.
If you have a backup and time to experiment, why not turn it off and see how your experience changes.
I would keep my swap on even if I knew for certain I had to pay for a new drive annually. The speed up that swap gives me is HUGE. This is not always so, and at times when the system is thrashing or paging - you can have the opposite. Many people choose to run without swap so that they get a memory allocation error rather than let their mac start paging since that can slow down a machine when things aren't running smoothly.
Your case with a SSD could be different, so do let us know if you try it.