Can I turn off swap and/or memory compression on macOS 10.12, Sierra?
Is there a way with macOS 10.12, Sierra, to safely turn off compressed memory? And is there a way to turn off safely swap?
This was possible on macOS 10.9 and macOS 10.10. Although it sometimes crashed on macOS 10.10.
On macOS 10.11, disabling compressed memory and swap caused a reproducable issue, click shutdown and OS X freezes.
Since then I didn't dare to experiment with it in macOS 10.12. But I'm still annoyed that the system wants to use compressed memory for no valid reason (at these fast SSDs I may not mind the swap that much though).
Regarding, vm_compressor_mode (vm.compressor_mode) values for enabled compressed memory in OS X. Value 1 for vm.compressor_mode
will this work on macOS 10.12 or crash like on macOS 10.11?
Regardless of whether you use some version of "official" settings to turn off swap, it is never really safe to do so.
Quick refresher about "swap". Swap space is memory contents stored on disk. In order to run more programs than physical memory allows, the operating system can "swap out" some memory, meaning write the contents of memory to disk, freeing up physical memory for use by other programs. When a program needs to access memory that has been swapped out, the OS "swaps in" the memory, meaning it reads the data from the disk back into physical memory. If memory is still full, that means the OS has to swap out some other memory before swapping in the requested memory. This whole scheme only works if there are big chunks of memory not being used for big chunks of time, but that can be the case on Mac, where your word processor can take a break while you are reading your web browser.
With swap, the system can use as much "virtual memory" as you have available disk space, and performance will degrade gradually as a higher percentage of memory is on disk. Without swap, the system can abruptly run out of memory, and because swap has been available for decades, the systems really do not handle running out of memory well. Your system and applications can get into all kinds of weird and unhealthy states because running out of memory is just not something people plan for anymore, or more importantly, test for. So even if the OS and apps are supposed to handle out-of-memory conditions, you will very likely run into bugs. If you are going to turn off compressed memory, then it is even more likely you will need swap. You can read first-hand accounts of system freezes due to running out of memory and not having swap in Yosemite.
Swap is known (by the OS) to be slow, so the software in the OS and affected app software like media players know how to keep critical data in memory and out of swap. If you find the system is using swap and you don't like it, then quit some applications (or close some browser tabs) until you get your "memory used" well below your "physical memory" and then the swap will gradually be emptied back into real memory, because it has to be read into real memory for a program to use it, and the OS will not swap out that memory back out if there is plenty of free physical memory available. (It used to be that swap space, once allocated, was never released from disk, but that is no longer the case, and even when it was the case, it was still true that the allocated swap space would be "free" or unused memory once all the in-use memory would fit in real physical memory.) This is what you would have to do without swap, anyway.
So the answer is (a) no, there's no way turn off swap and (b) if there were a way, doing it would lead your system to freeze and/or crash, and so is not worth it.
As for turning off memory compression, or as you put it "Value 1 for vm.compressor_mode
will this work on macOS 10.12 or crash like on macOS 10.11", the answer is much simpler: you cannot turn off memory compression. Starting with macOS 10.12 Sierra, if you try to turn off compression by setting vm.compressor_mode
to 1, the kernel treats it as though you set vm.compressor_mode
to 4 and turns memory compression on anyway. (See vm_pageout.c). So it won't crash, like with macOS 10.11, but it won't "work" to turn off compression, either. (AFAIK, the "freezer" modes are for iOS, to support fast resume when app switching. They require the kernel to be compiled with CONFIG_EMBEDDED
which the desktop OS is not.)