From 197b5d3247a5c19fe096ccfdfb6fac0dabf30794 Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Thu, 21 Mar 2024 18:58:11 +0100 Subject: [PATCH] tests/cgroup: check cgroup.max/cgroup.high values https://github.com/canonical/lxd/pull/13192 Signed-off-by: Alexander Mikhalitsyn --- tests/cgroup | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/cgroup b/tests/cgroup index cca890fef..9d8638122 100755 --- a/tests/cgroup +++ b/tests/cgroup @@ -106,14 +106,21 @@ fi lxc config unset c1 limits.cpu.allowance echo "==> Testing memory limits" -lxc config set c1 limits.memory=512MiB -[ "$(lxc exec c1 -- grep ^MemTotal /proc/meminfo)" = "MemTotal: 524288 kB" ] +MEM_LIMIT_MIB=512 +lxc config set c1 limits.memory="${MEM_LIMIT_MIB}MiB" +[ "$(lxc exec c1 -- grep ^MemTotal /proc/meminfo)" = "MemTotal: $((MEM_LIMIT_MIB * 1024)) kB" ] if [ -e "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes" ] || [ -e "/sys/fs/cgroup/memory.swap.max" ]; then - [ "$(lxc exec c1 -- grep ^SwapTotal /proc/meminfo)" = "SwapTotal: 524288 kB" ] + [ "$(lxc exec c1 -- grep ^SwapTotal /proc/meminfo)" = "SwapTotal: $((MEM_LIMIT_MIB * 1024)) kB" ] else [ "$(lxc exec c1 -- grep ^SwapTotal /proc/meminfo)" = "SwapTotal: 0 kB" ] fi +# ensure that we don't set memory.high when limits.memory.enforce=hard (default value) +if [ -e "/sys/fs/cgroup/system.slice/memory.high" ]; then + [ "$(lxc exec c1 -- cat /sys/fs/cgroup/memory.max)" = $((MEM_LIMIT_MIB * 1024 * 1024)) ] + [ "$(lxc exec c1 -- cat /sys/fs/cgroup/memory.high)" = "max" ] +fi + if [ -e "/sys/fs/cgroup/memory" ]; then lxc config set c1 limits.memory.swap=false [ "$(lxc exec c1 -- cat /sys/fs/cgroup/memory/memory.swappiness)" = "0" ]