lxc / lxcfs

FUSE filesystem for LXC
https://linuxcontainers.org/lxcfs
Other
1.04k stars 249 forks source link

No way to gain swap inside container #551

Closed rosbeef closed 2 years ago

rosbeef commented 2 years ago

Required information

Issue description

no swap inside my container

/snap/bin/lxc exec yunh1 -- free -m
              total        used        free      shared  buff/cache   available
Mem:           1990          13        1969           7           7        1977
Swap:             0           0           0

Steps to reproduce

create container the free -hin the container show no swap available

Information to attach

Resources: Processes: 6 CPU usage: CPU usage (in seconds): 16 Memory usage: Memory (current): 19.95MiB Network usage: eth0: Type: broadcast State: UP Host interface: enx00xxx6b6 MAC address: 00:xxx:2e MTU: 1500 Bytes received: 3.45kB Bytes sent: 2.31kB Packets received: 24 Packets sent: 23 IP addresses: inet: 192.168.0.153/24 (global) inet6: 2a01:xxx:7b2e/64 (global) inet6: fe80:xxx:7b2e/64 (link) lo: Type: loopback State: UP MTU: 65536 Bytes received: 0B Bytes sent: 0B Packets received: 0 Packets sent: 0 IP addresses: inet: 127.0.0.1/8 (local) inet6: ::1/128 (local)

Log:

lxc yunh1 20220815212056.933 WARN conf - ../src/src/lxc/conf.c:lxc_map_ids:3592 - newuidmap binary is missing lxc yunh1 20220815212056.934 WARN conf - ../src/src/lxc/conf.c:lxc_map_ids:3598 - newgidmap binary is missing lxc yunh1 20220815212056.936 WARN conf - ../src/src/lxc/conf.c:lxc_map_ids:3592 - newuidmap binary is missing lxc yunh1 20220815212056.937 WARN conf - ../src/src/lxc/conf.c:lxc_map_ids:3598 - newgidmap binary is missing lxc yunh1 20220815212104.254 WARN conf - ../src/src/lxc/conf.c:lxc_map_ids:3592 - newuidmap binary is missing lxc yunh1 20220815212104.255 WARN conf - ../src/src/lxc/conf.c:lxc_map_ids:3598 - newgidmap binary is missing


 - [x] Container configuration (`lxc config show NAME --expanded`)

/snap/bin/lxc config show yunh1 --expanded architecture: armv7l config: image.architecture: armhf image.description: Debian buster armhf (20220815_05:25) image.os: Debian image.release: buster image.serial: "20220815_05:25" image.type: squashfs image.variant: default limits.memory.swap: "true" security.syscalls.intercept.sysinfo: "true" volatile.base_image: 888106799c2e7b4a3ed66b5a0a5e32e53a65bdadabaf25e03adf80f71fabb1a2 volatile.cloud-init.instance-id: 89bafb63-157e-4f67-b6b5-b1c188f3048a volatile.eth0.host_name: mace6df26bd volatile.eth0.hwaddr: 00:1xxx:2e volatile.eth0.last_state.created: "false" volatile.eth0.name: eth0 volatile.idmap.base: "0" volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]' volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]' volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]' volatile.last_state.power: RUNNING volatile.uuid: d1606124-a0ca-4479-9e6f-2491e9a5d497 devices: eth0: nictype: macvlan parent: enx001e063686b6 type: nic root: path: / pool: default type: disk ephemeral: false profiles:

stgraber commented 2 years ago

Bouncing to lxcfs as it's not an actual LXD issue. I also seem to recall that it's a deliberate behavior of LXCFS as there's no better way to report this currently.

Basically, LXD sets up the swap under cgroup1 and cgroup2 to be 0 bytes. That doesn't actually mean no swap, it means no ADDITIONAL memory can be taken from swap. The total container allocation itself as set through memory limits can come from either swap or from main memory.

stgraber commented 2 years ago

We tried some approaches to report that in the past, but it's very tricky. Basically we know how much memory is used from swap and we know the total amount of memory the instance can use (ram+swap). But there is no fixed bucket of ram and fixed bucket of swap, which makes it impossible to report through the normal files.

In past LXCFS versions, we'd lie and always report the host swap as the swap and then report the container usage against that. But that had two issues:

As a result, in such situations, LXCFS will simply not report the swap at all. You'll typically only find accurate swap reporting when no memory limit is applied to the container as in that case we can safely expose the host values and have everything line up nicely.

stgraber commented 2 years ago

https://github.com/lxc/lxcfs#swap-handling has some more details

rosbeef commented 2 years ago

nice to view your complete a clear answer. i can close this