Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Mark Brown and committed by
Andrew Morton
85968b6a 7bd1fa0d

+42 -24
+42 -24
tools/testing/selftests/mm/run_vmtests.sh
··· 187 187 printf "Not enough huge pages available (%d < %d)\n" \ 188 188 "$freepgs" "$needpgs" 189 189 fi 190 + HAVE_HUGEPAGES=1 190 191 else 191 192 echo "no hugetlbfs support in kernel?" 192 - exit 1 193 + HAVE_HUGEPAGES=0 193 194 fi 194 195 195 196 # filter 64bit architectures ··· 219 218 # Usage: run_test [test binary] [arbitrary test arguments...] 220 219 run_test() { 221 220 if test_selected ${CATEGORY}; then 221 + local skip=0 222 + 222 223 # On memory constrainted systems some tests can fail to allocate hugepages. 223 224 # perform some cleanup before the test for a higher success rate. 224 225 if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then 225 - echo 3 > /proc/sys/vm/drop_caches 226 - sleep 2 227 - echo 1 > /proc/sys/vm/compact_memory 228 - sleep 2 226 + if [ "${HAVE_HUGEPAGES}" = "1" ]; then 227 + echo 3 > /proc/sys/vm/drop_caches 228 + sleep 2 229 + echo 1 > /proc/sys/vm/compact_memory 230 + sleep 2 231 + else 232 + echo "hugepages not supported" | tap_prefix 233 + skip=1 234 + fi 229 235 fi 230 236 231 237 local test=$(pretty_name "$*") ··· 240 232 local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -) 241 233 printf "%s\n%s\n%s\n" "$sep" "$title" "$sep" | tap_prefix 242 234 243 - ("$@" 2>&1) | tap_prefix 244 - local ret=${PIPESTATUS[0]} 235 + if [ "${skip}" != "1" ]; then 236 + ("$@" 2>&1) | tap_prefix 237 + local ret=${PIPESTATUS[0]} 238 + else 239 + local ret=$ksft_skip 240 + fi 245 241 count_total=$(( count_total + 1 )) 246 242 if [ $ret -eq 0 ]; then 247 243 count_pass=$(( count_pass + 1 )) ··· 283 271 CATEGORY="hugetlb" run_test ./hugetlb-madvise 284 272 CATEGORY="hugetlb" run_test ./hugetlb_dio 285 273 286 - nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages) 287 - # For this test, we need one and just one huge page 288 - echo 1 > /proc/sys/vm/nr_hugepages 289 - CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv 290 - CATEGORY="hugetlb" run_test ./hugetlb_madv_vs_map 291 - # Restore the previous number of huge pages, since further tests rely on it 292 - echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages 274 + if [ "${HAVE_HUGEPAGES}" = "1" ]; then 275 + nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages) 276 + # For this test, we need one and just one huge page 277 + echo 1 > /proc/sys/vm/nr_hugepages 278 + CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv 279 + CATEGORY="hugetlb" run_test ./hugetlb_madv_vs_map 280 + # Restore the previous number of huge pages, since further tests rely on it 281 + echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages 282 + fi 293 283 294 284 if test_selected "hugetlb"; then 295 285 echo "NOTE: These hugetlb tests provide minimal coverage. Use" | tap_prefix ··· 407 393 fi 408 394 409 395 # KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100 410 - CATEGORY="ksm" run_test ./ksm_tests -H -s 100 396 + if [ "${HAVE_HUGEPAGES}" = "1" ]; then 397 + CATEGORY="ksm" run_test ./ksm_tests -H -s 100 398 + fi 411 399 # KSM KSM_MERGE_TIME test with size of 100 412 400 CATEGORY="ksm" run_test ./ksm_tests -P -s 100 413 401 # KSM MADV_MERGEABLE test with 10 identical pages ··· 458 442 459 443 # Try to create XFS if not provided 460 444 if [ -z "${SPLIT_HUGE_PAGE_TEST_XFS_PATH}" ]; then 461 - if test_selected "thp"; then 462 - if grep xfs /proc/filesystems &>/dev/null; then 463 - XFS_IMG=$(mktemp /tmp/xfs_img_XXXXXX) 464 - SPLIT_HUGE_PAGE_TEST_XFS_PATH=$(mktemp -d /tmp/xfs_dir_XXXXXX) 465 - truncate -s 314572800 ${XFS_IMG} 466 - mkfs.xfs -q ${XFS_IMG} 467 - mount -o loop ${XFS_IMG} ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} 468 - MOUNTED_XFS=1 469 - fi 445 + if [ "${HAVE_HUGEPAGES}" = "1" ]; then 446 + if test_selected "thp"; then 447 + if grep xfs /proc/filesystems &>/dev/null; then 448 + XFS_IMG=$(mktemp /tmp/xfs_img_XXXXXX) 449 + SPLIT_HUGE_PAGE_TEST_XFS_PATH=$(mktemp -d /tmp/xfs_dir_XXXXXX) 450 + truncate -s 314572800 ${XFS_IMG} 451 + mkfs.xfs -q ${XFS_IMG} 452 + mount -o loop ${XFS_IMG} ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} 453 + MOUNTED_XFS=1 454 + fi 455 + fi 470 456 fi 471 457 fi 472 458