From 518a70b6e743d57eba71f7d5bf7d1979032dc5f8 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Tue, 20 Aug 2024 14:26:06 -0400 Subject: [PATCH] tests/cgroup: adapt expected swaptotal value based on LXD version Signed-off-by: Simon Deziel --- tests/cgroup | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/cgroup b/tests/cgroup index 538266340..a6b0fbdae 100755 --- a/tests/cgroup +++ b/tests/cgroup @@ -110,11 +110,18 @@ echo "==> Testing memory limits" 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" ] +SWAP_LIMIT_KIB="0" 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: $((MEM_LIMIT_MIB * 1024)) kB" ] -else - [ "$(lxc exec c1 -- grep ^SwapTotal /proc/meminfo)" = "SwapTotal: 0 kB" ] + # XXX: workaround for https://github.com/canonical/lxd/issues/13954 + # On cgroup1 systems, LXD 5.0 and later set the swap limit to twice the limits.memory. + SWAP_LIMIT_KIB="$((MEM_LIMIT_MIB * 1024 * 2))" + + # LXD 4.0 sets it to limits.memory + if echo "${LXD_SNAP_CHANNEL}" | grep -qE "^4\.0/"; then + SWAP_LIMIT_KIB="$((MEM_LIMIT_MIB * 1024))" + fi fi +[ "$(lxc exec c1 -- grep ^SwapTotal /proc/meminfo)" = "SwapTotal: ${SWAP_LIMIT_KIB} kB" ] # 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