[LTP] [PATCH v6 07/10] controllers: update memcg/functional to use newer cgroup lib
Luke Nowakowski-Krijger
luke.nowakowskikrijger@canonical.com
Wed Jul 27 00:13:23 CEST 2022
Update memcg_lib.sh to uses the newer cgroup lib to cleanup the mounting
and checking of the memory controller.
There are still some tests that make sense for v2 and should be modified
in a future patch, but since most of the tests are testing specific v1
memory controller features lets just skip it for now if v2 is mounted.
Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
v2->v6: Fixed spelling mistakes reported by checkpatch
.../memcg/functional/memcg_force_empty.sh | 2 +-
.../controllers/memcg/functional/memcg_lib.sh | 54 ++++++++++---------
2 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
index 23a4bd04d..580468784 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
@@ -50,7 +50,7 @@ test6()
{
# writing to non-empty top mem cgroup's force_empty
# should return failure
- EXPECT_FAIL echo 1 \> /dev/memcg/memory.force_empty
+ EXPECT_FAIL echo 1 \> "$mount_point/memory.force_empty"
}
. memcg_lib.sh
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
index 96d26ef2d..a89e24485 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -16,20 +16,20 @@ TST_TESTFUNC=memcg_testfunc
memcg_require_memsw()
{
- if ! [ -e /dev/memcg/memory.limit_in_bytes ]; then
- tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_memsw"
+ if ! [ -e "$mount_point/memory.limit_in_bytes" ]; then
+ tst_brk TBROK "$mount_point must be mounted before calling memcg_require_memsw"
fi
- if ! [ -e /dev/memcg/memory.memsw.limit_in_bytes ]; then
+ if ! [ -e "$mount_point/memory.memsw.limit_in_bytes" ]; then
tst_brk TCONF "mem+swap is not enabled"
fi
}
memcg_require_hierarchy_disabled()
{
- if [ ! -e "/dev/memcg/memory.use_hierarchy" ]; then
- tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_hierarchy_disabled"
+ if [ ! -e "$mount_point/memory.use_hierarchy" ]; then
+ tst_brk TBROK "$mount_point must be mounted before calling memcg_require_hierarchy_disabled"
fi
- if [ $(cat /dev/memcg/memory.use_hierarchy) -eq 1 ]; then
+ if [ "$(cat "$mount_point/memory.use_hierarchy")" -eq 1 ]; then
tst_brk TCONF "Test requires root cgroup memory.use_hierarchy=0"
fi
}
@@ -71,12 +71,19 @@ memcg_adjust_limit_for_kmem()
memcg_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"
+ cgroup_require "memory"
+ cgroup_version=$(cgroup_get_version "memory")
+
+ # Most of the tests here are testing specific parts of the cgroup v1 memory interface that is
+ # not present for cgroup2, so if it is already mounted on a cgroup v2 hierarchy we should skip
+ # the test.
+ # Some tests still make sense in v2 and should be modified in a future patch
+ if [ "$cgroup_version" = "2" ]; then
+ tst_brk TCONF "memory controller mounted on cgroup v2 hierarchy, skipping test."
fi
- ROD mkdir /dev/memcg
- ROD mount -t cgroup -omemory memcg /dev/memcg
+ mount_point=$(cgroup_get_mountpoint "memory")
+ test_dir=$(cgroup_get_test_path "memory")
# For kernels older than v5.11 the default value for
# memory.use_hierarchy is 0 and some of tests (memcg_stat_test.sh and
@@ -89,15 +96,15 @@ memcg_setup()
# Starting with kernel v5.11, the non-hierarchical mode is not
# available. See Linux kernel commit bef8620cd8e0 ("mm: memcg:
# deprecate the non-hierarchical mode").
- orig_memory_use_hierarchy=$(cat /dev/memcg/memory.use_hierarchy)
+ orig_memory_use_hierarchy=$(cat "$mount_point/memory.use_hierarchy")
if [ -z "$orig_memory_use_hierarchy" ];then
- tst_res TINFO "cat /dev/memcg/ failed"
+ tst_res TINFO "cat $mount_point failed"
elif [ "$orig_memory_use_hierarchy" = "0" ];then
orig_memory_use_hierarchy=""
else
- echo 0 > /dev/memcg/memory.use_hierarchy 2>/dev/null
+ echo 0 > "$mount_point/memory.use_hierarchy" 2>/dev/null
if [ $? -ne 0 ];then
- tst_res TINFO "set /dev/memcg/memory.use_hierarchy to 0 failed"
+ tst_res TINFO "set $mount_point/memory.use_hierarchy to 0 failed"
fi
fi
@@ -110,22 +117,19 @@ memcg_cleanup()
cd $TST_TMPDIR
# In order to remove all subgroups, we have to remove them recursively
- if [ -e /dev/memcg/ltp_$$ ]; then
- ROD find /dev/memcg/ltp_$$ -depth -type d -delete
+ if [ -e $test_dir ]; then
+ ROD find $test_dir -depth -type d -delete
fi
if [ -n "$orig_memory_use_hierarchy" ];then
- echo $orig_memory_use_hierarchy > /dev/memcg/memory.use_hierarchy
+ echo $orig_memory_use_hierarchy > $mount_point/memory.use_hierarchy
if [ $? -ne 0 ];then
- tst_res TINFO "restore /dev/memcg/memory.use_hierarchy failed"
+ tst_res TINFO "restore $mount_point/memory.use_hierarchy failed"
fi
orig_memory_use_hierarchy=""
fi
- if [ -e "/dev/memcg" ]; then
- umount /dev/memcg
- rmdir /dev/memcg
- fi
+ cgroup_cleanup
[ "$MEMCG_SHMMAX" = "1" ] && shmmax_cleanup
}
@@ -369,8 +373,8 @@ test_limit_in_bytes()
memcg_testfunc()
{
- ROD mkdir /dev/memcg/ltp_$$
- cd /dev/memcg/ltp_$$
+ ROD mkdir $test_dir/ltp_$$
+ cd $test_dir/ltp_$$
if type ${MEMCG_TESTFUNC}1 > /dev/null 2>&1; then
${MEMCG_TESTFUNC}$1 $1 "$2"
@@ -379,7 +383,7 @@ memcg_testfunc()
fi
cd $TST_TMPDIR
- ROD rmdir /dev/memcg/ltp_$$
+ ROD rmdir $test_dir/ltp_$$
}
memcg_no_testfunc()
--
2.34.1
More information about the ltp
mailing list