lxcfs
lxcfs copied to clipboard
Swap not working with cgroup2
When checking swap on container, reports 0.
swapaccount and cgroup_enable=memory are active on grub_cmdline
/boot/config... show that CONFIG_MEMECG_SWAP is enabled in the kernel
But here is the result when lauching lxcfs :
Running constructor lxcfs_init to reload liblxcfs
mount namespace: 5
hierarchies:
0: fd: 6: cpuset,cpu,io,memory,hugetlb,pids,rdma
Kernel supports pidfds
Kernel does not support swap accounting
api_extensions:
- cgroups
- sys_cpu_online
- proc_cpuinfo
- proc_diskstats
- proc_loadavg
- proc_meminfo
- proc_stat
- proc_swaps
- proc_uptime
- shared_pidns
- cpuview_daemon
- loadavg_daemon
- pidfds
It tells me that Kernel does not support swap accouting
Is that a problem on LXCFS ?
We check for memory.swap.max & memory.swap.current in the cgroup root directory, but those do not exist there.
Maybe we should just have a command line option to override this, as I'm not sure it makes sense to assume specific cgroup directories to exist.
Of course, we could just test some well known ones like systemd.slice (at least when -Dinit-script=systemd was used at build time?)
@brauner, any better ideas?
Same problem here.
I am using LXD to run the container. I can control the swap limit through echo $size > /sys/fs/cgroup/lxc.payload.test2/memory.swap.max, and read the swap usage through cat /sys/fs/cgroup/lxc.payload.test2/memory.swap.current, but the value of swap just doesn't show in the container.
I tried to read the source code (here) and I guess it may has some reason which cause the variable wants_swap is false, so it won't count the swap.
Well, I found a comment by @stgraber https://github.com/lxc/lxcfs/issues/551#issuecomment-1215990485, hope it helps.
I have a fresh install of Ubuntu 22.04.2 (Linux 5.19), and LXD 5.14.
My containers (Ubuntu 20.04.6 and 22.04.2) don't have SWAP (it shows zero 0 in free -m).
I tried many different values after reading about this issue here, on Reddit, on discuss of linuxcontainers, documents, etc, with no success.
Both CPU and Memory limits are working as expected (--config limits.cpu=1 --config limits.memory=192MiB, for example), only SWAP doesn't seem to be working.
It would be awesome to see LXD/LXC playing nice with cgroup2 and proper swap accounting!
The LXC Profile looks like this:
config:
limits.cpu: 0-7
limits.memory: 16GB
limits.memory.enforce: hard
limits.memory.swap: "false"
I also tried raw.lxc: lxc.cgroup.memory.memsw.limit_in_bytes = 64G. This seems invalid in Ubuntu 22.04.2, because it's v1, right?
Linux options: cgroup_enable=memory swapaccount=1.
Seems related: https://github.com/lxc/lxc/issues/4049
Any luck, folks?!