Skip to content

Commit ab66eaa

Browse files
committed
Merge: selftests/mm: resolve hugetlb_reparenting_test test fail on rhel-9.7
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6966 JIRA: https://issues.redhat.com/browse/RHEL-86180 Tested: by me, using RHEL-9.7. This is a clean backport to resolve hugetlb_reparenting_test.sh test fails on rhel9: ``` commit 585a914 selftests/mm: restore default nr_hugepages value during cleanup in hugetlb_reparenting_test.sh commit e487a5d selftest/mm: make hugetlb_reparenting_test tolerant to async reparenting commit 9c02223 selftests/mm: generate a temporary mountpoint for cgroup filesystem ``` Signed-off-by: Li Wang <liwang@redhat.com> Approved-by: Waiman Long <longman@redhat.com> Approved-by: Herton R. Krzesinski <herton@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 353f16a + c71d956 commit ab66eaa

File tree

2 files changed

+45
-59
lines changed

2 files changed

+45
-59
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: 43 additions & 57 deletions
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
@@ -36,7 +36,7 @@ else
3636
do_umount=1
3737
fi
3838
fi
39-
MNT='/mnt/huge/'
39+
MNT='/mnt/huge'
4040

4141
function get_machine_hugepage_size() {
4242
hpz=$(grep -i hugepagesize /proc/meminfo)
@@ -56,10 +56,45 @@ function cleanup() {
5656
rmdir "$CGROUP_ROOT"/a/b 2>/dev/null
5757
rmdir "$CGROUP_ROOT"/a 2>/dev/null
5858
rmdir "$CGROUP_ROOT"/test1 2>/dev/null
59-
echo 0 >/proc/sys/vm/nr_hugepages
59+
echo $nr_hugepgs >/proc/sys/vm/nr_hugepages
6060
set -e
6161
}
6262

63+
function assert_with_retry() {
64+
local actual_path="$1"
65+
local expected="$2"
66+
local tolerance=$((7 * 1024 * 1024))
67+
local timeout=20
68+
local interval=1
69+
local start_time
70+
local now
71+
local elapsed
72+
local actual
73+
74+
start_time=$(date +%s)
75+
76+
while true; do
77+
actual="$(cat "$actual_path")"
78+
79+
if [[ $actual -ge $(($expected - $tolerance)) ]] &&
80+
[[ $actual -le $(($expected + $tolerance)) ]]; then
81+
return 0
82+
fi
83+
84+
now=$(date +%s)
85+
elapsed=$((now - start_time))
86+
87+
if [[ $elapsed -ge $timeout ]]; then
88+
echo "actual = $((${actual%% *} / 1024 / 1024)) MB"
89+
echo "expected = $((${expected%% *} / 1024 / 1024)) MB"
90+
cleanup
91+
exit 1
92+
fi
93+
94+
sleep $interval
95+
done
96+
}
97+
6398
function assert_state() {
6499
local expected_a="$1"
65100
local expected_a_hugetlb="$2"
@@ -70,58 +105,13 @@ function assert_state() {
70105
expected_b="$3"
71106
expected_b_hugetlb="$4"
72107
fi
73-
local tolerance=$((5 * 1024 * 1024))
74-
75-
local actual_a
76-
actual_a="$(cat "$CGROUP_ROOT"/a/memory.$usage_file)"
77-
if [[ $actual_a -lt $(($expected_a - $tolerance)) ]] ||
78-
[[ $actual_a -gt $(($expected_a + $tolerance)) ]]; then
79-
echo actual a = $((${actual_a%% *} / 1024 / 1024)) MB
80-
echo expected a = $((${expected_a%% *} / 1024 / 1024)) MB
81-
echo fail
82-
83-
cleanup
84-
exit 1
85-
fi
86108

87-
local actual_a_hugetlb
88-
actual_a_hugetlb="$(cat "$CGROUP_ROOT"/a/hugetlb.${MB}MB.$usage_file)"
89-
if [[ $actual_a_hugetlb -lt $(($expected_a_hugetlb - $tolerance)) ]] ||
90-
[[ $actual_a_hugetlb -gt $(($expected_a_hugetlb + $tolerance)) ]]; then
91-
echo actual a hugetlb = $((${actual_a_hugetlb%% *} / 1024 / 1024)) MB
92-
echo expected a hugetlb = $((${expected_a_hugetlb%% *} / 1024 / 1024)) MB
93-
echo fail
109+
assert_with_retry "$CGROUP_ROOT/a/memory.$usage_file" "$expected_a"
110+
assert_with_retry "$CGROUP_ROOT/a/hugetlb.${MB}MB.$usage_file" "$expected_a_hugetlb"
94111

95-
cleanup
96-
exit 1
97-
fi
98-
99-
if [[ -z "$expected_b" || -z "$expected_b_hugetlb" ]]; then
100-
return
101-
fi
102-
103-
local actual_b
104-
actual_b="$(cat "$CGROUP_ROOT"/a/b/memory.$usage_file)"
105-
if [[ $actual_b -lt $(($expected_b - $tolerance)) ]] ||
106-
[[ $actual_b -gt $(($expected_b + $tolerance)) ]]; then
107-
echo actual b = $((${actual_b%% *} / 1024 / 1024)) MB
108-
echo expected b = $((${expected_b%% *} / 1024 / 1024)) MB
109-
echo fail
110-
111-
cleanup
112-
exit 1
113-
fi
114-
115-
local actual_b_hugetlb
116-
actual_b_hugetlb="$(cat "$CGROUP_ROOT"/a/b/hugetlb.${MB}MB.$usage_file)"
117-
if [[ $actual_b_hugetlb -lt $(($expected_b_hugetlb - $tolerance)) ]] ||
118-
[[ $actual_b_hugetlb -gt $(($expected_b_hugetlb + $tolerance)) ]]; then
119-
echo actual b hugetlb = $((${actual_b_hugetlb%% *} / 1024 / 1024)) MB
120-
echo expected b hugetlb = $((${expected_b_hugetlb%% *} / 1024 / 1024)) MB
121-
echo fail
122-
123-
cleanup
124-
exit 1
112+
if [[ -n "$expected_b" && -n "$expected_b_hugetlb" ]]; then
113+
assert_with_retry "$CGROUP_ROOT/a/b/memory.$usage_file" "$expected_b"
114+
assert_with_retry "$CGROUP_ROOT/a/b/hugetlb.${MB}MB.$usage_file" "$expected_b_hugetlb"
125115
fi
126116
}
127117

@@ -174,7 +164,6 @@ size=$((${MB} * 1024 * 1024 * 25)) # 50MB = 25 * 2MB hugepages.
174164

175165
cleanup
176166

177-
echo
178167
echo
179168
echo Test charge, rmdir, uncharge
180169
setup
@@ -195,7 +184,6 @@ cleanup
195184

196185
echo done
197186
echo
198-
echo
199187
if [[ ! $cgroup2 ]]; then
200188
echo "Test parent and child hugetlb usage"
201189
setup
@@ -212,7 +200,6 @@ if [[ ! $cgroup2 ]]; then
212200
assert_state 0 $(($size * 2)) 0 $size
213201

214202
rmdir "$CGROUP_ROOT"/a/b
215-
sleep 5
216203
echo Assert memory reparent correctly.
217204
assert_state 0 $(($size * 2))
218205

@@ -224,7 +211,6 @@ if [[ ! $cgroup2 ]]; then
224211
cleanup
225212
fi
226213

227-
echo
228214
echo
229215
echo "Test child only hugetlb usage"
230216
echo setup

0 commit comments

Comments
 (0)