Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
It's often disabled by the less knowledgeable because they heard on some blog that performance shot up threw the roof. SSDs also provide a nice testbed because they are inherently fast. Don't do this. It will decrease stability, and over time lead to catastrophic effects. To this day, I have not see any real data (valid and reliable) showing a performance increase. And it is a critical component of an OS, whether you have 2 GB or RAM or 120. –  cksum Sep 8 '11 at 16:53
What catastrophic effects? Just curious... it seems to be making my machine (4GB MacBook Pro) a ton faster. For example, when I open new terminal windows there is no longer any blocking... it's instant where it took several seconds before. And I was able to open twice as many apps as I would normally use and nothing bad happened. –  orange80 Sep 16 '11 at 19:37
orange80: The usual cause of slow terminal windows is the login process looking up the previous login, which can be fixed by hushlogin: apple.stackexchange.com/a/54167/22570 -- did you happen to reboot after changing swap settings, maybe? There's no reason that terminal window speed would be improved by removing swap. –  Ken Aug 2 '12 at 20:42
I understand that with a small capacity SSD you might want to free space. But on the side of the performance, SSDs are way faster than HDs so I do not see how disabling swapping in a SSD based OS would really improve performance. Any experience on that? Thanks. –  user28722 Sep 7 '12 at 12:11
In Super User, with an accepted answer: Disable Mac's dynamic_pager? (2012-04-27) –  Graham Perrin Apr 27 '13 at 12:14
add comment

12 Answers

up vote 34 down vote accepted

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.

share|improve this answer
The mac virtual memory system is very lazy in that it only creates the physical swap files when it is time to swap out actual memory. Whatever speed up you might see by not having to delay things to accommodate a write to swap would almost certainly be offset by the previous speed gains of having swap available in the first place. Having swap makes macs faster. The rest of the answer is spot on - nicely done! –  bmike Sep 8 '11 at 16:49
@geotavros The virtual memory system in Mac OS X does not work the same as Windows. With 4GB of memory, trust me, your Mac will work faster with Virtual Memory enabled. Disabling VM will only cause you headaches and system instability. –  ghoppe Mar 20 '12 at 15:06
FYI, a modern SSD with write-leveling and a decent capacity (128 GB), written to continuously, will have a write-cycle-limit measured in centuries. That was a reasonable fear in 2000 with small, primitive SSDs, but not any more. –  Ken Aug 2 '12 at 20:29
For a MacBookPro5,2 with 8 GB memory the performance improvement is dramatic. For Snow Leopard or Lion in a VirtualBoxVM the improvement is astounding. In all three cases the OS appears to use memory in a way that minimises the risk of reaching the 'limit' (where all things effectively stop) but that risk remains, so it's sane to observe usage in Activity Monitor. –  Graham Perrin Aug 11 '12 at 18:37
For information VM (or Virtual Memory) should not be confused with swap file. Windows, OS X, *BSD, Linux, many Unix are all using virtual memory. Usually the archiecture of this OSes gives a VM per process, the process allocated memory within this area and the OS takes care to put this allocated memory on physical RAM or swap as the OS deems so. Having or not swap can change in one way or the other performances for various criteria (speed, responsivity, etc.), this will depends of each one of us workload. As English people say: your milleage may vary! And greatly in this case. –  Huygens Feb 24 '13 at 14:14
show 1 more comment

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.

share|improve this answer
I'd like to echo what a bad idea this is. Swap is used even if you have 16 GB of RAM. Not as much, but a tiny bit is already written into swap. Always. It's a safeguard. And while the OS may run without it, you cannot be sure how 3rd party apps behave. HD get written to. It's a fact if life. And no, there will be no "real world" performance increase. That's a placebo. –  cksum Sep 8 '11 at 16:48
@cksum In some specific server scenarios, sysadmins will disable the swap file because it does make that specific configuration faster, but they don't do that without testing to make sure it both (a) won't run out of memory and (b) it actually is faster. But that's a server run by professionals: it's never necessary on a consumer machine. –  CajunLuke Sep 8 '11 at 17:02
@cksum I could agree with your first sentence, you are correct with the second, third and fourth one, but there rest is rubbish. An OS does not swap for "safeguard", an OS is swapping to make more available memory to active process that would require it or to speed up I/O by buffering data, so long unactive memory can be freed in the RAM. When you develop an application, you request memory to the OS, this memory is part of your virtual memory usage, as a developer or application you do not know if the OS put that memory or part of it in the physical RAM or swap. (to be continued) –  Huygens Feb 24 '13 at 14:20
So if a 3rd party app requests more memory than there is available, the OS will give it an error. This is independent of having swap or not. Having swap will put just the limit higher, that's it. As for performance, if you have 2 users logged in, if the active user use a video editor with huge files, the OS might start putting memory pages of the inactive user in the swap to speed up the tasks done by the active user. You get better performance in terms of speed in this case. However, switching to the other user will be slower, the OS has to read back the swap. This is not a placebo! –  Huygens Feb 24 '13 at 14:25
@Huygens "Having swap will put just the limit higher, that's it." You mean sort of like a safeguard? "speed up I/O by buffering data" Swap isn't used to speed anything up. RAM is, and always has been, faster than a hard disk, SSD or HDD. Swap is used when no more RAM is available to allocate to a given process. It's a fallback... a safeguard against completely running out of memory to allocate. That's it. There isn't any more to it than that. –  cksum Feb 24 '13 at 20:14
show 3 more comments

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.

