Merge pull request #28064 from bluca/test_oomd_swap

TEST-55-OOMD: use 'stress' to create high pressure, ensure swap is set up correctly on Ubuntu CI
This commit is contained in:
Luca Boccassi
2023-06-26 19:39:07 +01:00
committed by GitHub
5 changed files with 22 additions and 51 deletions
+7 -6
View File
@@ -5,18 +5,19 @@ set -e
TEST_DESCRIPTION="systemd-oomd Memory Pressure Test"
IMAGE_NAME="oomd"
# Need to set up swap
TEST_NO_NSPAWN=1
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
test_append_files() {
# Create a swap device
# Create a swap file
(
mkswap "${LOOPDEV:?}p2"
image_install swapon swapoff
image_install mkswap swapon swapoff stress
cat >>"${initdir:?}/etc/fstab" <<EOF
UUID=$(blkid -o value -s UUID "${LOOPDEV}p2") none swap defaults 0 0
EOF
dd if=/dev/zero of="${initdir:?}/swapfile" bs=1M count=48
chmod 0600 "${initdir:?}/swapfile"
mkdir -p "${initdir:?}/etc/systemd/system/init.scope.d/"
cat >>"${initdir:?}/etc/systemd/system/init.scope.d/test-55-oomd.conf" <<EOF
-40
View File
@@ -1,40 +0,0 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# Don't use set -x here, since it generates a lot of output and slows
# the script down, causing unexpected test fails.
set -eu
set -o pipefail
PAGE_SIZE=$(getconf PAGE_SIZE)
BLOAT_ITERATION_TARGET=$((100 << 20)) # 100 MB
BLOAT_HOLDER=()
PID="$$"
function bloat {
local set_size mem_usage target_mem_size
set_size=$(cut -d " " -f2 "/proc/$PID/statm")
mem_usage=$((set_size * PAGE_SIZE))
target_mem_size=$((mem_usage + $1))
BLOAT_HOLDER=()
while [[ "$mem_usage" -lt "$target_mem_size" ]]; do
echo "target $target_mem_size"
echo "mem usage $mem_usage"
BLOAT_HOLDER+=("$(printf "=%0.s" {1..1000000})")
set_size=$(cut -d " " -f2 "/proc/$PID/statm")
mem_usage=$((set_size * PAGE_SIZE))
done
}
function run {
local arr=()
while :; do
bloat "$BLOAT_ITERATION_TARGET"
arr+=("${BLOAT_HOLDER[@]}")
sleep 1
done
}
run
+3 -3
View File
@@ -3,8 +3,8 @@
Description=Create a lot of memory pressure
[Service]
# A VERY small memory.high will cause the script (trying to use a lot of memory)
# A VERY small memory.high will cause the 'stress' (trying to use a lot of memory)
# to throttle and be put under heavy pressure.
MemoryHigh=5M
MemoryHigh=3M
Slice=testsuite-55-workload.slice
ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-55-slowgrowth.sh
ExecStart=stress --timeout 3m --vm 10 --vm-bytes 200M --vm-keep --vm-stride 1
+2 -2
View File
@@ -3,6 +3,6 @@
Description=Create some memory pressure
[Service]
MemoryHigh=6M
MemoryHigh=12M
Slice=testsuite-55-workload.slice
ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-55-slowgrowth.sh
ExecStart=stress --timeout 3m --vm 10 --vm-bytes 200M --vm-keep --vm-stride 1
+10
View File
@@ -24,6 +24,13 @@ fi
rm -rf /run/systemd/system/testsuite-55-testbloat.service.d
# Activate swap file if we are in a VM
if systemd-detect-virt --vm --quiet; then
mkswap /swapfile
swapon /swapfile
swapon --show
fi
# Configure oomd explicitly to avoid conflicts with distro dropins
mkdir -p /run/systemd/oomd.conf.d/
cat >/run/systemd/oomd.conf.d/99-oomd-test.conf <<EOF
@@ -89,6 +96,7 @@ while [[ $(date -u +%s) -le $timeout ]]; do
if ! systemctl status testsuite-55-testbloat.service; then
break
fi
oomctl
sleep 2
done
@@ -126,6 +134,7 @@ while [[ $(date -u +%s) -le $timeout ]]; do
if ! systemctl --machine "testuser@.host" --user status testsuite-55-testbloat.service; then
break
fi
oomctl
sleep 2
done
@@ -153,6 +162,7 @@ EOF
if ! systemctl status testsuite-55-testmunch.service; then
break
fi
oomctl
sleep 2
done