Skip to content

Commit 5211ce2

Browse files
brooniejfvogel
authored andcommitted
selftests/mm: generate a temporary mountpoint for cgroup filesystem
commit 9c02223e2d9df5cb37c51aedb78f3960294e09b5 upstream. Currently if the filesystem for the cgroups version it wants to use is not mounted charge_reserved_hugetlb.sh and hugetlb_reparenting_test.sh tests will attempt to mount it on the hard coded path /dev/cgroup/memory, deleting that directory when the test finishes. This will fail if there is not a preexisting directory at that path, and since the directory is deleted subsequent runs of the test will fail. Instead of relying on this hard coded directory name use mktemp to generate a temporary directory to use as a mountpoint, fixing both the assumption and the disruption caused by deleting a preexisting directory. This means that if the relevant cgroup filesystem is not already mounted then we rely on having coreutils (which provides mktemp) installed. I suspect that many current users are relying on having things automounted by default, and given that the script relies on bash it's probably not an unreasonable requirement. Link: https://lkml.kernel.org/r/20250404-kselftest-mm-cgroup2-detection-v1-1-3dba6d32ba8c@kernel.org Fixes: 209376e ("selftests/vm: make charge_reserved_hugetlb.sh work with existing cgroup setting") Signed-off-by: Mark Brown <[email protected]> Cc: Aishwarya TCV <[email protected]> Cc: Mark Brown <[email protected]> Cc: Mina Almasry <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Waiman Long <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 824b7ad9cf499e2782a6f995e7e366fe74d8b896) Signed-off-by: Jack Vogel <[email protected]>
1 parent 1acbeb7 commit 5211ce2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

tools/testing/selftests/mm/charge_reserved_hugetlb.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ fi
2929
if [[ $cgroup2 ]]; then
3030
cgroup_path=$(mount -t cgroup2 | head -1 | awk '{print $3}')
3131
if [[ -z "$cgroup_path" ]]; then
32-
cgroup_path=/dev/cgroup/memory
32+
cgroup_path=$(mktemp -d)
3333
mount -t cgroup2 none $cgroup_path
3434
do_umount=1
3535
fi
3636
echo "+hugetlb" >$cgroup_path/cgroup.subtree_control
3737
else
3838
cgroup_path=$(mount -t cgroup | grep ",hugetlb" | awk '{print $3}')
3939
if [[ -z "$cgroup_path" ]]; then
40-
cgroup_path=/dev/cgroup/memory
40+
cgroup_path=$(mktemp -d)
4141
mount -t cgroup memory,hugetlb $cgroup_path
4242
do_umount=1
4343
fi

tools/testing/selftests/mm/hugetlb_reparenting_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fi
2323
if [[ $cgroup2 ]]; then
2424
CGROUP_ROOT=$(mount -t cgroup2 | head -1 | awk '{print $3}')
2525
if [[ -z "$CGROUP_ROOT" ]]; then
26-
CGROUP_ROOT=/dev/cgroup/memory
26+
CGROUP_ROOT=$(mktemp -d)
2727
mount -t cgroup2 none $CGROUP_ROOT
2828
do_umount=1
2929
fi

0 commit comments

Comments
 (0)