MacOS – way to limit the size of the disk swap file in Mac OS X

macbook promacosvirtual-memory

It seems to be that in OS X, whenever you are out of ram the system happily swaps to disk. This easily becomes an disaster due to the fact that the swapped out memory eventually fills my drive. On my Macbook Air with 2GB ram and 64GB disk this is a major problem.

In order to solve this I've created a crontab running a purge-command every 10:th minute. It minimizes the swap from growing and also makes the system more responsive whenever the system is swapping. I've tried to disable swap but it's far to unreliable.

Can you configure this behavior? Is there a better solution?

Disk swap on OSX never stops growing

$crontab -e

*/10 * * * * purge

Best Answer

Yes you can configure the dynamic_pager, but for most it is simpler to just disable it and see which program crashes due to the inevitable out of memory errors.

Why would I disable swap file in Mac OS X?

Pay attention to programs that implement their own virtual memory / cache / paging systems like virtualization and the Adobe Suite in case you have inadvertently tuned them to use more RAM than is available on the system. They tend to be first on my investigation list when I see a mac with runaway swap allocation on the filesystem.