Thursday, May 10, 2012

flush swap

Once in a while swap fills up and there's 0 free swap space, so I like to flush it and make room.

swapoff -a
swapon -a

does the trick.

However you have to make sure to close applications consuming a lot of %MEM (see the output of "top") before doing this. In my case free Mem, was less than used Swap and I got:

 # swapoff -a
swapoff: /dev/sda2: swapoff failed: Cannot allocate memory

After closing Firefox which was using 34% of MEM at that time, swapoff and swapon worked well and I got 0 used Swap.