Swapoff will make faster my linux box ?

Yes and no …

The swap partition is an extended memory. Newest kernels are reserving the entire ram at start so when an application needs more ram, swap partition is here for us. But what if our swap partition is full ? That cannot be done cause there is a percent that kernel is using for the swap partition. This kernel value is described here:

cat /proc/sys/vm/swappiness

In most linux systems the default value is 60 percent.
In virtual machines we should reduce this percent to something small cause of IO limitations.
In our desktops we can increase it, to even higher values.

But what if we need more ram, more swap ?
What if our applications are running all together and the swap partition is in its limits ?

Then just … swapoff !!!

With swapoff the system will drop the swap partition!
But how this is more helpful ?

It isnt !

swapoff frees up unused memory and we can change the value of swappiness to something higher, lets say:

sudo sysctl -w vm.swappiness=80

And then swapon the swap partition again …

If we need to make a permanent change for the swappiness, we need to make it to /etc/sysctl.conf

  1. Avatar di Salih Emin Salih Emin

    Tuesday, October 12, 2010 - 12:29:18

    Very informative article ! May I ask you a question ?
    What is the general recommendation for the existence of a swap file ? Do we need it when we have 4GB of RAM ?

    Once I had to install a system without a swapfile (info here: http://bit.ly/a3hGb6) and never had a problem. So what happens when RAM is big ? Like >4GB ?

  2. Avatar di ebal ebal

    Tuesday, October 12, 2010 - 14:06:43

    It really depends on your needs. If you are using hibernation then it would be safe to have the exactly same amount as your RAM. Some linux distros (or other OS) have the ability to dump all the RAM into swap when a system is crashing. As i’ve mentioned already, nowadays the kernel reserve the entire RAM at boot and handles memory resource a lot better. For desktops with a lot of RAM, but no services there isnt any need of swap partition. Honestly i prefer to create a large swap partition (double as my RAM) for the below reasons: a. Hard Disk are cheap and i can afford it, b. i run a lot of heavy services, c. i use hibernation and d. i use firefox and thunderbird. And that means that i need all the memory i can find !