Disable Swap Files In OS X

Every now and then I need to reclaim that space in /var/vm or I need to stop a process from paging to swap files while I’m troubleshooting something else. I in no way endorse disabling swap files (which basically kills using swap files as a part of your overall virtual memory) for extended periods of time. However, it has saved me in the case of stability concerns long enough to get a system patched or something like that.

To disable OS X swap files, all you need to do is stop the com.apple.dynamic_pager daemon and restart. Use launchctl to stop:

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

Once restarted, you may need to remove the files in /var/vm as that is where the swap files are stored. To do so, rm the contents of /var/vm:

rm /var/vm/swapfile*

You should also be able to get rid of the sleepimage file in that directory if needed. Since this is supposed to be a temporary or troubleshooting measure, to turn swapping back on:

sudo launchctl load -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

Comments are closed.