swappiness to 0 doesn't seems to work

CharlesErickT

Member
Mar 15, 2017
52
8
8
32
Hello,

I've recently changed the swappiness on my host to 0 since there is plenty of ram available. Rebooted to apply the change.

Now my container still consume swap even when there is memory free.

Here's in the webui:

zsaj2Nf.jpg


Here's the free output inside the container:
Code:
              total        used        free      shared  buff/cache   available
Mem:           1024          33         583        4363         406         583
Swap:           256         190          65

Maybe I'm reading the output wrong but it seems to have enough ram to not swap ?

Here's my pveversion (Running 5.1 with ZFS)
Code:
pve-manager: 5.1-35 (running version: 5.1-35/722cc488)
pve-kernel-4.13.4-1-pve: 4.13.4-25
libpve-http-server-perl: 2.0-6
lvm2: 2.02.168-pve6
corosync: 2.4.2-pve3
libqb0: 1.0.1-1
pve-cluster: 5.0-15
qemu-server: 5.0-17
pve-firmware: 2.0-3
libpve-common-perl: 5.0-20
libpve-guest-common-perl: 2.0-13
libpve-access-control: 5.0-7
libpve-storage-perl: 5.0-16
pve-libspice-server1: 0.12.8-3
vncterm: 1.5-2
pve-docs: 5.1-12
pve-qemu-kvm: 2.9.1-2
pve-container: 2.0-17
pve-firewall: 3.0-3
pve-ha-manager: 2.0-3
ksm-control-daemon: 1.2-2
glusterfs-client: 3.8.8-1
lxc-pve: 2.1.0-2
lxcfs: 2.0.7-pve4
criu: 2.11.1-1~bpo90
novnc-pve: 0.6-4
smartmontools: 6.5+svn4324-1
zfsutils-linux: 0.7.2-pve1~bpo90

Right now we need to 'swapoff -a' and 'swapon -a ' every couples of day to fix the issue temporary

Any idea idea what could cause this ?
Thanks
 
You need to set swap to 0 on the container Resources/Memory configuration.

That make sense. Would the best practice when using ZFS be to keep swappiness on the host to 10 and disable it for the container or it doesn't matter and I could set it at 0 on the host while disabling it for the container ?
 
IMHO the best practice is to disable swap for both PVE-hosts and VMs/containers completely. For a few years one of the things I do on every PVE-host is "zfs destroy rpool/swap" (not just "swappiness 0"). Never had any problem. And when I'm talking about it, swap on ZFS is still not very stable solution. One more reason to get rid of it completely...
 
Please also consider to use zram, which creates a compressed swap image in your ram - yes sounds strange, but works perfectly!
 
  • Like
Reactions: e100
IMHO the best practice is to disable swap for both PVE-hosts and VMs/containers completely. For a few years one of the things I do on every PVE-host is "zfs destroy rpool/swap" (not just "swappiness 0"). Never had any problem. And when I'm talking about it, swap on ZFS is still not very stable solution. One more reason to get rid of it completely...
Yeah this is what I'll do because we have plenty of ram available and so far the swap only brought issues so disabling it seems like the logical solution. Thanks for your input
 
Yeah this is what I'll do because we have plenty of ram available and so far the swap only brought issues so disabling it seems like the logical solution.

Filled up swap is not the root cause of your problem - swap is only used if there is not enough ram available, so if you disable swap and you run out of ram, processes will be killed, so this is absolutely the wrong thing to do. Increase your ram to the machines and keep the swap setting. Monitor what your containers/vms do and react accordingly.
 
Filled up swap is not the root cause of your problem - swap is only used if there is not enough ram available, so if you disable swap and you run out of ram, processes will be killed, so this is absolutely the wrong thing to do. Increase your ram to the machines and keep the swap setting. Monitor what your containers/vms do and react accordingly.

Yes I'm aware of that but based on what I've posted originally it's like the container is swapping even if the swappinness is 0 and there is plenty of ram available. We have some monitoring software in place to monitor the ram so it should never be full and if it even gets high we can act accordingly.
 
Yes I'm aware of that but based on what I've posted originally it's like the container is swapping even if the swappinness is 0 and there is plenty of ram available. We have some monitoring software in place to monitor the ram so it should never be full and if it even gets high we can act accordingly.

Yes, should work and if something gets oom-killed, memory can be increased further. Sometimes, simple processes like locales generation can need a lot of temporary memory, so those bottlenecks really occur often for a very, very short amount of time. Same for downloading and parsing package update lists etc.

I only want to cover all bases so only a small followup question:
Are you sure that you monitor the container ram correctly? Depending on the guest operating system and monitoring software, there have been problems in the past with different versions, that were also discussed in forums.
 
Are you sure that you monitor the container ram correctly?

I'm using Nagios with a custom script that reads /proc/meminfo of the container. The Nagios report is consistent with what I'm seeing in the Proxmox webui.

Here's free -m from a container
Code:
              total        used        free      shared  buff/cache   available
Mem:           1024          39         922        4820          61         922
Swap:             0           0           0


And Nagios report:
Code:
OK - Total: 1024 MB - Free: 988 MB - 4% used : Swap: 0 MB - Free: 0 MB - 0% used

Which seems to work fine
 
Yes I'm aware of that but based on what I've posted originally it's like the container is swapping even if the swappinness is 0 and there is plenty of ram available. We have some monitoring software in place to monitor the ram so it should never be full and if it even gets high we can act accordingly.
I had the same issue... For the swappiness setting you need to reboot the host system.
So im using Swappiness 0 ;)
 
ok, i thought maybe the swappiness setting might got lost.. but this isnt the situation. Strangely for me it works ..
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!