Skip to content

Commit

Permalink
tests/cgroup: adapt expected swaptotal value based on LXD version
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Aug 20, 2024
1 parent 4051094 commit 518a70b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/cgroup
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 518a70b

Please sign in to comment.