Limiting swap in LXC container

Hello, I know how to limit swap in LXD using limits.memory.swap. My question is how to do the same in LXC.

If I understood correctly, memory for a container can be limited with lxc.cgroup.memory.limit_in_bytes and setting lxc.cgroup.memory.memsw.limit_in_bytes to the same value makes swap equal zero.

But what if just want to disable swap without a hard memory limit on the container?

Thanks!

Then what LXD does is configure the swapiness to a value that’s extremely high (or low, can’t remember which way that goes) so that the system will effectively never swap the container.

Aha, swappiness=0 would generally (although not completely) disable swap. It isn’t a hard limit, but if this is the way LXD does it then I’ll just put it in the LXC container’s sysctl.conf. Thank you.

Yeah, that’s what we do in LXD.

Indeed if completely running out of physical memory, the system will still use the swap, so it’s not a complete off switch, but it’s about as close as we can get.