Skip to content

Commit 526e5a6

Browse files
committed
selftests/mm: allow tests to run with no huge pages support
JIRA: https://issues.redhat.com/browse/RHEL-130531 Conflicts: - Missing commit 3a103b5 ("selftest: mm: Test if hugepage does not get leaked during bio_release_pages()"), so lack the hugetlb_dio line, manually applied. - Missing commit fc4d182 ("mm: huge_memory: enable debugfs to split huge pages to any order"), so removed the 'split_huge_page_test' chunk. commit 85968b6 Author: Mark Brown <broonie@kernel.org> Date: Wed Feb 12 17:44:26 2025 +0000 selftests/mm: allow tests to run with no huge pages support Currently the mm selftests refuse to run if huge pages are not available in the current system but this is an optional feature and not all the tests actually require them. Change the test during startup to be non-fatal and skip or omit tests which actually rely on having huge pages, allowing the other tests to be run. The gup_test does support using madvise() to configure huge pages but it ignores the error code so we just let it run. Link: https://lkml.kernel.org/r/20250212-kselftest-mm-no-hugepages-v1-2-44702f538522@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org> Reviewed-by: Nico Pache <npache@redhat.com> Cc: Mariano Pache <npache@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
1 parent 09fe1bd commit 526e5a6

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

tools/testing/selftests/mm/run_vmtests.sh

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
181181
printf "Not enough huge pages available (%d < %d)\n" \
182182
"$freepgs" "$needpgs"
183183
fi
184+
HAVE_HUGEPAGES=1
184185
else
185186
echo "no hugetlbfs support in kernel?"
186-
exit 1
187+
HAVE_HUGEPAGES=0
187188
fi
188189

189190
# filter 64bit architectures
@@ -212,22 +213,33 @@ pretty_name() {
212213
# Usage: run_test [test binary] [arbitrary test arguments...]
213214
run_test() {
214215
if test_selected ${CATEGORY}; then
216+
local skip=0
217+
215218
# On memory constrainted systems some tests can fail to allocate hugepages.
216219
# perform some cleanup before the test for a higher success rate.
217220
if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then
218-
echo 3 > /proc/sys/vm/drop_caches
219-
sleep 2
220-
echo 1 > /proc/sys/vm/compact_memory
221-
sleep 2
221+
if [ "${HAVE_HUGEPAGES}" = "1" ]; then
222+
echo 3 > /proc/sys/vm/drop_caches
223+
sleep 2
224+
echo 1 > /proc/sys/vm/compact_memory
225+
sleep 2
226+
else
227+
echo "hugepages not supported" | tap_prefix
228+
skip=1
229+
fi
222230
fi
223231

224232
local test=$(pretty_name "$*")
225233
local title="running $*"
226234
local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -)
227235
printf "%s\n%s\n%s\n" "$sep" "$title" "$sep" | tap_prefix
228236

229-
("$@" 2>&1) | tap_prefix
230-
local ret=${PIPESTATUS[0]}
237+
if [ "${skip}" != "1" ]; then
238+
("$@" 2>&1) | tap_prefix
239+
local ret=${PIPESTATUS[0]}
240+
else
241+
local ret=$ksft_skip
242+
fi
231243
count_total=$(( count_total + 1 ))
232244
if [ $ret -eq 0 ]; then
233245
count_pass=$(( count_pass + 1 ))
@@ -264,13 +276,15 @@ CATEGORY="hugetlb" run_test ./hugepage-mremap
264276
CATEGORY="hugetlb" run_test ./hugepage-vmemmap
265277
CATEGORY="hugetlb" run_test ./hugetlb-madvise
266278

267-
nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages)
268-
# For this test, we need one and just one huge page
269-
echo 1 > /proc/sys/vm/nr_hugepages
270-
CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv
271-
CATEGORY="hugetlb" run_test ./hugetlb_madv_vs_map
272-
# Restore the previous number of huge pages, since further tests rely on it
273-
echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages
279+
if [ "${HAVE_HUGEPAGES}" = "1" ]; then
280+
nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages)
281+
# For this test, we need one and just one huge page
282+
echo 1 > /proc/sys/vm/nr_hugepages
283+
CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv
284+
CATEGORY="hugetlb" run_test ./hugetlb_madv_vs_map
285+
# Restore the previous number of huge pages, since further tests rely on it
286+
echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages
287+
fi
274288

275289
if test_selected "hugetlb"; then
276290
echo "NOTE: These hugetlb tests provide minimal coverage. Use" | tap_prefix
@@ -370,7 +384,9 @@ CATEGORY="madv_populate" run_test ./madv_populate
370384
CATEGORY="memfd_secret" run_test ./memfd_secret
371385

372386
# KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100
373-
CATEGORY="ksm" run_test ./ksm_tests -H -s 100
387+
if [ "${HAVE_HUGEPAGES}" = "1" ]; then
388+
CATEGORY="ksm" run_test ./ksm_tests -H -s 100
389+
fi
374390
# KSM KSM_MERGE_TIME test with size of 100
375391
CATEGORY="ksm" run_test ./ksm_tests -P -s 100
376392
# KSM MADV_MERGEABLE test with 10 identical pages

0 commit comments

Comments
 (0)