Containers use swap from host. Normally the SwapTotal in /proc/meminfo inside the container is the same as that on the host. However, since the latest snap lxd upgrade (version 4.2, 15564) all containers on some hosts show a SwapTotal of 0.
Hmm. On none of the boxes swapaccount=1 has been set. Note that Iâm not trying to limit swap for containers.
This box (A) the containers have the same swap report as the host:
uname -r
4.15.0-50-generic
grep CONFIG_MEMCG_SWAP /boot/config-*
/boot/config-4.15.0-101-generic:CONFIG_MEMCG_SWAP=y
/boot/config-4.15.0-101-generic:# CONFIG_MEMCG_SWAP_ENABLED is not set
/boot/config-4.15.0-50-generic:CONFIG_MEMCG_SWAP=y
/boot/config-4.15.0-50-generic:# CONFIG_MEMCG_SWAP_ENABLED is not set
/boot/config-4.15.0-99-generic:CONFIG_MEMCG_SWAP=y
/boot/config-4.15.0-99-generic:# CONFIG_MEMCG_SWAP_ENABLED is not set
grep -r GRUB_CMDLINE_LINUX /etc/default/grub*
/etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"
/etc/default/grub:GRUB_CMDLINE_LINUX=""
/etc/default/grub.d/50-cloudimg-settings.cfg:GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"
/etc/default/grub.d/50-cloudimg-settings.cfg:GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 modprobe.blacklist=btrfs"
On a similar host (B), the containers report:
grep ^Swap /proc/meminfo
SwapCached: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
uname -r
4.15.0-99-generic
grep CONFIG_MEMCG_SWAP /boot/config-*
/boot/config-4.15.0-101-generic:CONFIG_MEMCG_SWAP=y
/boot/config-4.15.0-101-generic:# CONFIG_MEMCG_SWAP_ENABLED is not set
/boot/config-4.15.0-66-generic:CONFIG_MEMCG_SWAP=y
/boot/config-4.15.0-66-generic:# CONFIG_MEMCG_SWAP_ENABLED is not set
/boot/config-4.15.0-99-generic:CONFIG_MEMCG_SWAP=y
/boot/config-4.15.0-99-generic:# CONFIG_MEMCG_SWAP_ENABLED is not set
grep -r GRUB_CMDLINE_LINUX /etc/default/grub*
/etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"
/etc/default/grub:GRUB_CMDLINE_LINUX=""
/etc/default/grub.d/50-cloudimg-settings.cfg:GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0"
/etc/default/grub.d/50-cloudimg-settings.cfg:GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 modprobe.blacklist=btrfs"
@brauner more SWAP fun. I also noticed here that systems with swapaccount disabled do not see any swap rather than see the host amount, that feels like a bug.
@brauner more SWAP fun. I also noticed here that systems with swapaccount disabled do not see any swap rather than see the host amount, that feels like a bug.
Iâm this close to rm mm/swap* in the kernel sources.
Do you have any memory limits set on your containers? I had the same problem after the snap updated and found the swap was visible in containers with memory limits as below
Indeed. Iâve still not enabled swap accounting on the system (I donât really need swap accounting). For testing Iâve enabled swap accounting on one box and these limits you suggested do help to show SwapTotal and SwapFree (no container restart needed).
Can we get this fix in 4.0/stable? The workaround suggested by @kbos works. But I have containers, that should use all available memory. So setting limits.memory is not an option for me.
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