My system was getting slower, especially when I use browsers like Firefox / Chromium and Virtual Machines. I noticed that I've got at least 3.2 GB of free RAM (using Gnome system monitor) and there was no swapping.
What I did now is swapoff -a
and system system performance is up by 30%. So my question is: Is it safe to use swapoff
? Will it be safe for my PC to restart with swapoff
?
The Linux kernel provides a tweakable setting that controls how often the swap file is used, called swappiness
A swappiness setting of zero means that the disk will be avoided unless absolutely necessary (you run out of memory), while a swappiness setting of 100 means that programs will be swapped to disk almost instantly.
Ubuntu system comes with a default of 60, meaning that the swap file will be used fairly often if the memory usage is around half of my RAM. You can check your own system's swappiness value by running:
As I have 4 GB of RAM, so I'd like to turn that down to 10 or 15. The swap file will then only be used when my RAM usage is around 80 or 90 percent. To change the system swappiness value, open
/etc/sysctl.conf as root
. Then, change or add this line to the file:Reboot for the change to take effect
You can also change the value while your system is still running
you can also clear your swap by running
swapoff -a
and thenswapon -a
as root instead of rebooting to achieve the same effect.To calculate your swap Formula
so what it mean is that when 10 % 395 MB of ram left then it start using swapiness
Probably. You should read the 'Why Do I Need Swap' part of the Ubuntu FAQ page here, and judge for yourself.
If you value speed over the safety net swap can provide, you should disable it
If you never suspend to disk and always shut down and restart you can disable it safely.
If you have lots of RAM (your 4GB + VMs running is a close call) then you can.
For me, I have my OS on a SSD, 8GB RAM and never suspend. I don't need swap, have never seen it in use, and I just set it up at install out of habit.
As an alternative, here is an about:config tweak for Firefox from Lifehacker that explains how to use RAM only for the browser cache. Read the rebuttal linked at the bottom of the article before you try it.
No it is not safe. The reason is that when the system runs out of RAM and will be unable to swap any of it, it might freeze with no chance for recovery other than a hard reset. It's not just about being able to suspend or not.
Source: my 14.04 does that.
You should keep a minimum amount of swap space, look at the Ubuntu FAQ for numbers.