Enable memory cgroup on a Raspberry Pi with DietPi an extremely lightweight Debian operating system.
As described inside issue cpuset disabled #1950 the memory cgroup is disabled due to memory overhead, so you need to be aware of this drawback.
In case of LXD (system container and virtual machine manager) the benefits of memory resource controller are far greater than the slightly increased memory usage.
$ sudo -i lxc info flying-lab
Name: flying-lab Status: RUNNING Type: container Architecture: armv7l PID: 1383 Created: 2021/11/13 12:05 CET Last Used: 2021/11/13 15:02 CET Resources: Processes: 9 CPU usage: CPU usage (in seconds): 5 Network usage: eth0: Type: broadcast State: UP Host interface: vethe15caef1 MAC address: 00:16:3e:42:3c:f7 MTU: 1500 Bytes received: 80.34kB Bytes sent: 2.73kB Packets received: 403 Packets sent: 24 IP addresses: inet: 10.114.53.238/28 (global) inet6: fe80::216:3eff:fe42:3cf7/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)
Inspect kernel boot parameters.
$ cat /boot/cmdline.txt
root=PARTUUID=8b0ac6f5-02 rootfstype=ext4 rootwait fsck.repair=yes net.ifnames=0 logo.nologo quiet console=tty1
Append cgroup_enable=memory
parameter to enable memory accounting.
$ sudo sed -i -e "1 s/$/ cgroup_enable=memory/" /boot/cmdline.txt
$ cat /boot/cmdline.txt
root=PARTUUID=8b0ac6f5-02 rootfstype=ext4 rootwait fsck.repair=yes net.ifnames=0 logo.nologo quiet console=tty1 cgroup_enable=memory
Reboot operating system.
$ sudo reboot
Verify that memory accounting is enabled.
$ sudo -i lxc info flying-lab
Name: flying-lab Status: RUNNING Type: container Architecture: armv7l PID: 1438 Created: 2021/11/13 12:05 CET Last Used: 2021/11/13 15:58 CET Resources: Processes: 9 CPU usage: CPU usage (in seconds): 6 Memory usage: Memory (current): 29.45MiB Network usage: 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) eth0: Type: broadcast State: UP Host interface: vethf125c08a MAC address: 00:16:3e:42:3c:f7 MTU: 1500 Bytes received: 26.05kB Bytes sent: 1.60kB Packets received: 186 Packets sent: 14 IP addresses: inet: 10.114.53.238/28 (global) inet6: fe80::216:3eff:fe42:3cf7/64 (link)
Additional notes
You can inspect dmesg output to determine current status of the memory control group subsystem.
Memory control group subsystem enabled at boot.
[ 0.000000] cgroup: Enabling memory control group subsystem
Memory control group subsystem disabled at boot.
[ 0.000936] cgroup: Disabling memory control group subsystem