сряда, 9 ноември 2011 г.

How to enable/disable/empty the swap

My Sabayon seems to have the habit of writing stuff into the swap and then forgetting about them. So I thought for a while, why not just empty the swap when it's full and I'm sure nothing is using it. Well, it turned out it's possible to do so. Thanks to this forum post, now I know how.
So, there are the commands:
which can be safely used to turn on and off the swap. Now, the source site suggests using ">$swapoff /dev/hdxx" but if you have only one swap partition (like I do) this is unnecessary.
All you need to do is (as sudo, of course):
>$swapoff -a
and after it finishes emptying your swap,
>$swapon -a
And it's done. You have a fresh swap file, which you can start trashing immediately.
Now, if you do that when a program is still writing to the swap, I don't know what will happen. Maybe something ugly, maybe not. I tested it when nothing was using the swap even though my ram was almost full, and I haven't noticed any problems for now.