Skip to content

Commit

Permalink
Merge pull request #107 from mihalicyn/cgroup2_limits_memory_test
Browse files Browse the repository at this point in the history
tests/cgroup: check cgroup.max/cgroup.high values
  • Loading branch information
tomponline authored Mar 22, 2024
2 parents 6879402 + 197b5d3 commit 21ae9cf
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 @@ -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" ]
Expand Down

0 comments on commit 21ae9cf

Please sign in to comment.