Skip to content

Commit f750092

Browse files
committed
selftests/mm: alloc hugepages in va_high_addr_switch test
JIRA: https://issues.redhat.com/browse/RHEL-130531 commit d9d957b Author: Chunyu Hu <chuhu@redhat.com> Date: Fri Sep 12 09:37:10 2025 +0800 selftests/mm: alloc hugepages in va_high_addr_switch test Alloc hugepages in the test internally, so we don't fully rely on the run_vmtests.sh. If run_vmtests.sh does that great, free hugepages is enough for being used to run the test, leave it as it is, otherwise setup the hugepages in the test. Save the original nr_hugepages value and restore it after test finish, so leave a stable test envronment. Link: https://lkml.kernel.org/r/20250912013711.3002969-3-chuhu@redhat.com Signed-off-by: Chunyu Hu <chuhu@redhat.com> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
1 parent 62c42f2 commit f750092

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tools/testing/selftests/mm/va_high_addr_switch.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Kselftest framework requirement - SKIP code is 4.
1111
ksft_skip=4
12+
orig_nr_hugepages=0
1213

1314
skip()
1415
{
@@ -76,5 +77,41 @@ check_test_requirements()
7677
esac
7778
}
7879

80+
save_nr_hugepages()
81+
{
82+
orig_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
83+
}
84+
85+
restore_nr_hugepages()
86+
{
87+
echo "$orig_nr_hugepages" > /proc/sys/vm/nr_hugepages
88+
}
89+
90+
setup_nr_hugepages()
91+
{
92+
local needpgs=$1
93+
while read -r name size unit; do
94+
if [ "$name" = "HugePages_Free:" ]; then
95+
freepgs="$size"
96+
break
97+
fi
98+
done < /proc/meminfo
99+
if [ "$freepgs" -ge "$needpgs" ]; then
100+
return
101+
fi
102+
local hpgs=$((orig_nr_hugepages + needpgs))
103+
echo $hpgs > /proc/sys/vm/nr_hugepages
104+
105+
local nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
106+
if [ "$nr_hugepgs" != "$hpgs" ]; then
107+
restore_nr_hugepages
108+
skip "$0: no enough hugepages for testing"
109+
fi
110+
}
111+
79112
check_test_requirements
113+
save_nr_hugepages
114+
# 4 keep_mapped pages, and one for tmp usage
115+
setup_nr_hugepages 5
80116
./va_high_addr_switch --run-hugetlb
117+
restore_nr_hugepages

0 commit comments

Comments
 (0)