MacOS – How to disable disk cache in Yosemite

hangmacosmemory

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

Best Answer

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.