-1

we have rhel servers with version 7.6

we configured the swap and we can see the swap size from the following

 free -g
              total        used        free      shared  buff/cache   available
Mem:             38          32           0           0           4           4
Swap:            23           0          23

we also configured the vm.swappiness as the following

 sysctl -a | grep swap
vm.swappiness = 95

from my understanding , when available memory comes to few GIGA free memory as 1-5G

then swap should be triggered , and we expect to have for example 5-10G swap total memory

but this inst happens

so what we should also check on my server?

maybe some other configuration that disabled the swap ?

update when doing free

free -g
              total        used        free      shared  buff/cache   available
Mem:             11           8           0           0           2           2
Swap:            23           0          23
# free
              total        used        free      shared  buff/cache   available
Mem:       11828240     8810264      161388       24696     2856588     2555472
Swap:      24575992        5120    24570872
yael
  • 13,106

1 Answers1

4

When vm.swappiness is set to 100, the page cache and swap are considered equally when handling memory pressure. Values less than 100 tell the kernel to consider swap to be more expensive than the page cache; thus when it needs to free pages, it will try to free pages from the page cache rather than use swap. The lower the value, the greater the cost of swap. (The calculation is more complex than my explanation here, but this should be close enough to understand what’s going on here.)

In your case, you’ve configured swap to be slightly more expensive than the page cache. All your page cache usage is reclaimable (within the rounding errors): your “available” value is equal to your “buff/cache” value. As a result, any memory pressure results in the page cache being reclaimed, rather than swap being used.

There’s nothing wrong with your server, it’s behaving as intended. You’ll see swap usage go up over the long term. If you want to see it used more, set vm.swappiness to 100.

See also Why does swappiness not work?

Stephen Kitt
  • 434,908
  • so let me understand , so the solution is to set vm.swappiness=100 , what about little less as vm.swappiness=99 ? – yael Oct 17 '20 at 19:34
  • Why do you want the system to use swap? – Stephen Kitt Oct 17 '20 at 20:05
  • we have vm labs that are limited to use ram memory , for now we not have resource to add additional datastore resource , since we are using the vm for installation ci-cd , then we are thinking to add swap memory in case machine is nearly 0 available memory – yael Oct 17 '20 at 20:08
  • for shot - we not have money to buy resources , so the reason is to use swap – yael Oct 17 '20 at 20:14
  • I’m asking why you want your system to have non-zero swap use. What’s actually wrong with the output you show from free? Why do you want to force your servers to swap out? – Stephen Kitt Oct 17 '20 at 20:56
  • in some cases the available memory from free -g get nearly 0 , so in that case we not have other alternative , what we can do , so this is the reason that I want to use swap , in fact installation is failed in case of nearly 0 available memory – yael Oct 17 '20 at 21:07
  • What does free without -g show in such cases? – Stephen Kitt Oct 17 '20 at 21:22
  • You’d probably get a more useful answer if you described you actual problem and asked what to do about it. – Stephen Kitt Oct 17 '20 at 21:23
  • I never tested the free without "-g" , but on the coming cluster I will verify this – yael Oct 17 '20 at 21:23
  • see now the update in my question with free only – yael Oct 17 '20 at 21:37
  • That shows that you still have plenty of available memory and that swap is being used (a very small amount, but non-zero). – Stephen Kitt Oct 17 '20 at 21:51