gup_test.c currently serves two distinct purposes: microbenchmarking
(GUP_FAST_BENCHMARK, PIN_FAST_BENCHMARK, PIN_LONGTERM_BENCHMARK) and
functional correctness testing (GUP_BASIC_TEST, PIN_BASIC_TEST,
DUMP_USER_PAGES_TEST). Mixing these in a single binary means functional
tests cannot be run or reported individually and run_vmtests.sh must
invoke the binary multiple times with different flag combinations to
cover all configurations.
This patch series separates the two concerns: tools/mm/gup_bench for
benchmarking and tools/testing/selftests/mm/gup_test for functional
testing. To avoid duplicating HugeTLB and related file helpers, the
series first moves the common helper code to tools/lib/mm/ so it can be
shared by both selftests and tools/mm.
Patch 1 adds tools/lib/mm/file_utils.[ch], moving read_file(),
write_file(), read_num() and write_num() out of vm_util.c into a shared
helper without a kselftest dependency. It also adds tools/lib/mm/ to the
MEMORY MANAGEMENT - MISC entry in MAINTAINERS.
Patch 2 moves hugepage_settings.[ch] from selftests/mm to tools/lib/mm/,
updates the selftests/mm users to include it from there and removes the
remaining kselftest dependency from the implementation while dropping
non-fatal hugetlb informational prints from the shared helper.
Patch 3 adds tools/mm/gup_bench.c, a standalone microbenchmark for
GUP_FAST, PIN_FAST and PIN_LONGTERM via the CONFIG_GUP_TEST debugfs
interface. It runs the same matrix of configurations as the old
run_gup_matrix() shell function (all three commands, read/write,
private/shared, four page counts, THP on/off, hugetlb), but as a
standalone C program under tools/mm using the shared tools/lib/mm
helpers.
Patch 4 rewrites gup_test.c as a kselftest harness-based selftest. It
covers all five GUP kernel functions (get_user_pages, get_user_pages_fast,
pin_user_pages, pin_user_pages_fast, pin_user_pages with FOLL_LONGTERM)
plus DUMP_USER_PAGES_TEST, across 12 mapping configurations (THP on,
THP off and hugetlb, each across private/shared and read/write variants)
and four batch sizes (1, 512, 123, all pages). It also preserves the old
sparse dump coverage for pages 0, 19 and 0x1000. Results are reported as
standard TAP output with no command-line arguments required.
---
These patches apply on top of mm/mm-new.
Changes in v3:
- Address v2 feedback from Sashiko
- Add shared file_utils helpers under tools/lib/mm
- Move hugepage_settings out of selftests and into tools/lib/mm
- Convert gup_bench to use the shared tools/lib/mm helpers
- Guard against invalid thread counts in gup_bench
- Handle thread-array allocation failure cleanly in gup_bench
- Restore hugetlb settings on setup failure in gup_test
- Add sparse DUMP_USER_PAGES_TEST coverage for pages 0, 19 and 0x1000 in gup_test
Changes in v2:
- Address v1 feedback from Sashiko
- Add fast and longterm GUP/PUP coverage
- Sweep nr_pages_per_call over 1, 512, 123 and all pages
- Call madvise(MADV_NOHUGEPAGE) in non-THP variants
- Use 256 MB for hugetlb fixtures
- Use hugetlb_restore_settings() in FIXTURE_TEARDOWN instead of atexit()
- Add TH_LOG to report nr_pages_per_call for each iteration
- Update Documentation/core-api/pin_user_pages.rst unit testing section
Previous versions:
v2: https://lore.kernel.org/all/20260519120506.184512-1-sarthak.sharma@arm.com/
v1: https://lore.kernel.org/all/20260515084840.174652-1-sarthak.sharma@arm.com/
---
Sarthak Sharma (4):
tools/lib/mm: add shared file helpers
tools/lib/mm: move hugepage_settings out of selftests
tools/mm: add a standalone GUP microbenchmark
selftests/mm: rewrite gup_test as a standalone harness-based selftest
Documentation/core-api/pin_user_pages.rst | 12 +-
MAINTAINERS | 2 +
tools/lib/mm/file_utils.c | 83 +++
tools/lib/mm/file_utils.h | 12 +
.../selftests => lib}/mm/hugepage_settings.c | 14 +-
.../selftests => lib}/mm/hugepage_settings.h | 0
tools/mm/.gitignore | 2 +
tools/mm/Makefile | 10 +-
tools/mm/gup_bench.c | 390 ++++++++++++
tools/testing/selftests/mm/Makefile | 8 +-
tools/testing/selftests/mm/compaction_test.c | 2 +-
tools/testing/selftests/mm/cow.c | 2 +-
.../selftests/mm/folio_split_race_test.c | 3 +-
tools/testing/selftests/mm/guard-regions.c | 3 +-
tools/testing/selftests/mm/gup_longterm.c | 2 +-
tools/testing/selftests/mm/gup_test.c | 587 +++++++++++-------
tools/testing/selftests/mm/hmm-tests.c | 6 +-
tools/testing/selftests/mm/hugetlb-madvise.c | 3 +-
tools/testing/selftests/mm/hugetlb-mmap.c | 3 +-
tools/testing/selftests/mm/hugetlb-mremap.c | 3 +-
tools/testing/selftests/mm/hugetlb-shm.c | 2 +-
.../selftests/mm/hugetlb-soft-offline.c | 2 +-
tools/testing/selftests/mm/hugetlb-vmemmap.c | 3 +-
tools/testing/selftests/mm/hugetlb_dio.c | 3 +-
.../selftests/mm/hugetlb_fault_after_madv.c | 2 +-
.../selftests/mm/hugetlb_madv_vs_map.c | 2 +-
tools/testing/selftests/mm/khugepaged.c | 3 +-
tools/testing/selftests/mm/ksm_tests.c | 2 +-
tools/testing/selftests/mm/migration.c | 6 +-
tools/testing/selftests/mm/pagemap_ioctl.c | 2 +-
.../testing/selftests/mm/prctl_thp_disable.c | 2 +-
tools/testing/selftests/mm/protection_keys.c | 2 +-
tools/testing/selftests/mm/run_vmtests.sh | 37 +-
tools/testing/selftests/mm/soft-dirty.c | 2 +-
.../selftests/mm/split_huge_page_test.c | 4 +-
tools/testing/selftests/mm/thuge-gen.c | 3 +-
tools/testing/selftests/mm/transhuge-stress.c | 3 +-
tools/testing/selftests/mm/uffd-common.h | 2 +-
tools/testing/selftests/mm/uffd-wp-mremap.c | 3 +-
.../selftests/mm/va_high_addr_switch.c | 2 +-
tools/testing/selftests/mm/vm_util.c | 65 +-
tools/testing/selftests/mm/vm_util.h | 5 -
42 files changed, 935 insertions(+), 369 deletions(-)
create mode 100644 tools/lib/mm/file_utils.c
create mode 100644 tools/lib/mm/file_utils.h
rename tools/{testing/selftests => lib}/mm/hugepage_settings.c (98%)
rename tools/{testing/selftests => lib}/mm/hugepage_settings.h (100%)
create mode 100644 tools/mm/gup_bench.c
base-commit: 4c6512d033e5e9469cc76d07512c24a0ee0ac207
--
2.39.5