11

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?

  • 1
    Just buy more RAM. Trying to outguess the OS is a fruitless exercise. – Tetsujin Mar 5 '17 at 18:26
  • Is your Mac storage or processing power constrained? What limits are you hitting with specific processes or tasks? – Graham Miln Mar 5 '17 at 19:11
  • 16G ram I have with the Late 2016 Macbook Pro, also I have a Macbook Air 2014 with 8GB RAM. Believe me, I feel it becoming slow, when more and more items arriving to compressed memory. I also have a retina iMac, there sometimes Soundcloud starts skipping sound when memory is compressed, also scroll of some pages becomes slower, and they are fine when compressed memory is 0. I just want it off, even when you have lots of ram available, a sleep+wake or a half day idle time just puts things randomly there :( – dszakal Mar 5 '17 at 19:44
  • Actually this is the reason I restart my MacBook Air at least once a day. By the end of the day it is becoming slower as despite the 8GB ram and most of them being free or only uised for file cache, something is there in compressed. 16 gb ram devices are also restarted once a week and I try not to use sleep for the very same reason (lock screen only) – dszakal Mar 5 '17 at 19:46
  • 1
    Surely if you ruined compression off you will just run out of memory quicker so it does not help you – user151019 Mar 6 '17 at 11:27
-1

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.)

  • 1
    "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" - this is just simply NOT true. Not happening. You don't get back the swap without restarting the machine. Otherwise this question wouldn't exist at all with 9 upvotes. – dszakal Nov 5 '19 at 7:17
  • @dszakal I am not sure what you mean by "you don't get back the swap". What I mean, and observe every day on my Mac running El Capitan, is that Activity Monitor's Memory tab will show "Swap Used" decline to 0 bytes (or a very small number) after "Memory Used" goes well below "Physical Memory" (exactly how far below I do not know). Nothing in the question asks about reducing swap after it is allocated, so you cannot claim votes for it discredit my assertion. – Old Pro Nov 6 '19 at 4:22
  • On my MacBook right now I have 32gb physical memory, 11.95gb memory used, and 9.95gb swap used. I’ve spent the last hour trying to identify processes I can kill to reduce swap usage, and I’ve freed up plenty more memory than the swap used, but it’s not swapping it back. – ShadSterling Jan 9 at 6:24
  • @ShadSterling - Catalina or earlier? Rumor has it Catalina may have fixed/improved something related to it (I haven't upgraded yet, never had chance to check) - if it's doing the same on Catalina, we still have something to report for Apple – dszakal Jan 13 at 11:51
  • @dszakal, macOS 10.14.6 Mojave. I got it to stop using swap with sudo nvram boot-args="vm_compressor=2" and a reboot, which seems to disable swap and allow compression (as described in answers to other questions). – ShadSterling Jan 13 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .