Skip to content

Commit 776dd24

Browse files
committed
selftests/mm: fix hugepages cleanup too early
JIRA: https://issues.redhat.com/browse/RHEL-130531 Conflicts: - Missing tests: migration, mkdirty, mdwe, page_frag and rmap. Missing of the rmap line makes the last chunk of the patch failed to apply, manually fixed it. commit 6e296bc Author: Chunyu Hu <chuhu@redhat.com> Date: Fri Sep 12 09:37:09 2025 +0800 selftests/mm: fix hugepages cleanup too early Patch series "Fix va_high_addr_switch.sh test failure", v3. These three patches fix the va_high_addr_switch.sh test failure on x86_64. Patch 1 fixes the hugepage setup issue that nr_hugepages is reset too early in run_vmtests.sh and break the later va_high_addr_switch testing. Patch 2 adds hugepage setup in va_high_addr_switch test, so that it can still work if vm_runtests.sh changes the hugepage setup someday. Patch 3 fixes the test failure caused by the hint addr align method change in hugetlb_get_unmapped_area(). This patch (of 3): The nr_hugepgs variable is used to keep the original nr_hugepages at the hugepage setup step at test beginning. After userfaultfd test, a cleaup is executed, both /sys/kernel/mm/hugepages/hugepages-*/nr_hugepages and /proc/sys//vm/nr_hugepages are reset to 'original' value before userfaultfd test starts. Issue here is the value used to restore /proc/sys/vm/nr_hugepages is nr_hugepgs which is the initial value before the vm_runtests.sh runs, not the value before userfaultfd test starts. 'va_high_addr_swith.sh' tests runs after that will possibly see no hugepages available for test, and got EINVAL when mmap(HUGETLB), making the result invalid. And before pkey tests, nr_hugepgs is changed to be used as a temp variable to save nr_hugepages before pkey test, and restore it after pkey tests finish. The original nr_hugepages value is not tracked anymore, so no way to restore it after all tests finish. Add a new variable orig_nr_hugepgs to save the original nr_hugepages, and and restore it to nr_hugepages after all tests finish. And change to use the nr_hugepgs variable to save the /proc/sys/vm/nr_hugeages after hugepage setup, it's also the value before userfaultfd test starts, and the correct value to be restored after userfaultfd finishes. The va_high_addr_switch.sh broken will be resolved. Link: https://lkml.kernel.org/r/20250912013711.3002969-1-chuhu@redhat.com Link: https://lkml.kernel.org/r/20250912013711.3002969-2-chuhu@redhat.com Signed-off-by: Chunyu Hu <chuhu@redhat.com> Acked-by: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
1 parent 526e5a6 commit 776dd24

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/testing/selftests/mm/run_vmtests.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ fi
160160

161161
# set proper nr_hugepages
162162
if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
163-
nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
163+
orig_nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
164164
needpgs=$((needmem_KB / hpgsize_KB))
165165
tries=2
166166
while [ "$tries" -gt 0 ] && [ "$freepgs" -lt "$needpgs" ]; do
167167
lackpgs=$((needpgs - freepgs))
168168
echo 3 > /proc/sys/vm/drop_caches
169-
if ! echo $((lackpgs + nr_hugepgs)) > /proc/sys/vm/nr_hugepages; then
169+
if ! echo $((lackpgs + orig_nr_hugepgs)) > /proc/sys/vm/nr_hugepages; then
170170
echo "Please run this test as root"
171171
exit $ksft_skip
172172
fi
@@ -177,6 +177,7 @@ if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
177177
done < /proc/meminfo
178178
tries=$((tries - 1))
179179
done
180+
nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages)
180181
if [ "$freepgs" -lt "$needpgs" ]; then
181182
printf "Not enough huge pages available (%d < %d)\n" \
182183
"$freepgs" "$needpgs"
@@ -435,6 +436,10 @@ CATEGORY="migration" run_test ./migration
435436

436437
CATEGORY="mkdirty" run_test ./mkdirty
437438

439+
if [ "${HAVE_HUGEPAGES}" = 1 ]; then
440+
echo "$orig_nr_hugepgs" > /proc/sys/vm/nr_hugepages
441+
fi
442+
438443
echo "SUMMARY: PASS=${count_pass} SKIP=${count_skip} FAIL=${count_fail}" | tap_prefix
439444
echo "1..${count_total}" | tap_output
440445

0 commit comments

Comments
 (0)