Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a KVM host running several virtual machines. The hardware is comprised of 24 cores w/ 40G of ram. This is the output of the free command:

                     total      used       free     shared  buffers  cached 
Mem:                 41180500   32340344   8840156       0  2126008  36480
-/+ buffers/cache:   30177856   11002644 
Swap:                3903484    3511516    391968

Why is the system swapping if it still has a lot of free RAM? Occupation has never been above 80% (nagios never reported more than that amount). And given that 20% of the RAM is 8G, it's still much more than the available swap (which is 4G).

share|improve this question

migrated from stackoverflow.com Jun 21 '13 at 11:57

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers

up vote 3 down vote accepted

Take a look at this article. It explains the problem, provides solution and some quick benchmarks. In short some settings that should improved the situation are:

vm.swappiness=20
vm.vfs_cache_pressure=50

Explanation of what they are and what they do can be found in the article.

share|improve this answer
add comment

You could try changing your "swappiness" value.

Here is a howto link: http://askubuntu.com/questions/103915/how-do-i-configure-swappiness/103916#103916

share|improve this answer
add comment

To stop the kernel swap memory you can change vm.swappiness to 0. This stops the kernel using virtual memory. You can also use the function mlock() to stop your application from being swapped.

share|improve this answer
add comment

On modern systems, swap will usually remain unused. Processes which are long-running are shifted to swap by the kernel. Some programs start working slowly because of that. You said you have ram free, so you could disable swap by running the command: swapoff -av (prefixed by sudo if you're not root)

If you don't like the swap off, you may enable it, using reverse command: swapon -av (again with sudo if necessary).

share|improve this answer
    
Changing swappiness as described in other answers is a much better approach, since it can handle out-of-memory problems when you DO manage to use more memory –  nealmcb Dec 28 '13 at 1:53
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.