No swap inside containers when using snap LXD

Hello:

Swap space on the host is ok:

manager@andromeda:~$ sudo swapon --show
NAME       TYPE      SIZE USED PRIO
/dev/zram0 partition   2G 256K    5
/dev/zram1 partition   2G 256K    5
/dev/zram2 partition   2G 256K    5
/dev/zram3 partition   2G   0B    5
/swapfile  file        2G   0B   -2
manager@andromeda:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G         11G        807M         53M        3.0G        3.5G
Swap:          9.8G        768K        9.8G

But there is no swap space available for containers:

manager@andromeda:~$ lxc exec sombrero -- free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        622M         14G        164K        102M         14G
Swap:            0B          0B          0B

manager@andromeda:~$ lxc exec backward -- free -h
              total        used        free      shared  buff/cache   available
Mem:            15G         53M         15G        236K         69M         15G
Swap:            0B          0B          0B
manager@andromeda:~$

I´m using Ubuntu 18.04. It only happens with snap version of LXD. With the default LXD installation (package) that comes with Ubuntu swap space inside containers works just fine.

Any pointers?

Thanks a lot!

This is a known issue.

Until it is fixed, the workaround would be:

1 - Enable swap accounting. Add boot argument swapaccount=1 to the GRUB_CMDLINE_LINUX_DEFAULT= variable in /etc/default/grub, then run ‘update-grub’ as root and reboot;

2 - Use lxc config set containername ...

  • limits.memory must be set to some value (percentage or fixed value)
  • limits.memory.enforce must be set to hard
  • limits.memory.swap must be set to false

More info here.

Does this workaround actually work?

After enabling “swapaccount=1” via GRUB file and setting the above mentioned parameters I can now see 10GB swap inside my container, but it is never used.

I tried filling a tmpfs inside the container as well as letting processes run out of memory.
In both cases the RAM fills up until it is completely full and processes are being killed by the kernels OOM killer, all while swap stays at 0 bytes used.

Does anybody else experience this issue or has found a solution?
Thank you

1 Like

On my end I also encountered Cypher’s issue. We the same configs recommended byDuli and saw OOM issued to a container process due to CGROUP out of memory even though plenty of swap was available. On lxd 4.6