Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/cgroup: on cgroup1 systems, the swap limit is set to limits.memory * 2 #272

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions tests/cgroup
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,20 @@ 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
# XXX: using awk to get only the value to avoid problems with formatting including varying amount of spaces before the kB value
# shellcheck disable=SC2016
[ "$(lxc exec c1 -- awk '/^SwapTotal/ { print $2 }' /proc/meminfo)" = "${SWAP_LIMIT_KIB}" ]
Fixed Show fixed Hide fixed

# 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
Loading