Quantcast
Viewing latest article 5
Browse Latest Browse All 14

Hibernation and turning swap off

Having 16 GB RAM today is nothing extraordinary. Swap seems to be a useless thing. And it perhaps is. Even if you are able somehow fill up those gigs of memory then it is caused probably by some extremely hungry program which will initiate a horrendous swapping and your system will become virtually frozen.

Easiest solution is to have ho swap partition or no swap entry in /etc/fstab. But the hibernation will not work.

First step – turn off swap on boot – add “swapoff -a” to /etc/rc.local.

Then you need to turn on the swap before hibernation and turn it back on resume. Create a file /etc/pm/sleep.d/01_swap with content:

case "${1}" in
    hibernate|suspend)
        echo 3 > /proc/sys/vm/drop_caches
        swapon -a
        ;;

    thaw|resume)
        swapoff -a
        service preload restart
        ;;
esac

Dropping caches is a good way to really minimize amount of data written to swap. My experience tells me that the drop speeds the hibernation up. I also use preload program for faster programs starting after fresh boot. It is necessary to restart it after resuming.

And remember that you need bigger swap then your RAM!


Viewing latest article 5
Browse Latest Browse All 14

Trending Articles