Making tricky things easy …

Today I was on amazon looking for some technical literature (about Kubernetes if you’re wondering), when I suddenly wondered if there was a newer version of my old amazon firestick available …

There was.

All of a sudden … I switched to wondering how I was going to avoid being stuck with trying to offload an extra (older) firestick during a pandemic … when I see this …

When I hit that button, amazon showed me the exact order with my older firestick, offered me a 20% discount and all I had to do was drop it off at the UPS center. The only thing left to do was say … “yes, take my money”.

I did.

Making tricky things easy for your users will never go out of style.

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 🙂