Hi all,
Powerpc systems with a 64K base page size exposed several issues while
running mm selftests. Some tests assume specific hugetlb configurations,
use incorrect interfaces, or fail instead of skipping when the required
kernel features are not available.
This series fixes these issues and improves test robustness.
Please review the patches and provide any feedback or suggestions for
improvement.
Thanks,
Sayali
---
v5->v6
- For "selftests/mm: restore default nr_hugepages value via exit trap
in charge_reserved_hugetlb.sh":
Extended trap to include INT and TERM in hugetlb tests to ensure
nr_hugepages is restored on signal-based exits.
- For "selftests/mm: restore default nr_hugepages value via exit trap
in hugetlb_reparenting_test.sh":
Extended trap to include INT and TERM in hugetlb tests to ensure
nr_hugepages is restored on signal-based exits.
- For "selftests/mm: fix cgroup task placement and drop memory.current
checks in hugetlb_reparenting_test.sh":
Updated the subshell invocation to pass variables as positional arguments
instead of interpolating them into the command string as per review comment.
- For "selftests/mm: move hwpoison setup into run_test() and silence modprobe
output for memory-failure category":
Updated the condition to avoid unconditional module removal and ensures it is
only unloaded if loaded by the test.
v5: https://lore.kernel.org/all/cover.1776150071.git.sayalip@linux.ibm.com/
---
---
v4->v5
- For "selftests/mm: move hwpoison setup into run_test() and silence modprobe
output for memory-failure category":
Renamed LOADED_MOD to LOADED_HWPOISON_INJECT_MOD as per review comment.
- Dropped "selftests/cgroup: extend test_hugetlb_memcg.c to support all huge
page sizes":
Due to intermittent failures observed on some systems.
- Added Tested-by from Venkat for all patches.
- Added Reviewed-by from Zi yan for patches 7,8 and 13.
- Added Acked-by from Zi yan for patches 1 and 3.
v4: https://lore.kernel.org/all/cover.1775466329.git.sayalip@linux.ibm.com/
---
v3->v4
- selftests/mm: restore default nr_hugepages value via EXIT
trap in charge_reserved_hugetlb.sh:
Updated to use an EXIT trap to restore the original nr_hugepages
once at script termination, ensuring reliable restoration on all
exit paths.
- selftest/mm: fix cgroup task placement and drop memory.current checks
in hugetlb_reparenting_test.sh:
Updated to use a deterministic synchronization method by migrating the
workload process within a wrapper subshell before calling exec() to
ensure correct cgroup accounting.
- selftest/mm: align memory size to huge page size in hugepage-mremap
test:
Update test code directly to align memory allocations to the hugepage
size, rather than modifying run_vmtests.sh. This replaces the previous
commit “adjust hugepage-mremap test size for large huge pages” with
a cleaner, direct approach in the test itself.
- selftests/mm: ensure destination is hugetlb-backed in hugepage-mremap:
Updated to remove MAP_POPULATE flag for the mmap call as per review
comment.
- selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported:
Updated as per review comment to initialize features to zero and exit
on all uffd_get_features() failures, avoiding spurious test errors.
- selftests/mm: move hwpoison setup into run_test() and silence
modprobe output for memory-failure category:
Declared LOADED_MOD as local variable and avoided a redundant
skip message when the module is not found.
Updated logic to set exitcode to ksft_skip only when no failure has
been recorded.
- selftests/cgroup: extend test_hugetlb_memcg.c to support all huge
page sizes:
Updated to skip on memory constraints instead of returning
EXIT_FAILURE.
Updated the logic to fully account for the scenario when the
per-CPU stock is empty and a refill charges MEMCG_CHARGE_BATCH.
Updated to avoid overflow on 32-bit systems for memory.max value.
- Included "selftests/mm: restore default nr_hugepages value via
EXIT trap in hugetlb_reparenting_test.sh"
- Included "selftests/mm: free dynamically allocated PMD-sized
buffers in split_huge_page_test"
- Included "selftests/mm: clarify alternate unmapping in compaction_test"
- Dropped "selftests/mm: fix double increment in linked list cleanup in
compaction_test":
The behaviour is intentional.
v3: https://lore.kernel.org/all/cover.1774591179.git.sayalip@linux.ibm.com/
---
v2->v3
- selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported:
Rename function to check_uffd_wp_feature_supported() as suggested in review.
- selftest/mm: fix cgroup task placement and drop memory.current checks
in hugetlb_reparenting_test.sh:
Drop memory.current validation from the hugetlb reparenting test.
Keep tolerance at 7MB (reverting earlier increase to 8MB in v1).
- Included "selftests/mm: allow PUD-level entries in compound testcase of hmm
tests" patch:
Extend the compound testcase checks to accept PUD-level mappings.
- Included "selftests/mm: replace hardcoded THP size with runtime PMD page size in
hmm tests" patch:
Use read_pmd_pagesize() instead of TWOMEG and cap maximum THPs in
benchmarks to avoid integer overflow.
v2: https://lore.kernel.org/all/cover.1773305677.git.sayalip@linux.ibm.com/
---
v1->v2
- For "selftests/mm: ensure destination is hugetlb-backed in hugepage-mremap":
update FLAGS definition to MAP_HUGETLB | MAP_SHARED | MAP_POPULATE and
used it for mmap() calls as suggested during review.
v1: https://lore.kernel.org/all/cover.1773134177.git.sayalip@linux.ibm.com/
---
Sayali Patil (14):
selftests/mm: restore default nr_hugepages value via exit trap in
charge_reserved_hugetlb.sh
selftests/mm: fix hugetlb pathname construction in
charge_reserved_hugetlb.sh
selftests/mm: restore default nr_hugepages value via exit trap in
hugetlb_reparenting_test.sh
selftests/mm: fix hugetlb pathname construction in
hugetlb_reparenting_test.sh
selftests/mm: fix cgroup task placement and drop memory.current checks
in hugetlb_reparenting_test.sh
selftests/mm: size tmpfs according to PMD page size in
split_huge_page_test
selftests/mm: free dynamically allocated PMD-sized buffers in
split_huge_page_test
selftest/mm: align memory size to huge page size in hugepage-mremap
test
selftest/mm: register existing mapping with userfaultfd in
hugepage-mremap
selftests/mm: ensure destination is hugetlb-backed in hugepage-mremap
selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported
selftests/mm: skip uffd-stress test when nr_pages_per_cpu is zero
selftests/mm: move hwpoison setup into run_test() and silence modprobe
output for memory-failure category
selftests/mm: clarify alternate unmapping in compaction_test
.../selftests/mm/charge_reserved_hugetlb.sh | 45 +++++++++-----
tools/testing/selftests/mm/compaction_test.c | 3 +
tools/testing/selftests/mm/hugepage-mremap.c | 42 ++++++-------
.../selftests/mm/hugetlb_reparenting_test.sh | 60 ++++++++++---------
tools/testing/selftests/mm/run_vmtests.sh | 52 ++++++++++------
.../selftests/mm/split_huge_page_test.c | 27 ++++++---
tools/testing/selftests/mm/uffd-stress.c | 6 +-
tools/testing/selftests/mm/uffd-wp-mremap.c | 13 ++++
8 files changed, 153 insertions(+), 95 deletions(-)
--
2.52.0
The test modifies nr_hugepages during execution and restores it from
cleanup() and again reconfigure it setup, which is invoked multiple
times across test flow. This can lead to repeated
allocation/freeing of hugepages.
With set -e, failures in cleanup (e.g., rmdir/umount) can also
cause early exit before restoring the original value at the end.
Move restoration of the original nr_hugepages value to a trap handler
registered for EXIT, INT, and TERM signals so it is always restored on
all exit paths. This also avoids unnecessary allocation churn across
repeated cleanup/setup cycles.
Fixes: 585a9145886a ("selftests/mm: restore default nr_hugepages value during cleanup in hugetlb_reparenting_test.sh")
Acked-by: Zi Yan <ziy@nvidia.com>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/hugetlb_reparenting_test.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
cleanup() resets nr_hugepages to 0 on every invocation, while the test
reconfigures it again in the next iteration. This leads to repeated
allocation and freeing of large numbers of hugepages, especially when
the original value is high.
Additionally, with set -e, failures in earlier cleanup steps (e.g.,
rmdir or umount returning EBUSY while background activity is still
ongoing) can cause the script to exit before restoring the original
value, leaving the system in a modified state.
Introduce a trap on EXIT, INT, and TERM to restore the original
nr_hugepages value once at script termination. This avoids
unnecessary allocation churn and ensures the original value
is reliably restored on all exit paths.
Fixes: 7d695b1c3695b ("selftests/mm: save and restore nr_hugepages value")
Acked-by: Zi Yan <ziy@nvidia.com>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/charge_reserved_hugetlb.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
The charge_reserved_hugetlb.sh script assumes hugetlb cgroup memory
interface file names use the "<size>MB" format
(e.g. hugetlb.1024MB.current).
This assumption breaks on systems with larger huge pages such as 1GB,
where the kernel exposes normalized units:
hugetlb.1GB.current
hugetlb.1GB.max
hugetlb.1GB.rsvd.max
...
As a result, the script attempts to access files like
hugetlb.1024MB.current, which do not exist when the kernel reports the
size in GB.
Normalize the huge page size and construct the pathname using the
appropriate unit (MB or GB), matching the hugetlb controller naming.
Fixes: 209376ed2a84 ("selftests/vm: make charge_reserved_hugetlb.sh work with existing cgroup setting")
Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests")
Reviewed-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
.../selftests/mm/charge_reserved_hugetlb.sh | 42 +++++++++++++------
1 file changed, 29 insertions(+), 13 deletions(-)
@@ -94,6 +94,15 @@ function get_machine_hugepage_size() {}MB=$(get_machine_hugepage_size)+if((MB>=1024));then+# For 1GB hugepages+UNIT="GB"+MB_DISPLAY=$((MB/1024))+else+# For 2MB hugepages+UNIT="MB"+MB_DISPLAY=$MB+fifunctionsetup_cgroup(){localname="$1"
@@ -103,11 +112,12 @@ function setup_cgroup() {mkdir$cgroup_path/$nameechowritingcgrouplimit:"$cgroup_limit"-echo"$cgroup_limit">$cgroup_path/$name/hugetlb.${MB}MB.$fault_limit_file+echo"$cgroup_limit">\+$cgroup_path/$name/hugetlb.${MB_DISPLAY}${UNIT}.$fault_limit_fileechowritingreservationlimit:"$reservation_limit"echo"$reservation_limit">\-$cgroup_path/$name/hugetlb.${MB}MB.$reservation_limit_file+$cgroup_path/$name/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_limit_fileif[-e"$cgroup_path/$name/cpuset.cpus"];thenecho0>$cgroup_path/$name/cpuset.cpus
@@ -142,7 +152,7 @@ function wait_for_file_value() {functionwait_for_hugetlb_memory_to_get_depleted(){localcgroup="$1"-localpath="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"+localpath="$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file"wait_for_file_value"$path""0"}
@@ -150,7 +160,7 @@ function wait_for_hugetlb_memory_to_get_depleted() {functionwait_for_hugetlb_memory_to_get_reserved(){localcgroup="$1"localsize="$2"-localpath="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file"+localpath="$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file"wait_for_file_value"$path""$size"}
@@ -158,7 +168,7 @@ function wait_for_hugetlb_memory_to_get_reserved() {functionwait_for_hugetlb_memory_to_get_written(){localcgroup="$1"localsize="$2"-localpath="$cgroup_path/$cgroup/hugetlb.${MB}MB.$fault_usage_file"+localpath="$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file"wait_for_file_value"$path""$size"}
@@ -180,8 +190,8 @@ function write_hugetlbfs_and_get_usage() {hugetlb_difference=0reserved_difference=0-localhugetlb_usage=$cgroup_path/$cgroup/hugetlb.${MB}MB.$fault_usage_file-localreserved_usage=$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file+localhugetlb_usage=$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file+localreserved_usage=$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_filelocalhugetlb_before=$(cat$hugetlb_usage)localreserved_before=$(cat$reserved_usage)
@@ -312,8 +322,10 @@ function run_test() {cleanup_hugetlb_memory"hugetlb_cgroup_test"-localfinal_hugetlb=$(cat$cgroup_path/hugetlb_cgroup_test/hugetlb.${MB}MB.$fault_usage_file)-localfinal_reservation=$(cat$cgroup_path/hugetlb_cgroup_test/hugetlb.${MB}MB.$reservation_usage_file)+localfinal_hugetlb=$(cat\+$cgroup_path/hugetlb_cgroup_test/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file)+localfinal_reservation=$(cat\+$cgroup_path/hugetlb_cgroup_test/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file)echo$hugetlb_differenceecho$reserved_difference
@@ -369,10 +381,14 @@ function run_multiple_cgroup_test() {reservation_failed1=$reservation_failedoom_killed1=$oom_killed-localcgroup1_hugetlb_usage=$cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB}MB.$fault_usage_file-localcgroup1_reservation_usage=$cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB}MB.$reservation_usage_file-localcgroup2_hugetlb_usage=$cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB}MB.$fault_usage_file-localcgroup2_reservation_usage=$cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB}MB.$reservation_usage_file+localcgroup1_hugetlb_usage=\+$cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file+localcgroup1_reservation_usage=\+$cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file+localcgroup2_hugetlb_usage=\+$cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file+localcgroup2_reservation_usage=\+$cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_filelocalusage_before_second_write=$(cat$cgroup1_hugetlb_usage)localreservation_usage_before_second_write=$(cat$cgroup1_reservation_usage)
The hugetlb_reparenting_test.sh script constructs hugetlb cgroup
memory interface file names based on the configured huge page size. The
script formats the size only in MB units, which causes mismatches on
systems using larger huge pages where the kernel exposes normalized
units (e.g. "1GB" instead of "1024MB").
As a result, the test fails to locate the corresponding cgroup files
when 1GB huge pages are configured.
Update the script to detect the huge page size and select the
appropriate unit (MB or GB) so that the constructed paths match the
kernel's hugetlb controller naming.
Also print an explicit "Fail" message when a test failure occurs to
improve result visibility.
Fixes: e487a5d513cb ("selftest/mm: make hugetlb_reparenting_test tolerant to async reparenting")
Reviewed-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
.../selftests/mm/hugetlb_reparenting_test.sh | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
The split_file_backed_thp() test mounts a tmpfs with a fixed size of
"4m". This works on systems with smaller PMD page sizes,
but fails on configurations where the PMD huge page size is
larger (e.g. 16MB).
On such systems, the fixed 4MB tmpfs is insufficient to allocate even
a single PMD-sized THP, causing the test to fail.
Fix this by sizing the tmpfs dynamically based on the runtime
pmd_pagesize, allocating space for two PMD-sized pages.
Before patch:
running ./split_huge_page_test /tmp/xfs_dir_YTrI5E
--------------------------------------------------
TAP version 13
1..55
ok 1 Split zero filled huge pages successful
ok 2 Split huge pages to order 0 successful
ok 3 Split huge pages to order 2 successful
ok 4 Split huge pages to order 3 successful
ok 5 Split huge pages to order 4 successful
ok 6 Split huge pages to order 5 successful
ok 7 Split huge pages to order 6 successful
ok 8 Split huge pages to order 7 successful
ok 9 Split PTE-mapped huge pages successful
Please enable pr_debug in split_huge_pages_in_file() for more info.
Failed to write data to testing file: Success (0)
Bail out! Error occurred
Planned tests != run tests (55 != 9)
Totals: pass:9 fail:0 xfail:0 xpass:0 skip:0 error:0
[FAIL]
After patch:
running ./split_huge_page_test /tmp/xfs_dir_bMvj6o
--------------------------------------------------
TAP version 13
1..55
ok 1 Split zero filled huge pages successful
ok 2 Split huge pages to order 0 successful
ok 3 Split huge pages to order 2 successful
ok 4 Split huge pages to order 3 successful
ok 5 Split huge pages to order 4 successful
ok 6 Split huge pages to order 5 successful
ok 7 Split huge pages to order 6 successful
ok 8 Split huge pages to order 7 successful
ok 9 Split PTE-mapped huge pages successful
Please enable pr_debug in split_huge_pages_in_file() for more info.
Please check dmesg for more information
ok 10 File-backed THP split to order 0 test done
Please enable pr_debug in split_huge_pages_in_file() for more info.
Please check dmesg for more information
ok 11 File-backed THP split to order 1 test done
Please enable pr_debug in split_huge_pages_in_file() for more info.
Please check dmesg for more information
ok 12 File-backed THP split to order 2 test done
...
ok 55 Split PMD-mapped pagecache folio to order 7 at
in-folio offset 128 passed
Totals: pass:55 fail:0 xfail:0 xpass:0 skip:0 error:0
[PASS]
ok 1 split_huge_page_test /tmp/xfs_dir_bMvj6o
Fixes: fbe37501b252 ("mm: huge_memory: debugfs for file-backed THP split")
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/split_huge_page_test.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
@@ -489,7 +491,8 @@ static void split_file_backed_thp(int order)file_buf1[i]=(char)i;memset(file_buf2,0,pmd_pagesize);-status=mount("tmpfs",tmpfs_loc,"tmpfs",0,"huge=always,size=4m");+snprintf(opts,sizeof(opts),"huge=always,size=%lu",size);+status=mount("tmpfs",tmpfs_loc,"tmpfs",0,opts);if(status)ksft_exit_fail_msg("Unable to create a tmpfs for testing\n");
Dynamically allocated buffers of PMD size for file-backed
THP operations (file_buf1 and file_buf2) were not freed on
the success path and some failure paths. Since the
function is called repeatedly in a loop for each split order,
this can cause significant memory leaks.
On architectures with large PMD sizes, repeated leaks
could exhaust system memory and trigger the OOM killer
during test execution.
Ensure all allocated buffers are freed to maintain
stable repeated test runs.
Fixes: 035a112e5fd5 ("selftests/mm: make file-backed THP split work by writing PMD size data")
Reviewed-by: Zi Yan <ziy@nvidia.com>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
.../selftests/mm/split_huge_page_test.c | 22 ++++++++++++++-----
1 file changed, 16 insertions(+), 6 deletions(-)
@@ -473,12 +473,15 @@ static void split_file_backed_thp(int order)unsignedlongsize=2*pmd_pagesize;charopts[64];ssize_tnum_written,num_read;-char*file_buf1,*file_buf2;+char*file_buf1=NULL,*file_buf2=NULL;uint64_tpgoff_start=0,pgoff_end=1024;inti;ksft_print_msg("Please enable pr_debug in split_huge_pages_in_file() for more info.\n");+if(!tmpfs_loc)+ksft_exit_fail_msg("mkdtemp failed\n");+file_buf1=(char*)malloc(pmd_pagesize);file_buf2=(char*)malloc(pmd_pagesize);
@@ -494,8 +497,10 @@ static void split_file_backed_thp(int order)snprintf(opts,sizeof(opts),"huge=always,size=%lu",size);status=mount("tmpfs",tmpfs_loc,"tmpfs",0,opts);-if(status)-ksft_exit_fail_msg("Unable to create a tmpfs for testing\n");+if(status){+ksft_print_msg("Unable to create a tmpfs for testing\n");+gotoout;+}status=snprintf(testfile,INPUT_MAX,"%s/thp_file",tmpfs_loc);if(status>=INPUT_MAX){
@@ -547,10 +552,13 @@ static void split_file_backed_thp(int order)status=umount(tmpfs_loc);if(status){-rmdir(tmpfs_loc);-ksft_exit_fail_msg("Unable to umount %s\n",tmpfs_loc);+ksft_print_msg("Unable to umount %s\n",tmpfs_loc);+gotoout;}+free(file_buf1);+free(file_buf2);+status=rmdir(tmpfs_loc);if(status)ksft_exit_fail_msg("cannot remove tmp dir: %s\n",strerror(errno));
The hugepage-mremap selftest uses a default mapping size of 10MB
when no argument is provided. This size is not guaranteed to be
aligned to the system hugepage size, which can cause munmap() to fail
and mremap() to succeed where a failure is expected.
Align the mapping length to the runtime hugepage size using
default_huge_page_size() to ensure the mapping is properly
aligned. Also handle the case where
default_huge_page_size() returns 0 by skipping the test.
Before patch:
running ./hugepage-mremap
------------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000
Map daddr: Returned address is 0x7daa40000000
Map vaddr: Returned address is 0x7faa40000000
Address returned by mmap() = 0x7fffaa600000
Mremap: Returned address is 0x7faa40000000
First hex is 0
First hex is 3020100
Bail out! mremap: Expected failure, but call succeeded
Planned tests != run tests (1 != 0)
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
[FAIL]
not ok 1 hugepage-mremap # exit=1
After patch:
running ./hugepage-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000
Map daddr: Returned address is 0x7daa40000000
Map vaddr: Returned address is 0x7faa40000000
Address returned by mmap() = 0x7fff13000000
Mremap: Returned address is 0x7faa40000000
First hex is 0
First hex is 3020100
ok 1 Read same data
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
[PASS]
ok 1 hugepage-mremap
Fixes: f77a286de48c ("mm, hugepages: make memory size variable in hugepage-mremap selftest")
Reviewed-by: Zi Yan <ziy@nvidia.com>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/hugepage-mremap.c | 10 ++++++++++
1 file changed, 10 insertions(+)
Previously, register_region_with_uffd() created a new anonymous
mapping and overwrote the address supplied by the caller before
registering the range with userfaultfd.
As a result, userfaultfd was applied to an unrelated anonymous mapping
instead of the hugetlb region used by the test.
Remove the extra mmap() and register the caller-provided address range
directly using UFFDIO_REGISTER_MODE_MISSING, so that faults are
generated for the hugetlb mapping used by the test.
This ensures userfaultfd operates on the actual hugetlb test region and
validates the expected fault handling.
Before patch:
running ./hugepage-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000
Map daddr: Returned address is 0x7daa40000000
Map vaddr: Returned address is 0x7faa40000000
Address returned by mmap() = 0x7fff9d000000
Mremap: Returned address is 0x7faa40000000
First hex is 0
First hex is 3020100
ok 1 Read same data
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
[PASS]
ok 1 hugepage-mremap
After patch:
running ./hugepage-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000
Map daddr: Returned address is 0x7daa40000000
Map vaddr: Returned address is 0x7faa40000000
Registered memory at address 0x7eaa40000000 with userfaultfd
Mremap: Returned address is 0x7faa40000000
First hex is 0
First hex is 3020100
ok 1 Read same data
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
[PASS]
ok 1 hugepage-mremap
Fixes: 12b613206474 ("mm, hugepages: add hugetlb vma mremap() test")
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/hugepage-mremap.c | 21 +++++---------------
1 file changed, 5 insertions(+), 16 deletions(-)
@@ -86,25 +86,14 @@ static void register_region_with_uffd(char *addr, size_t len)if(ioctl(uffd,UFFDIO_API,&uffdio_api)==-1)ksft_exit_fail_msg("ioctl-UFFDIO_API: %s\n",strerror(errno));-/* Create a private anonymous mapping. The memory will be-*demand-zeropaged--thatis,notyetallocated.Whenwe-*actuallytouchthememory,itwillbeallocatedvia-*theuserfaultfd.-*/--addr=mmap(NULL,len,PROT_READ|PROT_WRITE,-MAP_PRIVATE|MAP_ANONYMOUS,-1,0);-if(addr==MAP_FAILED)-ksft_exit_fail_msg("mmap: %s\n",strerror(errno));--ksft_print_msg("Address returned by mmap() = %p\n",addr);--/* Register the memory range of the mapping we just created for-*handlingbytheuserfaultfdobject.Inmode,werequesttotrack-*missingpages(i.e.,pagesthathavenotyetbeenfaultedin).+/* Register the passed memory range for handling by the userfaultfd object.+*Inmode,werequesttotrackmissingpages+*(i.e.,pagesthathavenotyetbeenfaultedin).*/if(uffd_register(uffd,addr,len,true,false,false))ksft_exit_fail_msg("ioctl-UFFDIO_REGISTER: %s\n",strerror(errno));++ksft_print_msg("Registered memory at address %p with userfaultfd\n",addr);}intmain(intargc,char*argv[])
The hugepage-mremap selftest reserves the destination address using a
anonymous base-page mapping before calling mremap() with MREMAP_FIXED,
while the source region is hugetlb-backed.
When remapping a hugetlb mapping into a base-page VMA may fail with:
mremap: Device or resource busy
This is observed on powerpc hash MMU systems where slice constraints
and page size incompatibilities prevent the remap.
Ensure the destination region is created using MAP_HUGETLB so that both
source and destination VMAs are hugetlb-backed and compatible.
Update the FLAGS macro to include MAP_HUGETLB | MAP_SHARED
so that both mappings are hugetlb-backed and compatible.
Also use the macro for the mmap() calls to avoid repeating
the flag combination.
This ensures the test reliably exercises hugetlb mremap instead of
failing due to VMA type mismatch.
Fixes: 12b613206474 ("mm, hugepages: add hugetlb vma mremap() test")
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/hugepage-mremap.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
@@ -131,23 +131,20 @@ int main(int argc, char *argv[])/* mmap to a PUD aligned address to hopefully trigger pmd sharing. */unsignedlongsuggested_addr=0x7eaa40000000;-void*haddr=mmap((void*)suggested_addr,length,PROTECTION,-MAP_HUGETLB|MAP_SHARED|MAP_POPULATE,fd,0);+void*haddr=mmap((void*)suggested_addr,length,PROTECTION,FLAGS,fd,0);ksft_print_msg("Map haddr: Returned address is %p\n",haddr);if(haddr==MAP_FAILED)ksft_exit_fail_msg("mmap1: %s\n",strerror(errno));/* mmap again to a dummy address to hopefully trigger pmd sharing. */suggested_addr=0x7daa40000000;-void*daddr=mmap((void*)suggested_addr,length,PROTECTION,-MAP_HUGETLB|MAP_SHARED|MAP_POPULATE,fd,0);+void*daddr=mmap((void*)suggested_addr,length,PROTECTION,FLAGS,fd,0);ksft_print_msg("Map daddr: Returned address is %p\n",daddr);if(daddr==MAP_FAILED)ksft_exit_fail_msg("mmap3: %s\n",strerror(errno));suggested_addr=0x7faa40000000;-void*vaddr=-mmap((void*)suggested_addr,length,PROTECTION,FLAGS,-1,0);+void*vaddr=mmap((void*)suggested_addr,length,PROTECTION,FLAGS,fd,0);ksft_print_msg("Map vaddr: Returned address is %p\n",vaddr);if(vaddr==MAP_FAILED)ksft_exit_fail_msg("mmap2: %s\n",strerror(errno));
uffd-stress currently fails when the computed nr_pages_per_cpu
evaluates to zero:
nr_pages_per_cpu = bytes / page_size / nr_parallel
This can occur on systems with large hugepage sizes (e.g. 1GB) and a
high number of CPUs, where the total allocated memory is sufficient
overall but not enough to provide at least one page per cpu.
In such cases, the failure is due to insufficient test resources
rather than incorrect kernel behaviour. Update the test
to treat this condition as a test skip instead of reporting an error.
Fixes: db0f1c138f18 ("selftests/mm: print some details when uffd-stress gets bad params")
Acked-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/uffd-stress.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -19,6 +19,17 @@ static size_t thpsizes[20];staticintnr_hugetlbsizes;staticsize_thugetlbsizes[10];+staticvoidcheck_uffd_wp_feature_supported(void)+{+uint64_tfeatures=0;++if(uffd_get_features(&features))+ksft_exit_skip("failed to get available features (%d)\n",errno);++if(!(features&UFFD_FEATURE_PAGEFAULT_FLAG_WP))+ksft_exit_skip("uffd-wp feature not supported\n");+}+staticintdetect_thp_sizes(size_tsizes[],intmax){intcount=0;
@@ -336,6 +347,8 @@ int main(int argc, char **argv)structthp_settingssettings;inti,j,plan=0;+check_uffd_wp_feature_supported();+pagesize=getpagesize();nr_thpsizes=detect_thp_sizes(thpsizes,ARRAY_SIZE(thpsizes));nr_hugetlbsizes=detect_hugetlb_page_sizes(hugetlbsizes,
Add a comment explaining that every other entry in the list is
unmapped to intentionally create fragmentation with
locked pages before invoking check_compaction().
Fixes: bd67d5c15cc1 ("Test compaction of mlocked memory")
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/compaction_test.c | 3 +++
1 file changed, 3 insertions(+)
@@ -261,6 +261,9 @@ int main(int argc, char **argv)mem_fragmentable_MB-=MAP_SIZE_MB;}+/* Unmap every other entry in the list to create fragmentation with+*lockedpagesbeforeinvokingcheck_compaction().+*/for(entry=list;entry!=NULL;entry=entry->next){munmap(entry->map,MAP_SIZE);if(!entry->next)
run_vmtests.sh contains special handling to ensure the hwpoison_inject
module is available for the memory-failure tests. This logic was
implemented outside of run_test(), making the setup category-specific
but managed globally.
Move the hwpoison_inject handling into run_test() and restrict it
to the memory-failure category so that:
1. the module is checked and loaded only when memory-failure tests run,
2. the test is skipped if the module or the debugfs interface
(/sys/kernel/debug/hwpoison/) is not available.
3. the module is unloaded after the test if it was loaded by the script.
This localizes category-specific setup and makes the test flow
consistent with other per-category preparations.
While updating this logic, fix the module availability check.
The script previously used:
modprobe -R hwpoison_inject
The -R option prints the resolved module name to stdout, causing every
run to print:
hwpoison_inject
in the test output, even when no action is required, introducing
unnecessary noise.
Replace this with:
modprobe -n hwpoison_inject
which verifies that the module is loadable without producing output,
keeping the selftest logs clean and consistent.
Also, ensure that skipped tests do not override a previously recorded
failure. A skipped test currently sets exitcode to ksft_skip even if a
prior test has failed, which can mask failures in the final exit status.
Update the logic to only set exitcode to ksft_skip when no failure has
been recorded.
Fixes: ff4ef2fbd101 ("selftests/mm: add memory failure anonymous page test")
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Tested-by: Venkat Rao Bagalkote <redacted>
Signed-off-by: Sayali Patil <redacted>
---
tools/testing/selftests/mm/run_vmtests.sh | 52 ++++++++++++++---------
1 file changed, 33 insertions(+), 19 deletions(-)
@@ -235,6 +235,7 @@ pretty_name() { run_test(){iftest_selected${CATEGORY};thenlocalskip=0+localLOADED_HWPOISON_INJECT_MOD=0# On memory constrainted systems some tests can fail to allocate hugepages.# perform some cleanup before the test for a higher success rate.
@@ -250,6 +251,28 @@ run_test() {fifi+# Ensure hwpoison_inject is available for memory-failure tests+if["${CATEGORY}"="memory-failure"];then+# Try to load hwpoison_inject if not present.+HWPOISON_DIR=/sys/kernel/debug/hwpoison/+if[!-d"$HWPOISON_DIR"];then+if!modprobe-nhwpoison_inject>/dev/null2>&1;then+echo"Module hwpoison_inject not found, skipping..."\+|tap_prefix+skip=1+else+modprobehwpoison_inject>/dev/null2>&1+LOADED_HWPOISON_INJECT_MOD=1+if[!-d"$HWPOISON_DIR"];then+echo"hwpoison debugfs interface not present"\+|tap_prefix+skip=1+fi+fi+fi++fi+localtest=$(pretty_name"$*")localtitle="running $*"localsep=$(echo-n"$title"|tr"[:graph:][:space:]"-)
@@ -261,6 +284,12 @@ run_test() {elselocalret=$ksft_skipfi++# Unload hwpoison_inject if we loaded it+if["${LOADED_HWPOISON_INJECT_MOD}"="1"];then+modprobe-rhwpoison_inject>/dev/null2>&1+fi+count_total=$((count_total+1))if[$ret-eq0];thencount_pass=$((count_pass+1))
@@ -531,24 +562,7 @@ CATEGORY="page_frag" run_test ./test_page_frag.sh nonalignedCATEGORY="rmap"run_test./rmap-# Try to load hwpoison_inject if not present.-HWPOISON_DIR=/sys/kernel/debug/hwpoison/-if[!-d"$HWPOISON_DIR"];then-if!modprobe-q-Rhwpoison_inject;then-echo"Module hwpoison_inject not found, skipping..."-else-modprobehwpoison_inject>/dev/null2>&1-LOADED_MOD=1-fi-fi--if[-d"$HWPOISON_DIR"];then-CATEGORY="memory-failure"run_test./memory-failure-fi--if[-n"${LOADED_MOD}"];then-modprobe-rhwpoison_inject>/dev/null2>&1-fi+CATEGORY="memory-failure"run_test./memory-failureif["${HAVE_HUGEPAGES}"=1];thenecho"$orig_nr_hugepgs">/proc/sys/vm/nr_hugepages
The test currently moves the calling shell ($$) into the target cgroup
before executing write_to_hugetlbfs. This results in the shell and any
intermediate allocations being charged to the cgroup, introducing noise
and nondeterminism in accounting. It also requires moving the shell back
to the root cgroup after execution.
Spawn a helper process that joins the target cgroup and
exec()'s write_to_hugetlbfs. This ensures that only the workload is
accounted to the cgroup and avoids unintended charging from the shell.
The test currently validates both hugetlb usage and memory.current.
However, memory.current includes internal memcg allocations and
per-CPU batched accounting (MEMCG_CHARGE_BATCH), which are not
synchronized and can vary across systems, leading to
non-deterministic results.
Since hugetlb memory is accounted via hugetlb.<size>.current,
memory.current is not a reliable indicator here. Drop memory.current
checks and rely only on hugetlb controller statistics for stable
and accurate validation.
Fixes: 29750f71a9b4 ("hugetlb_cgroup: add hugetlb_cgroup reservation tests")
Signed-off-by: Sayali Patil <redacted>
---
.../selftests/mm/hugetlb_reparenting_test.sh | 42 ++++++++-----------
1 file changed, 18 insertions(+), 24 deletions(-)
From: Andrew Morton <akpm@linux-foundation.org> Date: 2026-05-13 03:10:44
On Mon, 4 May 2026 13:54:37 +0530 Sayali Patil [off-list ref] wrote:
Powerpc systems with a 64K base page size exposed several issues while
running mm selftests. Some tests assume specific hugetlb configurations,
use incorrect interfaces, or fail instead of skipping when the required
kernel features are not available.
This series fixes these issues and improves test robustness.
From: Andrew Morton <akpm@linux-foundation.org> Date: 2026-05-13 03:24:40
On Mon, 4 May 2026 13:54:37 +0530 Sayali Patil [off-list ref] wrote:
Powerpc systems with a 64K base page size exposed several issues while
running mm selftests. Some tests assume specific hugetlb configurations,
use incorrect interfaces, or fail instead of skipping when the required
kernel features are not available.
This series fixes these issues and improves test robustness.
Sorry, bitrot. Mike's monster series "make MM selftests more CI
friendly" has moved a lot of this code around then altered it. Can you
please redo against mm.git's mm-new branch?
Thanks.
Hi Andrew,
Sure, I will rebase the series on top of the current mm-new branch and resend an updated version. It appears that Mike’s changes have modified many selftests, so I will adjust the series accordingly and ensure it applies cleanly.
Thanks,
Sayali
On 13/05/26 08:54, Andrew Morton wrote:
On Mon, 4 May 2026 13:54:37 +0530 Sayali Patil [off-list ref] wrote:
quoted
Powerpc systems with a 64K base page size exposed several issues while
running mm selftests. Some tests assume specific hugetlb configurations,
use incorrect interfaces, or fail instead of skipping when the required
kernel features are not available.
This series fixes these issues and improves test robustness.
Sorry, bitrot. Mike's monster series "make MM selftests more CI
friendly" has moved a lot of this code around then altered it. Can you
please redo against mm.git's mm-new branch?
Thanks.