Skip to contentSkip to conversation

selftests/mm: add folio_split() and filemap_get_entry() race test

PATCH Superseded Zi Yan 1 participant 2 messages Mar 19

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zi Yan

author
#0 lore raw

PATCH v2 1/1 selftests/mm: add folio_split() and filemap_get_entry() race test

The added folio_split_race_test is a modified C port of the race condition test from [1]. The test creates shmem huge pages shared by both a parent and a child processes, where the parent process punches holes in the shmem to cause folio_split() in the kernel and the child process reads the shmem in 16 threads 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.

Note: the initial rust to C conversion is done by Cursor.

---
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      | 431 ++++++++++++++++++
 tools/testing/selftests/mm/run_vmtests.sh     |   2 +
 3 files changed, 434 insertions(+)
 create mode 100644 tools/testing/selftests/mm/folio_split_race_test.c
tools/testing/selftests/mm/Makefile +1 -0
index 7a5de4e9bf520..cd24596cdd27e 100644
@@ -105,6 +105,7 @@ TEST_GEN_FILES += droppable
 TEST_GEN_FILES += guard-regions
 TEST_GEN_FILES += merge
 TEST_GEN_FILES += rmap
+TEST_GEN_FILES += folio_split_race_test
 
 ifneq ($(ARCH),arm64)
 TEST_GEN_FILES += soft-dirty
tools/testing/selftests/mm/folio_split_race_test.c new file +431 -0

431 lines not on this page · raw message

tools/testing/selftests/mm/run_vmtests.sh +2 -0
index 606558cc3b098..530980fdf3227 100755
@@ -553,6 +553,8 @@ if [ -n "${MOUNTED_XFS}" ]; then
     rm -f ${XFS_IMG}
 fi
 
+CATEGORY="thp" run_test ./folio_split_race_test
+
 CATEGORY="migration" run_test ./migration
 
 CATEGORY="mkdirty" run_test ./mkdirty
Signature · 1 line
2.51.0
author
#1 lore raw
Quoted 28 lines · Zi Yan

The added folio_split_race_test is a modified C port of the race condition test from [1]. The test creates shmem huge pages shared by both a parent and a child processes, where the parent process punches holes in the shmem to cause folio_split() in the kernel and the child process reads the shmem in 16 threads 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.

Note: the initial rust to C conversion is done by Cursor.

---
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.

Quoted 6 lines
 tools/testing/selftests/mm/Makefile           |   1 +
 .../selftests/mm/folio_split_race_test.c      | 431 ++++++++++++++++++
 tools/testing/selftests/mm/run_vmtests.sh     |   2 +
 3 files changed, 434 insertions(+)
 create mode 100644 tools/testing/selftests/mm/folio_split_race_test.c

It seems that I sent a stale version. Will update it. Sorry for the noise.

Best Regards,
Yan, Zi