My MacBook constantly freezes because of using all RAM (8GB). The disk cache seems to be the cause. The command sudo purge only helps a little bit. In some older versions of OS X, my MacBook worked fine because it had (just) enough RAM for running Xcode (with big project) without constantly swapping.

This is the memory usage after compiling my project once. The memory usage of Xcode can grow few hundreds more MB after few hours of usage.

enter image description here

  • The memory pressure us low and 0 swap so I don't think you are running out of memory – mmmmmm Mar 24 '15 at 17:38
  • CPU usage was low when the system was hanging. The hang was highly correlated to memory usage – keithyip Mar 25 '15 at 1:00
  • The memory usuage shown here is minimal and not a problem – mmmmmm Mar 25 '15 at 11:06
  • @keithyip You experimented a bit in the past, so what are your current vm_compressor settings? Is your "project" freely available (e.g. github) to run a test with it? – klanomath Mar 25 '15 at 18:19
  • @klanomath I switched it back to the default value, 4. I tried to disabling the compressor because OS X was not unable to maintain constant FPS in games. The only drawback was that OS X crashed if there was not enough RAM. The project is my company's app. It is closed source. A easy alternative way to occupy your RAM by using Chrome without killing it for a few days or try using memory_pressure. – keithyip Mar 26 '15 at 1:02

This isn't directly answering your question since I don't know of a way to disable the file cache mechanism in OSX. That being said, I can't think of a good reason WHY you would want to do so in the first place? What makes you so sure it is because of the file cache?

The file cache is a dynamic thing in that it gets larger as you do more I/O with your disk, but gets purged and shrinks as soon as an application needs RAM to get something done. What lives in the file cache is copies of recently used files with the idea that if you need them again shortly thereafter, the I/O will be much faster since it is already in RAM. While this is similar to the RAM cache function of the older MacOS, the big difference here is that it is completely dynamic and grows to make use of unused RAM in your system and will shrink as soon as ANYTHING needs RAM. In other words, it isn't locking up your memory and shouldn't be the cause of any slowdowns on your Mac.

That all being said, there is somewhat of a balance between how OSX manages your RAM. I have seen that there are small delays as things go in/out of the "compressed" state and in general the idea is that once something is compressed, it will stay there until there is a real need otherwise. The bigger cause for a delay would be if you were using swap since that is the slowest form of memory, but your screenshot even indicates 0 bytes dedicated to swap. Compression and swapping aside, I wouldn't be surprised if there is some overhead and delay as a result of shuffling all this around when all of your RAM is being utilized. However, the question might be more around what applications are freezing up when you're in this situation. Perhaps even your disk is near capacity and you're rather experiencing the fact that HFS+ is much slower when the disk is near full?

In general, you might have some short term benefit from purging or disabling the file cache, but I would hazard a guess that it would actually degrade your performance since you wouldn't get the benefit of a filesystem cache.

| improve this answer | |
  • "sudo purge" was very slow (order of minutes) so I guess the problem was the poor performance in managing the disk cache. All the hang problems appeared after OS X update with new memory management. When they happened, they were highly correlated with the memory usage at 7.99GB. The freeze was system wide. Xcode and Safari kept being unresponsive. The small choke was bad too but less problematic and was another story. For you reference, my disk free space is 80GB. The derived data of my project is 6GB. The old memory management was very good in working with that. No small choke, no big freeze. – keithyip Mar 25 '15 at 1:34
  • That would be helpful if someone could provide commands to disable disk cache for testing. The new memory management is a joke (or a business strategy?) for old Mac devices. – keithyip Mar 25 '15 at 1:45
  • @keithyip, I actually preferred RAM performance under 10.8 in comparison to what is now going on under the hood in 10.9 (can't upgrade to 10.10 due to apple borking the smart card handling). I definitely notice pauses here and there which I imagine is analysis and freeing up of portions of in-memory apps which are deemed valid to be unloaded. Perhaps somewhere in here is why the newest Apple coding direction is trying to get away from relying on the garbage collector of ObjC? – bjb Mar 25 '15 at 16:50
  • @keithyip & bjb - I agree, memory management was great in Mavericks… until you got near your actual RAM, then it was abysmal. My solution was to put another 16GB in - so i have no clue how Yosemite deals with it as I never get there anymore :( – Tetsujin Mar 25 '15 at 18:48
  • I am using a 2011 Macbook pro. Sadly I have to keep updating OS X because Xcode needs newest OS X. It does not worth upgrading the RAM so I am looking for software fixes. – keithyip Mar 26 '15 at 1:14

If sudo purge didn't help, try disabling dynamic pager, e.g.

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

Warning: This completely disables the Mac OS X paging ability, so use it only when you've huge amount of RAM, but your Mac is still using swap files. If your system has SIP protection, you'll have to disable it first (not recommended).

You can also remove swap files manually from /private/var/vm/, e.g.

sudo rm -f /private/var/vm/swapfile*

then restart the computer.

Source: Mac Virtual Memory – What it is, the Swap Location, and How to Disable Swap

To disable memory swapping completely, set vm_compressor to 1, e.g.

sudo nvram boot-args="vm_compressor=2"

or set it to 4 to default, see the other values (from vm_pageout.h):

#define VM_PAGER_DEFAULT                0x1 /* Use default pager. */
#define VM_PAGER_COMPRESSOR_NO_SWAP         0x2 /* In-core compressor only. */
#define VM_PAGER_COMPRESSOR_WITH_SWAP           0x4 /* In-core compressor + swap backend. */
#define VM_PAGER_FREEZER_DEFAULT            0x8 /* Freezer backed by default pager.*/
#define VM_PAGER_FREEZER_COMPRESSOR_NO_SWAP     0x10    /* Freezer backed by in-core compressor only i.e. frozen data remain in-core compressed.*/
#define VM_PAGER_FREEZER_COMPRESSOR_WITH_SWAP       0x20    /* Freezer backed by in-core compressor with swap support too.*/

To check your current value, run:

sysctl vm.compressor_mode

To back to normal, delete boot args by:

sudo nvram -d boot-args

restart and reset your NVRAM.

See: vm_compressor=VM_PAGER_DEFAULT in Yosemite caused freeze when physical memory was full

| improve this answer | |

You must log in to answer this question.

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