Disable swapping on Yosemite

Under OS X Mavericks and below we just could launchctl unload the dynamic_pager plist, but trying to unload this plist doesn't have any effect since OS X Yosemite.

What is the new way to disable swap files now with OS X Yosemite?


Solution 1:

Have you tried something like this?

# Check installed RAM, disable VM if 8Gb or more.

mem_inst=`/usr/sbin/sysctl -n hw.memsize`

if [ "$mem_inst" -ge "8589934592" ]; then
    echo "8Gb+ Memory installed."
        if [ "$action" == "unload" ]; then
            sudo nvram boot-args="vm_compressor=2"
            sudo pmset -a hibernatemode 0
            echo "vm.compressor_mode set to 2"
        else
            sudo nvram boot-args="vm_compressor=4"
            sudo pmset -a hibernatemode 3
            echo "vm.compressor_mode reset to defaults"
        fi
            launch_control $action /System/Library/LaunchDaemons com.apple.dynamic_pager
    else
    echo "Less than 8Gb memory."
fi

This isn't something I wrote, was information I found.

Solution 2:

Here's what I do:

sudo pmset -a hibernatemode 0
(disables hibernation mode)

sudo rm -rf /private/var/vm/.
*(removes existing swap files)

sudo chflags uchg /private/var/vm/
(locks down the swapfile directory, prevents anything from being written to the folder)

As others have said, though, please only do this if you know what you're doing.