[LTP] [PATCH 1/4] controllers/memcg: update stress test to work under cgroup2
Luke Nowakowski-Krijger
luke.nowakowskikrijger@canonical.com
Sat Nov 27 01:04:22 CET 2021
Update tests to be able to work when memory controller is mounted under
cgroup2 hierarchy.
Remove redundant mounts so that it mounts once for both tests to keep
the logic a bit simpler.
Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
.../memcg/stress/memcg_stress_test.sh | 73 ++++++++++++++-----
1 file changed, 56 insertions(+), 17 deletions(-)
diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
index c43d72116..ba7c8f386 100755
--- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
+++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
@@ -21,12 +21,62 @@ TST_TIMEOUT=2100
. cgroup_lib.sh
+setup_cgroupv2()
+{
+ mount_point=$(grep -w cgroup2 /proc/mounts | cut -f 2 | cut -d " " -f2)
+ if ! grep -q memory "$mount_point"/cgroup.controllers; then
+ tst_res TINFO "memory controller not supported on cgroup v2."
+ return
+ fi
+
+ task_list="cgroup.procs"
+ cgroup_v="v2"
+}
+
+setup_cgroupv1()
+{
+ exist=$(grep -w memory /proc/cgroups | cut -f1);
+ if [ "$exist" = "" ]; then
+ tst_brk TCONF NULL "memory controller not supported"
+ fi
+
+ mount_point=$(grep -w memory /proc/mounts | cut -f 2 | cut -d " " -f2)
+ if [ "$mount_point" = "" ]; then
+ cgroup_mounted=0
+ mount_point="/dev/memcg"
+ fi
+
+ if [ "$cgroup_mounted" -eq "0" ]; then
+ ROD mkdir -p $mount_point
+ ROD mount -t cgroup -o memory none $mount_point
+ fi
+
+ task_list="tasks"
+ cgroup_v="v1"
+}
+
setup()
{
if ! is_cgroup_subsystem_available_and_enabled "memory"; then
tst_brk TCONF "Either kernel does not support Memory Resource Controller or feature not enabled"
fi
+ if tst_kvcmp -lt "2.6.30"; then
+ tst_brk TBROK "Test should be run with kernel 2.6.30 or newer"
+ fi
+
+ cgroup_mounted=1
+
+ if grep -q cgroup2 /proc/mounts; then
+ setup_cgroupv2
+ fi
+
+ if [ -z "$cgroup_v" ]; then
+ setup_cgroupv1
+ fi
+
+ tst_res TINFO "test starts with cgroup $cgroup_v"
+
echo 3 > /proc/sys/vm/drop_caches
sleep 2
local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'`
@@ -43,20 +93,12 @@ setup()
cleanup()
{
- if [ -e /dev/memcg ]; then
- EXPECT_PASS umount /dev/memcg
- EXPECT_PASS rmdir /dev/memcg
+ if [ $cgroup_mounted -eq "0" ]; then
+ EXPECT_PASS umount $mount_point
+ EXPECT_PASS rmdir $mount_point
fi
}
-do_mount()
-{
- cleanup
-
- EXPECT_PASS mkdir /dev/memcg
- EXPECT_PASS mount -t cgroup -omemory memcg /dev/memcg
-}
-
# $1 Number of cgroups
# $2 Allocated MB memory in one process
# $3 The interval to touch memory in a process
@@ -71,13 +113,11 @@ run_stress()
tst_res TINFO "Testing $cgroups cgroups, using $mem_size MB, interval $interval"
- do_mount
-
tst_res TINFO "Starting cgroups"
for i in $(seq 0 $(($cgroups-1))); do
- mkdir /dev/memcg/$i 2> /dev/null
+ mkdir "$mount_point/$i" 2> /dev/null
memcg_process_stress $mem_size $interval &
- echo $! > /dev/memcg/$i/tasks
+ echo $! > "$mount_point/$i/$task_list"
pids="$pids $!"
done
@@ -93,12 +133,11 @@ run_stress()
for pid in $pids; do
kill -KILL $pid 2> /dev/null
wait $pid 2> /dev/null
- rmdir /dev/memcg/$i 2> /dev/null
+ rmdir "$mount_point/$i" 2> /dev/null
i=$((i+1))
done
tst_res TPASS "Test passed"
- cleanup
}
test1()
--
2.32.0
More information about the ltp
mailing list