share|improve this answer
I find the opposite, a huge speedup when dynamic_pager is disabled. The screenshot currently at apple.stackexchange.com/a/60661/8546 shows virtual memory size and page ins measured whilst that daemon is disabled (whilst swap files are not used). –  Graham Perrin Aug 14 '12 at 15:41
What precisely is being measured to determine a speedup? (Or are you seeing the absence of lags or delays in the UI or something else that's not easily quantifiable or measurable?) –  bmike Aug 14 '12 at 15:43
Without measuring: with Lion, most things seemed noticeably faster – enough for me to use the word huge. More recently: 10.8 in a VirtualBoxVM, for example, to log in and resume Activity Monitor takes sixteen seconds with dynamic_pager, twelve seconds without. For a broader and more measured comparison we might use Phoronix Test Suite or Geekbench. –  Graham Perrin Aug 14 '12 at 16:23
add comment

I'll be the naysayer here: I disabled swap on my late 2008 unibody macbook pro and it improved performance noticably: Less waiting, faster switching between applications.

Mind you, I keep an eye on my free memory and I have 6GB installed. The few times that I hit the memory limit, the system crashed :-D

On my new MacBook Air I wouldn't dream of disabling swap, it's already fast with it enabled and it only has 4GB to begin with.

Another good reason people disable swap on an SSD is because they get tiny SSDs and need all the space they can get. In any case, don't do it.

share|improve this answer
+1 for mentioning the slight caveat on the 2nd ¶ –  koiyu Nov 23 '11 at 8:31
Awesome to have real experience where this worked. What was the RAM commitment on the machine when swap was disabled? What happened when you opened more apps than would fit in RAM? How much RAM did you have and what apps would run in that space comfortably without errors? –  bmike Nov 26 '11 at 15:33
@bmike, not sure, the system crashes :-D, 6GB and all the ones I use :). Aperture or XCode are real memory hogs and they could sometimes tip over the system but Skype, Mail, Adium, Safari, Chrome, iTunes and OmniFocus all fit nicely... –  w00t Nov 29 '11 at 20:14
add comment

My experience is similar to w00t's. I have disabled the swap file on SL and Lion because the performance increase works for me. Wired usage does get out of control after a week or so but a simple reboot fixes that. I do not have a SSD but a slow 5400rpm disk. SSD lifespans aren't actually as bad as people try to make them out to be though. If you're doing it simply because you're afraid of wearing out your SSD please see: http://www.anandtech.com/show/4159/ocz-vertex-3-pro-preview-the-first-sf2500-ssd/2 and http://communities.intel.com/thread/21717?tstart=0 Intel rates their drives for over 20GB a day, every day, for up to 5 years on a 80gb drive. Bigger sized drives will last even longer. The average user doesn't even use 10GB/day.

I make sure to monitor my 4GB memory usage with iStat Menus and use an Automator script with the "purge" bash command (requires Xcode to be installed) to clear out inactive memory and open up more free memory frequently. The few times I have had apps with memory leaks use up all the RAM, I did have to do a hard reset. The rare occasions of that happening and the speed up in general makes it worthwhile to keep the swap file disabled for me. I realize that I can't have as many apps open at once because of this as stated by others but I'm able to work with that.

share|improve this answer
Memory Scope has an option to automatically purge. (if dynamic_pager is enabled, I disallow purges.) –  Graham Perrin Aug 11 '12 at 18:57
add comment

I've been disabling swap on machines for many years, both on OS X and other UNIX variants.

