LXC: set memory.swappiness for individual CTs

harvie

Well-Known Member
Apr 5, 2017
138
22
58
34
Hello,
according to cgroupv1 docs: https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt

It IS possible to set different swappiness value for each cgroup. How can i do this with proxmox CTs?
Also: Can you please add GUI for this?

This would greatly help me with swap issues caused by proxmox not using LXC4 (cgroupv2) yet and therefore not being able to limit swap per CT.
 
OK, so i've added following line to /etc/pve/lxc/XXX.conf file:
lxc.cgroup.memory.swappiness: 0

And it seems to be working. Hopefully the swap is now disabled for that CT...
 
Probably can even use following line in /etc/lxc/default.conf :
lxc.cgroup.memory.swappiness = 0

But i am not sure... This does not seem to be applied to proxmox CTs.
 
Last edited:
You can check the swappiness was applied to individual CT by following command:
cat /sys/fs/cgroup/memory/lxc/<CTID>/memory.swappiness

But i let it run over night and according to proxmox web ui, the CT has swapped 100MB, so i am not sure if something really changed...
 
According to some docs, the swappiness cannot completely prevent cgroup from swapping when whole system is deprived of ram.

But hey. it still might be interresting idea to set lower swappiness for mission critical containers, so they stay in the RAM during the peak hours, while the non-essential containers get swapped out and slow down.

Or maybe i can set system-wide swappiness to 0 and then reenable higher swappines in some containers. I am not sure if that's possible, but it might help to get system running, while some containers are being swapped out.

Another interresting cgroup setting might be memory.oom_control. Which decides whether OOM should kill the cgroup or not. When the OOM killer is disabled, tasks that attempt to use more memory than they are allowed are paused until additional memory is freed.
 
Last edited:

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!