Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm running Debian Squeeze 6.0.5. Does the use of swap memory make my computer run slower? If so, how can I reduce the size of the swap memory after the system is already installed?

share|improve this question
add comment

4 Answers

up vote 3 down vote accepted

You don't want to reduce it, but rather increase its lazy usage — the more clean pages are already in swap, the better, it means they can easily be set off RAM when free RAM is needed. Linux VM, though, have some weird behavior regarding swapping — intensive disk I/O (like huge file cp) can make your system swap heavily. It can be mitigated by decreasing vm.swappinness and increasing vfs_cache_pressure.

share|improve this answer
add comment

To turn off swap temporarily, use (as root) the command:

swapoff -a

To turn it back on again (if you find your system is actually slower):

swapon -a

To turn it off permanently, edit the file /etc/fstab and comment out any lines with swap in the type column.

More swap does not always improve performance. There are times when reducing it or turning it off is better - it all depends on the mix of applications.

I did a quick google and came up with this good article on the subject:

https://www.linux.com/news/software/applications/8208-all-about-linux-swap-space

share|improve this answer
add comment

Using it does, having it there does not. Slowing down will occur if you run too many memory hogging programs at once, which will cause the swap to be used.

If you really want to reduce it, boot a livecd and fire up gparted and resize the partition.

share|improve this answer
2  
Isn't swapoff sufficient? And then gparted from the running system. –  Marco Jun 14 '12 at 14:57
    
@Marco, presumably you would want to expand the root partition rather than just leave some unpartitioned space left from shrinking the swap partition, hence the need to boot a livecd. If you don't care about the unpartitioned space, then sure, you could run gparted from the hd and you'd just have to right click the swap partition and swapoff before you could shrink it. –  psusi Jun 14 '12 at 15:31
add comment

swap serves basically two purposes. It allows the system to continue to operate when physical memory runs out at a performance cost - run out of physical memory without it, you get crashes, lockups, and processes being killed with out of memory errors the second they ask for more memory than the system has. The reduced performance in this case is a symptom of being forced to use it for active processes, rather than a symptom of having too much swap.

It also lets physical memory be used more efficiently, by moving less-used pages in memory to disk until they are needed again. This frees up memory for cacheing purposes, which is usually a more efficient use of space than having infrequently used segments of program memory just sitting there locked in physical ram.

A long-standing best practice has been to size swap space at twice the physical memory, in other words, if you have 1GB of ram, devote 2GB to swap. This is still good advice, but in practice more modern systems with 4GB or more of physical ram can usually drop this to the same amount of swap as the system has of physical memory.

There are a few things you can do to improve performance when using swap. If you have multiple drives, moving swap to a faster or less used hard drive is recommended, and on a very IO-bound system, you may get significant performance increases by doing this. For traditional hard drives, moving swap closer to the center of the physical disk may help, as seek times are generally shorter at the center due to less travel of the drive heads.

Having swap on an SSD can help significantly as well, but I'd caution you that this may create a lot of wear and tear on a SSD, and will give it a shorter lifespan.

Of course, the best solution to improving memory performance is usually to throw more RAM into the box, and if you look at your memory usage and see heavy usage of swap along with little or no free memory, it's a good indication that it's time to invest in more ram.

share|improve this answer
    
With multiple disks, you can also put a swap area on each disk and assign them all equal priorities. The swapper then load balances between all swap areas for added speed. –  Alexios Jun 15 '12 at 11:25
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.