Re: [PATCH v4] selftests/mm: add folio_split() and filemap_get_entry() race test
From: Zi Yan
Date: Fri Mar 20 2026 - 14:01:05 EST
On 20 Mar 2026, at 10:22, Zi Yan wrote:
> The added folio_split_race_test is a modified C port of the race condition
> test from [1]. The test creates shmem huge pages, where the main thread
> punches holes in the shmem to cause folio_split() in the kernel and
> a set of 16 threads reads the shmem to cause filemap_get_entry() in the
> kernel. filemap_get_entry() reads the folio and xarray split by
> folio_split() locklessly. The original test[2] is written in rust and uses
> memfd (shmem backed). This C port uses shmem directly and use a single
> process.
>
> Note: the initial rust to C conversion is done by Cursor.
>
> Link: https://lore.kernel.org/all/CAKNNEtw5_kZomhkugedKMPOG-sxs5Q5OLumWJdiWXv+C9Yct0w@xxxxxxxxxxxxxx/ [1]
> Link: https://github.com/dfinity/thp-madv-remove-test [2]
> Signed-off-by: Bas van Dijk <bas@xxxxxxxxxxx>
> Signed-off-by: Adam Bratschi-Kaye <adam.bratschikaye@xxxxxxxxxxx>
> Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
> ---
> From V3:
> 1. fixed for loop stepping issue
> 2. used PRIu64 instead of %zu for uint64_t.
>
> From V2:
> 1. simplied the program by removing fork.
>
> From V1:
> 1. added prctl(PR_SET_PDEATHSIG, SIGTERM) to avoid child looping
> forever.
> 2. removed page_idx % PUNCH_INTERVAL >= 0, since it is a nop. Added a
> comment.
> 3. added a child process status check to prevent parent looping forever
> and record that as a failure.
> 4. used ksft_exit_skip() instead of ksft_finished() when the program is
> not running as root.
> 5. restored THP settings properly when the program exits abnormally.
> tools/testing/selftests/mm/Makefile | 1 +
> .../selftests/mm/folio_split_race_test.c | 293 ++++++++++++++++++
> tools/testing/selftests/mm/run_vmtests.sh | 2 +
> 3 files changed, 296 insertions(+)
> create mode 100644 tools/testing/selftests/mm/folio_split_race_test.c
>
Hi Andrew,
The fixup below adds folio_split_race_test binary to .gitignore.
Thank Lorenzo for pointing this out.
From bd164a7090c0e8b6e3013502c64c161214e38714 Mon Sep 17 00:00:00 2001
From: Zi Yan <ziy@xxxxxxxxxx>
Date: Fri, 20 Mar 2026 13:56:04 -0400
Subject: [PATCH] git: add generated binary into gitignore
Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
---
tools/testing/selftests/mm/.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore
index 83ad9454dd9d1..b0c30c5ee9e30 100644
--- a/tools/testing/selftests/mm/.gitignore
+++ b/tools/testing/selftests/mm/.gitignore
@@ -61,3 +61,4 @@ guard-regions
merge
prctl_thp_disable
rmap
+folio_split_race_test
--
2.51.0
Best Regards,
Yan, Zi