Skip to content

Commit 209376e

Browse files
Waiman-Longtorvalds
authored andcommitted
selftests/vm: make charge_reserved_hugetlb.sh work with existing cgroup setting
The hugetlb cgroup reservation test charge_reserved_hugetlb.sh assume that no cgroup filesystems are mounted before running the test. That is not true in many cases. As a result, the test fails to run. Fix that by querying the current cgroup mount setting and using the existing cgroup setup instead before attempting to freshly mount a cgroup filesystem. Similar change is also made for hugetlb_reparenting_test.sh as well, though it still has problem if cgroup v2 isn't used. The patched test scripts were run on a centos 8 based system to verify that they ran properly. Link: https://lkml.kernel.org/r/[email protected] Fixes: 29750f7 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests") Signed-off-by: Waiman Long <[email protected]> Acked-by: Mina Almasry <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Mike Kravetz <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e9ea874 commit 209376e

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

tools/testing/selftests/vm/charge_reserved_hugetlb.sh

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,23 @@ if [[ "$1" == "-cgroup-v2" ]]; then
2424
reservation_usage_file=rsvd.current
2525
fi
2626

27-
cgroup_path=/dev/cgroup/memory
28-
if [[ ! -e $cgroup_path ]]; then
29-
mkdir -p $cgroup_path
30-
if [[ $cgroup2 ]]; then
27+
if [[ $cgroup2 ]]; then
28+
cgroup_path=$(mount -t cgroup2 | head -1 | awk -e '{print $3}')
29+
if [[ -z "$cgroup_path" ]]; then
30+
cgroup_path=/dev/cgroup/memory
3131
mount -t cgroup2 none $cgroup_path
32-
else
32+
do_umount=1
33+
fi
34+
echo "+hugetlb" >$cgroup_path/cgroup.subtree_control
35+
else
36+
cgroup_path=$(mount -t cgroup | grep ",hugetlb" | awk -e '{print $3}')
37+
if [[ -z "$cgroup_path" ]]; then
38+
cgroup_path=/dev/cgroup/memory
3339
mount -t cgroup memory,hugetlb $cgroup_path
40+
do_umount=1
3441
fi
3542
fi
36-
37-
if [[ $cgroup2 ]]; then
38-
echo "+hugetlb" >/dev/cgroup/memory/cgroup.subtree_control
39-
fi
43+
export cgroup_path
4044

4145
function cleanup() {
4246
if [[ $cgroup2 ]]; then
@@ -108,7 +112,7 @@ function setup_cgroup() {
108112

109113
function wait_for_hugetlb_memory_to_get_depleted() {
110114
local cgroup="$1"
111-
local path="/dev/cgroup/memory/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
115+
local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
112116
# Wait for hugetlbfs memory to get depleted.
113117
while [ $(cat $path) != 0 ]; do
114118
echo Waiting for hugetlb memory to get depleted.
@@ -121,7 +125,7 @@ function wait_for_hugetlb_memory_to_get_reserved() {
121125
local cgroup="$1"
122126
local size="$2"
123127

124-
local path="/dev/cgroup/memory/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
128+
local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"
125129
# Wait for hugetlbfs memory to get written.
126130
while [ $(cat $path) != $size ]; do
127131
echo Waiting for hugetlb memory reservation to reach size $size.
@@ -134,7 +138,7 @@ function wait_for_hugetlb_memory_to_get_written() {
134138
local cgroup="$1"
135139
local size="$2"
136140

137-
local path="/dev/cgroup/memory/$cgroup/hugetlb.${MB}MB.$fault_usage_file"
141+
local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$fault_usage_file"
138142
# Wait for hugetlbfs memory to get written.
139143
while [ $(cat $path) != $size ]; do
140144
echo Waiting for hugetlb memory to reach size $size.
@@ -574,5 +578,7 @@ for populate in "" "-o"; do
574578
done # populate
575579
done # method
576580

577-
umount $cgroup_path
578-
rmdir $cgroup_path
581+
if [[ $do_umount ]]; then
582+
umount $cgroup_path
583+
rmdir $cgroup_path
584+
fi

tools/testing/selftests/vm/hugetlb_reparenting_test.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ if [[ "$1" == "-cgroup-v2" ]]; then
1818
usage_file=current
1919
fi
2020

21-
CGROUP_ROOT='/dev/cgroup/memory'
22-
MNT='/mnt/huge/'
2321

24-
if [[ ! -e $CGROUP_ROOT ]]; then
25-
mkdir -p $CGROUP_ROOT
26-
if [[ $cgroup2 ]]; then
22+
if [[ $cgroup2 ]]; then
23+
CGROUP_ROOT=$(mount -t cgroup2 | head -1 | awk -e '{print $3}')
24+
if [[ -z "$CGROUP_ROOT" ]]; then
25+
CGROUP_ROOT=/dev/cgroup/memory
2726
mount -t cgroup2 none $CGROUP_ROOT
28-
sleep 1
29-
echo "+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control
30-
else
27+
do_umount=1
28+
fi
29+
echo "+hugetlb +memory" >$CGROUP_ROOT/cgroup.subtree_control
30+
else
31+
CGROUP_ROOT=$(mount -t cgroup | grep ",hugetlb" | awk -e '{print $3}')
32+
if [[ -z "$CGROUP_ROOT" ]]; then
33+
CGROUP_ROOT=/dev/cgroup/memory
3134
mount -t cgroup memory,hugetlb $CGROUP_ROOT
35+
do_umount=1
3236
fi
3337
fi
38+
MNT='/mnt/huge/'
3439

3540
function get_machine_hugepage_size() {
3641
hpz=$(grep -i hugepagesize /proc/meminfo)

tools/testing/selftests/vm/write_hugetlb_memory.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ want_sleep=$8
1414
reserve=$9
1515

1616
echo "Putting task in cgroup '$cgroup'"
17-
echo $$ > /dev/cgroup/memory/"$cgroup"/cgroup.procs
17+
echo $$ > ${cgroup_path:-/dev/cgroup/memory}/"$cgroup"/cgroup.procs
1818

1919
echo "Method is $method"
2020

0 commit comments

Comments
 (0)