Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

enter image description here

share|improve this question
    
Are you sure that Ubuntu is using your swap before it fully uses the ram? What's the output with free -m? Usually, turning off swap won't make a difference as Ubuntu tries to use the ram as much as possible, and it shouldn't happen that ram is unused and swap is used. –  Ubuntu_kwr Feb 11 '12 at 7:42
2  
Just fyi, I have no swap on my 8GB system with a single SSD. –  Lekensteyn Feb 11 '12 at 8:25
2  
You can either turn off swap, which should be fine, or adjust the swappiness value. It can be found at /proc/sys/vm/swappiness. Use 'sysctl' for a more permanent change. One thing to note is that hibernate needs swap. I think sleep doesn't really need it, but hibernate does. –  Marky Feb 11 '12 at 9:08
    
@kniwor ya i did , after 2.5 GB ram ...it uses swap & i have to restart then my system run ok . & some time after 1 GB my system got slow –  One Zero Feb 11 '12 at 10:27
    
@ i have checked this 5 to 6 times –  One Zero Feb 11 '12 at 10:30
show 1 more comment

2 Answers 2

up vote 53 down vote accepted

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:

one@onezero:~$ cat /proc/sys/vm/swappiness
60

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:

vm.swappiness = 10

Reboot for the change to take effect

You can also change the value while your system is still running

sysctl vm.swappiness=10

you can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect.

To calculate your swap Formula

free -m (total) / 100 = A

A * 10

root@onezero:/home/one# free -m
             total       used       free     shared    buffers     cached
Mem:          3950       2262       1687          0        407        952
-/+ buffers/cache:        903       3047
Swap:         1953          0       1953

so total is 3950 / 100 = 39.5 * 10 = 395

so what it mean is that when 10 % 395 MB of ram left then it start using swapiness

share|improve this answer
3  
+1 This is an excellent how-to on configuring swap. Great answer. You might even post a new question asking 'how do I configure swappiness' and copy this answer, so it's easier for others to find. People coming to this question are going to be looking for 'yes or no' answers, yours is a how-to for people that already chose 'yes' –  Tom Brossman Feb 13 '12 at 17:06
    
@TomBrossman thanks alot sir , ok –  One Zero Feb 13 '12 at 18:25
1  
@TomBrossman , i did you can check it askubuntu.com/questions/103915/how-do-i-configure-swappiness –  One Zero Feb 13 '12 at 18:35
2  
This, while being a useful guide, does not answer the question. The asker wanted to know whether it was safe or not, not how to do it. –  InkBlend Mar 19 '13 at 1:04
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.