1

Recently I saw a box (actually, web server VM) that has exact 0 (zero) bytes unused in its swap, while available ram (which is not free, but the sum of free+buffers+cache) is at 60% of total VM ram. Never seen that before, so wondered if this is good config (for the box and applications).

The admin of the VM told me he treat that as perfectly normal and that’s his ordinary way of tuning boxes up.

His idea was that if box has a lot of cold ram pages the kernel will seap it out to free up “real” ram pages so it can used to cache data.

As for me, I used to know the swap if the last thing to use if we like to have fast box. So, I used to set swappiness to lower values (so kernel won’t like to swap pages out), but this person approach was it is good to swap out as much data as we have swap space, thus having more cache. And yes, he said, the kernel can cache swapped pages, too, so there is no good in keep swap free.

Please easy my mind on that: is the VM seap should be used at its best, and ram be freed this way so kernel disk cache can be used more effectively?

To be exact, there was at the moment: 1 Gb of swap space (used at 100%), VM has 32 Gb of ram, and available ram was of 13 Gb.

1

A small amount of swap (1GiB is small compared to 32GiB of RAM) used entirely is fine. What this means is exactly as the VM’s administrator described it: given the availability of RAM, anything that ends up in swap is unused, and it’s better to keep it there and use the corresponding physical memory for more pressing purposes — whether active workloads, or disk cache.

Excessive swap use is only worrying if the amount of swap is large, or if pages are being swapped because of memory pressure, and more importantly if the swap activity is important, i.e. if vmstat shows pages being swapped in and out all the time. That indicates that the system is thrashing, spending its time evicting pages only to have to swap them back in again; that happens when the amount of RAM is too small for the system’s workload.

The system I’m writing this on has slightly more swap, and is in a similar situation to your VM:

$ free -m
              total        used        free      shared  buff/cache   available
Mem:          32054       19405        1098        2365       11550        9827
Swap:          6410        6410           0

Interactive performance is fine though, and vmstat shows no swap activity.

3
  • That sounds reasonable, but what worries me is that swap is totally used. This way, no swap out possible (not a single byte in swap size limits left unused; no space = no write, right?), while swap in is possible, surely. But how can I set any random linux box this way (use maximum swap thus having ram free) without ruining kernel algorithms? Looks like there is no need to set swappiness to 100 for that, kernel itself should do that magic. In real life, I have never seen that huge swap percent usage.
    – Alexander
    Jun 11 at 21:13
  • @Alexander see What Is Swappiness on Linux? (and How to Change It) - it gives a pretty good overview of how swap (and swappiness and memory zones etc) work on linux. IMO if your swap is 100% full then either a) your swappiness value is wrong, or b) you need more swap space, or c) both of the above. "c" is most likely. 1GB swap seems low to me. BTW, even though the article mentions this, it's worth saying again: swapping is not a bad thing. swap thrashing is bad - it means you need more memory.
    – cas
    Jun 12 at 6:01
  • @Alexander having swap full isn’t a goal to seek, but it’s not something to worry about when it happens (as an isolated symptom). As far as swap is concerned, what matters is dynamic behaviour, not static measurements. If swap is full then yes, you can’t write more to it, but that’s not a problem unless your RAM is too small for your working set, and in that case you’ve got a problem regardless of how much swap you have. Jun 12 at 11:35

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.