LXC container memory configuration

otbutz

Active Member
Oct 17, 2017
13
3
43
33
Could somebody elaborate on how to configure the LXC memory settings properly?

The UI allows me to set the memory limit of my container to e.g 1024MB and 0MB for swap. According to the documentation this would be wrong:

swap:
Allows the container to use additional swap memory from the host swap space. This corresponds to the memory.memsw.limit_in_bytes cgroup setting, which is set to the sum of both value (memory + swap).
Is the UI missing a sanity check or am i misinterpreting the documentation?
 
If the "swap" parameter is actually memory+swap this example would make no sense to me:

Memory: 1024MB
Swap: 0MB

How can memory+swap be set to 0MB if the memory is set to 1024MB?
 
This comes from the fact that the kernel does the accounting slightly differently. At a higher level it seems easier to just say I want 1G of memory and 1G of swap, but really to the kernel we're saying 1G of memory, and 2G of both together. This means that it's possible to get into a situation where your container is in fact only using 500M of memory and 1.5G of swap, which is more swap space than you configured for the container, but it doesn't mean the container will be able to exceed the 1G of RAM (or the total of 2Gs). The container cannot actually cause this to happen by itself. In order for this to happen there needs to be memory pressure from the outside, iow. from the host or other containers (or both).
If memory & swap were strictly separated then 1G of memory + 0 swap would effectively lock the container's used memory into physical RAM, which is usually not helpful, and if you add overprovisioning to this then it would become much easier to have the OOM-killer go on a rampage.
 
Hello,
If I understand correctly, minimum swap memory is always the same size as physical memory in LXC. And all memory is physical memory+swap memory.
Regards,
 

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!