3

I see sometimes Linux based servers using the swap when it is not necessary. Especially when all of the free ram is used for caching. But now my dedicated server with 16GB RAM begins to swap, although there is enough RAM free:

$ free -m

            total      used     free     shared    buffers     cached
Mem:        16029      10035    5994     0         421         8508
-/+ buffers/cache:     1104     14925
Swap:       19322      3        19319

The server is running a web-server, php and a database which never use all of the 16GB. There should be no need to swap. But Linux still does this. In this case only 3MB but it's the principle.

  • Is your question academic in nature, or are you experiencing a problem because of this? – MDMarra Feb 6 '14 at 0:17
  • What you've shown us says that it is using 3 bytes of swap, right? That's hardly anything. – Vasili Syrakis Feb 6 '14 at 0:21
  • It's 3MB not 3 Byte and it's only an example. I ask this because on servers with less RAM (eg 4GB) i saw a few times that they'll swap 256MB and more. In this case the problem is very clear because you see that nearly 6GB RAM are completely free, but Debian use 3MB from swap what is absolutely not necessary. – Lion Feb 6 '14 at 0:28
  • This varies quite a bit on the Kernel version being used and the vm.overcommit settings. – Matthew Ife Feb 6 '14 at 0:39
  • If it makes you feel better, that's 3MiB more RAM for I/O caching available to your system – BRPocock Feb 6 '14 at 6:35
8

If the kernel sees that a memory page hasn't been touched for a long time, it'll opportunistically swap it out, freeing that RAM for other applications or for cache.

Doing this makes better use of the RAM that you have, making your system perform better.

  • I thought the kernel is doing this by himself? And I've 6GB of RAM which is totally free. So it would be make much more sense to use some of these 6GB instead of the swap. But why the kernel isn't doing that? – Lion Feb 11 '14 at 0:15
  • Because you don't need that page in RAM. It's doing some opportunistic housecleaning to free up memory for other applications. – EEAA Feb 11 '14 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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