4

I have a couple of CentOS 6.5 x64 servers with 64 GB RAM running lots of KVM VPS's.

Some of these servers have no swap usage at all and some do. I've set swappiness to zero. However, some still swap even if they have lots of free GBs in RAM.

The faulty* program is qemu-kvm - the VPS's are KVM virtual machines.

This is output from top ordered by swapping (Op enter):

top - 10:47:31 up 14 days,  1:25,  1 user,  load average: 0.05, 0.10, 0.13
Tasks: 325 total,   1 running, 324 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.4%sy,  0.0%ni, 99.5%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  65940252k total, 41202572k used, 24737680k free,  9129148k buffers
Swap:  5240808k total,  1039544k used,  4201264k free, 10935732k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP COMMAND
11653 qemu      20   0 1437m 725m 4968 S  0.0  1.1  24:23.56  51m qemu-kvm
 4873 qemu      20   0 1451m 743m 4968 S  0.0  1.2  22:32.94  50m qemu-kvm
14265 qemu      20   0 1443m 742m 4968 S  0.0  1.2  27:21.25  47m qemu-kvm
 5928 qemu      20   0 1445m 751m 4968 S  0.0  1.2  24:56.82  45m qemu-kvm
11294 qemu      20   0 1436m 718m 5004 S  0.0  1.1  23:35.45  45m qemu-kvm
10016 qemu      20   0 1438m 741m 4968 S  0.0  1.2  24:58.07  45m qemu-kvm
 8028 qemu      20   0 1445m 725m 4968 S  0.0  1.1  22:49.86  44m qemu-kvm
13449 qemu      20   0 1439m 738m 5008 S  0.3  1.1  25:49.07  43m qemu-kvm
 9065 qemu      20   0 1439m 738m 4968 S  0.0  1.1  22:35.70  41m qemu-kvm
 5173 qemu      20   0 1443m 748m 4968 S  0.3  1.2  24:57.27  41m qemu-kvm
 6833 qemu      20   0 1445m 735m 4968 S  0.3  1.1  24:43.94  40m qemu-kvm
12901 qemu      20   0 1447m 754m 4968 S  0.7  1.2  26:46.74  39m qemu-kvm
12508 qemu      20   0 1435m 737m 4968 S  0.0  1.1  24:07.60  37m qemu-kvm
 8197 qemu      20   0 1449m 752m 4968 S  0.0  1.2  23:15.54  37m qemu-kvm
 7394 qemu      20   0 1444m 745m 5008 S  0.3  1.2  22:20.29  36m qemu-kvm
 7783 qemu      20   0 1435m 739m 4996 S  0.0  1.1  24:02.63  36m qemu-kvm
14733 qemu      20   0 1448m 753m 5000 S  0.3  1.2  28:58.61  35m qemu-kvm
14323 qemu      20   0 1448m 750m 4968 S  0.0  1.2  26:02.34  35m qemu-kvm
 9381 qemu      20   0 1426m 728m 4968 S  0.0  1.1  23:27.13  35m qemu-kvm
 5472 qemu      20   0 1443m 743m 4968 S  0.3  1.2  22:14.22  35m qemu-kvm
13293 qemu      20   0 1428m 727m 4968 S  0.0  1.1  24:51.03  34m qemu-kvm
11697 qemu      20   0 1449m 756m 4968 S  0.0  1.2  24:46.59  33m qemu-kvm
 4566 qemu      20   0 1432m 747m 5008 S  0.0  1.2  23:28.19  30m qemu-kvm
 9752 qemu      20   0 1439m 743m 4968 S  0.3  1.2  22:56.10  30m qemu-kvm
 6533 qemu      20   0 1438m 747m 4968 S  0.0  1.2  22:38.61  30m qemu-kvm
 6234 qemu      20   0 1418m 724m 4968 S  0.3  1.1  23:14.90  28m qemu-kvm
    1 root      20   0 19232 1524 1232 S  0.0  0.0   0:02.86    0 init

Now as you can see qemu-kvm is swapping. The boxes run the latest OS updated. Also notice there's a lot of free RAM available there.

How can I prevent swapping completely? It annoys me a great lot and it's even more baffling considering I have more servers like this and some never swap. Ever.

5

vm.swappiness = 0 does not completely prevent swapping. To turn swap off altogether, you could issue the command swapoff -a with root privilege. However, disabling swap completely is generally unsafe -- when a memory-starvation extreme condition hits, the system will probably crash. Also, the swapoff action itself copies from swap (slow) to RAM, therefore it may just as well hit performance as actual swapping.

Despite the apparent "free" memory, the kernel tends to swap out long-inactive and memory -consuming processes. This frees up RAM for caches, thus improves responsiveness. Unless you have real proof of performance degradation, I'd suggest you stop worrying and love the kernel ;)

3
  • yes, well, considering the fact that some boxes came preinstalled with 1gb swap, when this swapp fills vps pids get killed. not funny at all. that's why i created additional swap as a file and added to existing swap. still want a perma no swap because it has 20GB ram buffer free. your solution has been considered but i dont know how -safe- it is to do swapoff in production. some things i never considered could crash. or worse. – Horatiu May 29 '14 at 12:53
  • 2
    As mentioned here ( percona.com/blog/2014/04/28/… ), in modern kernels, vm.swappiness = 0 has a new meaning; it will turn off swapping (in effect) – ϹοδεMεδιϲ Mar 23 '16 at 12:07
  • @ϹοδεMεδιϲ this had to be ammended somewhere, because even with latest kernel swappiness 0 will not prevent swapping – Petr Dec 17 '19 at 8:26

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.