How to disable swap usage on Mac OS and why you should do it (in 2020)

I just got myself a Macbook Pro with 32GB of RAM.

So imagine my surprise when after a few days of running it, I looked at my memory in activity monitor and noticed that I was running with almost 14GGB of swap ?!?!? (It eventually ballooned to 32-35 GB of disk at one point)

This had been a recurring theme on my old machine with 16GB of Memory. The swap would increase up to 16GB sometimes, as much at 19-20GB+ and I couldn’t understand why. I just assumed that when I got more memory the problem would go away.

So after asking around on twitter, I started doing some research on possibly turning off my swap file. This may seem drastic, but many years ago when I was still a Windows user, I’d managed to do the same thing without much ill effect, so I figured … why not?

The instructions and a detailed explanation of what you’re doing are here. But the long and short of it is that you need to boot into recovery mode and then run the command

sudo nvram boot-args="vm_compressor=2"

When you boot back into MacOS, you can check that you are running in this mode by running this command

$ sysctl -a vm.compressor_mode

to which you should see this in response
vm.compressor_mode: 2

At first I was very nervous about running out of memory, but then I noticed something interesting. MacOS was still using swap!!!!

I was bummed, I thought I’d gotten it wrong somehow ?, but I hate rebooting my machine so I left things alone and continued to monitor memory/swap usage.That’s when I realized something interesting … My swap file usage wasn’t disabled, it was just now extremely conservative. I’ve been using this for almost a month now and the most swap I’ve ever seen it use is 300MB.

This is my current system swap usage

MacOS running with swap "disabled"

MacOS running with swap “disabled”

Amazing right?!

Its exactly what I wanted, and I’ve run so far without any memory errors or problems. And that’s while I am also using Memory Clean 3, to help me occasionally reclaim memory. I’ve used Memory clean for years and just recently upgraded.

I must mention that I’m not doing anything particularly stressful like video editing, gaming. Just running a couple of docker containers and running some Rspec tests from time time time, so your mileage may vary. If you do turn on conservative swap file usage on MacOS please report back or tweet at me to let me know how it goes!

Update: 10/23/20
I found that enabling “Automatic Graphics switching” in the Energy Saver section of System preference made the system use up more RAM.

This makes sense, the dedicated AMD Radeon Pro 5500 GPU on my Macbook Pro has 4GB of its own dedicated GDDR6 memory (VRAM), so it makes sense that the integrated graphics system uses RAM when it needs to. 

Apple appears to have fixed the usage of RAM by the integrated graphics to to 1.5GB
Unfortunately this seemed to put lots of memory pressure on my system after a few days, to where I’d see the occasional crash.

So for now I have disabled this option, and my system seems more stable now as my Macbook Pro uses the GPU memory exclusively and doesn’t touch my RAM 🙂

 

  • Bruno Villanova

    Running smoother than ever now on my iMac.
    Thank you very much!

  • Tee Ele

    I have a MBP 16 with 64GB of RAM and noticed that swap memory is still being used at times, I simply don’t understand why that is. Do you recommend I follow your instructions to limit swap usage?

  • concept47

    I think that’s ultimately up to you. But at 64gb of Ram, I definitely would. 🙂