I use a tool to alert me when memory is running low, and never worry about my system crashing.

My iMac has 12GB, and with swap disabled I almost always have 4GB free, even with multiple development tools, apps, browsers etc. open

share|improve this answer
What memory tool are you using? –  geotavros Mar 29 '12 at 15:05
add comment

Just throwing in my 2 cents for those who wish to disable swap BECAUSE of small SSDs: the sleepimage uses far more disk space.

And, for those concerned about the limited life of the SSD (particularly those with MBA's and hard-wired SSD chips that CANNOT be replaced), if your computer sleeps many times per day, the rewriting of the sleepimage may be a concern. My laptop sleeps a half dozen times/day easily. That writes 48GB of data to my SSD daily.

The solution in each case is to disable hibernation, and then delete the sleepimage file that is as large as your installed RAM (8GB in my case).

The downside risk: if your battery dies while your laptop is sleeping, your current state will be lost. This will be equivalent to a forced hard restart. No physical harm to the laptop, just a loss of productivity. If you disable hibernation, then run your battery low and can't charge, just have the code handy to enable hibernation!

To disable hibernation, in the Terminal, the command is as follows:

 sudo pmset hibernatemode 0

To enable hibernation, the command is as follows:

 sudo pmset hibernatemode 1

To delete the last sleepimage to free up SSD/HDD space (only makes sense if you turn off hibernation, else a new one will take up that space next time your computure sleeps):

 sudo rm -rf /var/vm/sleepimage
share|improve this answer
add comment

Disabling swap does increase performance. For example I regularly use Aperture and when swap grows performance worsens and when it goes beyond 1Gb I have to restart OS to clean it and restore performance. Note: machine has 6GB of RAM and NOT all of it occupied, about 3GB is free, but 1G is swap significantly degrades performance.

share|improve this answer
add comment

I just disabled the swap file on my 2011 Macbook air (4GB RAM, 128GB SSD) because I was sick of the swap file slowly eating up all my remaining HD space and then having to restart. This way, the idea is that I will just run less programs.

I'll see if that really works, or if I will have to restart anyway to clear the "Wired" memory, but for now it appears to be working well. The one time the memory got really full the computer slowed down just as much it does when my SSD runs out of memory - but it recovered a lot faster as soon as I quit applications. (And I was actually able to quit applications, which I usually am not when the SSD fills up).

I'll see how it goes stability wise, but so far I'm a happy camper. It also forces me to run fewer applications (and Chrome tabs) at a time, which is good for task focus.

share|improve this answer
add comment

Just a personal experience.

Memory Amount    |
 4 GB            | Don't disable it, Mountain Lion itself boots with about 1 GB.
 8 GB            | Do if you don't run apps that requires more than 1 GB of memory, in short, virtualization software, Photoshop, and stuff.
16 GB or more    | Do it! Even Xcode or Final Cut won't use more than 4 GB of memory, at least as I've seen. Just don't run too many virtual machines though.

A quick note: If your Mac uses integrated graphics, its memory is shared with your main memory with kernel_task. Thus, you will have to subtract that amount from your total usable.

SSD users, it's satisfying to have more space, but it's important to know that virtual memory thrives on SSDs, you can get whole lot of performance gain from it. Does it hurt the SSD? Yes, but you will long replace your Mac before you notice.

share|improve this answer
I've personally disabled virtual memory on my Retina MacBook Pro with just 8 GB memory. Here's the math, the system uses about 2 GB memory counting integrated graphics. So that's 6 GB for me. I do Xcode for work, at that consumes no more than 2 GB memory. So I have plenty to spare. –  Shane Hsu Jan 30 '13 at 1:55
add comment

Executive summary

A swap area (called swap partition, swap file or page file) is just a mechanism to augment the physical memory addressable by the OS.

If you are low in available physical RAM, and on today's machine, I would say if you have 4 GB or less RAM. Then you should probably have a swap. But this depends on your workload and how you use your machine.

If you have more than 4GB of RAM, there is a good chance that your system might never use the swap. So if the swap is enable or not, this won't change much.
Although this depends on other factors, the longer your machine will be running the more likely the OS will swap small unused portion of the RAM to the swap eventhough there is plenty of place left apparently. However, often the system use the "free" RAM for file buffers and other stuff, and some workload might make your file buffer use all available RAM.

Background information

Any way what would happen if you disable the swap and your memory is completely used? Well, the next time an application request more memory (like with a malloc or realloc), it will receive an error! If it is properly coded, the application will detect it, but handling such an error and terminating the program gracefully could be a challenge still! However, many developer don't test for successful memory allocation and often the application crashes as soon as this non allocated memory is going to be used. So there is a strong chance that the application will crash, and actually that many application will crash because you have more than one application usually running at the same time. Hopefully, the kernel itself should be immune, but in my experience it was not always the case.

If you have swap, you will have the same behaviour, but you have a higher limit so chances are that you won't reach that limit.

I have personnaly 2 machines with 8 and 16 GB of RAM. My personal usage of these machine should never bring me close to use all of this RAM (today! perhaps in a few years that could be different). The only reason I would hit the physical RAM limits is that a process got rogue and is consuming all the RAM. Having no swap is a relief, the kernel will promptly kill the rogue process as soon as it hit the RAM limit. If you have swap, you will get a painful experience (maybe not on SSD...) as your system will swap and swap and swap and become sometimes totally unresponsive until hopefully your kernel kills the culprit!


You should not be scared by people telling you something horribly wrong might happen if you remove swap. If you do so, your physical address space will be reduced, much like if you would go from 4 GB of RAM to 2 GB. Would you do such a thing? Then you should not remove the swap. You can however decide to limit it, and that would be wise.

If one thinks his workload might bring him to use close or more than the available physical RAM, or if one needs a lot of I/O (read/write to disks), then swap should be kept.

When swap should be kept, a user should try to set limits to the amount of memory a process can use. On a Linux system, one could use cgroups memory limits to avoid that some process gets out of control, I don't know the equivalent on OS X but that should be the way.

However, if one has more than enough available memory for his workload, then he could safely disable swap or he could keep it. It won't change much even in terms of performance because if the system does not use the swap, then you don't get hit by a performance drop (especially visible on an old rotational hard disk, less so on SSD).

Using the same trick as above to try to set memory limits per process or group of processes is also beneficiary in the case of more than enough available RAM.

My own example

I have an old PC with 1 GB RAM, there I do have a big swap: 4 GB so I can run Firefox and other application on it. I tend to use as little application (or tabs in Firefox) as possible to have a correct user experience though.

I have a small server with 8 GB RAM. There I know exactly my work load and I do not want my server to slow down because a process got rogue and is consuming all memory. There I have no swap and cgroup memory limit enforcing barrier, so applications or services can crash but not the kernel. Btw, this is a Linux machine.

Then, I have my Mac with 16 GB RAM. I am not the sole user of it, and we would not mind waiting when switching user. There we do have swap, it is difficult for me to plan the work load of other users of this computer. Even if I would be the only one I would use swap. I often run several VMs and use memory consuming applications, but not all at he same time, so I would not mind the OS swaping in an unused app so I can get faster disk I/O or launch yet another VM. Althoug up to now, I haven't seen this machine swapping!

share|improve this answer
add comment

The repeating pattern here is this:

Those who HAVE disabled swap file experienced improved performance (with sufficient physical RAM)

Those who have NOT disabled swap space are certain that it will not work, and something terrible will happen, and are ardently advising that you not do it.

This is due simply to two things:

  1. Outdated ideas about the scarcity and high cost of physical RAM which are no longer valid
  2. A really poor swapping mechanism in MacOS causing use of swap files when there is sufficient physical RAM.
share|improve this answer
If swap space was used ONLY when needed, then it would be great. However, that's not the case. I run 2gb and 4gb virtual machines on my MacOS. If I have 1.6gb of free RAM, I should be able to run a 1GB virtual machine (or other program), but I can't because the OS starts paging it out. As a result, I can only use about 85-90% of my RAM. If I want to get to ALL of my RAM, I need to disable paging. I do this on all my Windows machines, and would like to do the same on my MacOS. If a program runs out of RAM, then it will fail. That's what I want to happen. I don't want other, running applications –  user26622 Aug 2 '12 at 19:03
YMMV. I don't disable swap anymore as I've not found it to help performance any on modern, RAM-loaded machines. I used to in the past as it did help back in the bad old days. Nowadays not only do I NOT see any performance change by disabling swap, I DO see greatly increased application instability. –  Brian Knoblauch Aug 10 '12 at 18:24
The undesirable thing that will happen is that a human will forget that they can't launch another program and in time, the machine will crash due to a low memory error. Whether this is terrible, humorous, educational depends on the timing, your backup frequency and tolerance for delays. –  bmike Sep 7 '12 at 12:29
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.