Tell macOS to only use swap and compressed memory when really needed (macOS 10.14 Mojave) As disabling swap and/or compressing memory is not recommended and also not a stable option after 10.9 Mavericks (despite the vm setting exists), I'm doomed after few days of running my Mac with my memory writing to the far-from-optimal pages of memory. As everything gets to swap or compressed memory so easily, I need to reboot my system relatively often (despite my 16GB RAM).

I'm searching for a solution which saves me from these slowdowns.

For example in Linux zramswap is optional. Also Linux has its swappiness value between 0 and 100 variable like

vm.swappiness=5


Also I may consider a solution about file cache (which usually randomly eats up tons of memory for no valid reason and fails to drop it before RAM turns to the less optimal purgatories of compressed memory and swap). For example here ZFS has an option on FreeBSD to maximize the size of file cache in memory:

vfs.zfs.arc_max="1536M"


In macOS the best known workaround for the file cache issue is running

# /usr/sbin/purge


Which is even "cronnable". So this flushes file cache, but unlikely to be optimal. It flushes too many things. Also if something is already in swap and/or compressed memory, despite the purge it stays there, so those softwares using them stay slow (and I feel that slowness, trust me).

Is there any solution to make macOS less likely to use file cache, compressed memory or swap (but still keep the first for performance and the latter two for emergency)?
I have the same issue and completely sympathise. Unnecessary swapping in the face of other options (e.g. shrinking the cached files area) has been a problem for years. It's made even worse under Mojave, where free memory - not even disk cache, but completely free - is present, but the system decides to use swap anyway. On an SSD, every write causes wear &amp; tear to the hardware, so this is actually (albeit in a small way) physically damaging behaviour. Since the SSDs in modern Macs are soldered onto the main board, the situation is dire.

I've been told many times by very confident posters on sites such as this that free memory is a bad idea, because it's sitting there consuming power and being of no other use. Disc cache (at least) should consume it. I agree with this; Mojave does not, compressing data and swapping it to disc even when gigabytes of free memory are present. On my home laptop, sleep cycles make it even worse. Right now, after a wake-up the machine has 11GB free, 5GB in use and 6GB swapped. The gibberish "memory pressure" colour is green, whatever that means. It's utterly absurd and indefensibly broken.

I used to think there must be something I was installing or doing wrong, but on brand new Macs at work with nothing extra installed, consuming RAM via opening lots of tabs in Safari will soon enough show use of swap space despite lots of free RAM.

And yes, it lags - badly at times. This definitely has a performance impact.

I know of no solution. Apple Engineering claim it 'works as designed'.