[PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing

Sarthak Sharma posted 5 patches 1 week, 5 days ago
Documentation/core-api/pin_user_pages.rst     |  12 +-
MAINTAINERS                                   |   2 +
tools/lib/mm/file_utils.c                     |  82 +++
tools/lib/mm/file_utils.h                     |  12 +
.../selftests => lib}/mm/hugepage_settings.c  | 103 ++-
.../selftests => lib}/mm/hugepage_settings.h  |   0
tools/mm/.gitignore                           |   2 +
tools/mm/Makefile                             |  10 +-
tools/mm/gup_bench.c                          | 433 +++++++++++++
tools/testing/selftests/mm/Makefile           |  12 +-
tools/testing/selftests/mm/compaction_test.c  |   2 +-
tools/testing/selftests/mm/cow.c              |   1 -
.../selftests/mm/folio_split_race_test.c      |   1 -
tools/testing/selftests/mm/guard-regions.c    |   1 -
tools/testing/selftests/mm/gup_longterm.c     |   1 -
tools/testing/selftests/mm/gup_test.c         | 606 +++++++++++-------
tools/testing/selftests/mm/hmm-tests.c        |   6 +-
tools/testing/selftests/mm/hugetlb-madvise.c  |   1 -
tools/testing/selftests/mm/hugetlb-mmap.c     |   1 -
tools/testing/selftests/mm/hugetlb-mremap.c   |   1 -
tools/testing/selftests/mm/hugetlb-shm.c      |   1 -
.../selftests/mm/hugetlb-soft-offline.c       |   2 +-
tools/testing/selftests/mm/hugetlb-vmemmap.c  |   1 -
tools/testing/selftests/mm/hugetlb_dio.c      |   1 -
.../selftests/mm/hugetlb_fault_after_madv.c   |   1 -
.../selftests/mm/hugetlb_madv_vs_map.c        |   1 -
tools/testing/selftests/mm/khugepaged.c       |  14 +-
tools/testing/selftests/mm/ksm_tests.c        |   1 -
tools/testing/selftests/mm/migration.c        |   5 +-
tools/testing/selftests/mm/pagemap_ioctl.c    |   1 -
.../testing/selftests/mm/prctl_thp_disable.c  |   1 -
tools/testing/selftests/mm/protection_keys.c  |   2 +-
tools/testing/selftests/mm/run_vmtests.sh     |  37 +-
tools/testing/selftests/mm/soft-dirty.c       |   1 -
.../selftests/mm/split_huge_page_test.c       |   6 +-
tools/testing/selftests/mm/thuge-gen.c        |   1 -
tools/testing/selftests/mm/transhuge-stress.c |   1 -
tools/testing/selftests/mm/uffd-common.h      |   1 -
tools/testing/selftests/mm/uffd-wp-mremap.c   |   2 +-
.../selftests/mm/va_high_addr_switch.c        |   1 -
tools/testing/selftests/mm/vm_util.c          |  82 +--
tools/testing/selftests/mm/vm_util.h          |   7 +-
42 files changed, 1067 insertions(+), 392 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 (89%)
rename tools/{testing/selftests => lib}/mm/hugepage_settings.h (100%)
create mode 100644 tools/mm/gup_bench.c
[PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing
Posted by Sarthak Sharma 1 week, 5 days ago
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 prepares the existing file helpers for sharing, then moves
the common helper code to tools/lib/mm/ so it can be shared by both
selftests and tools/mm.

Patch 1 makes read_file(), write_file(), read_num() and write_num() in
vm_util.c return errors to callers instead of exiting internally. Existing
mm selftest callers are updated to report failures through kselftest
helpers. This avoids carrying selftest-specific process-exit behaviour
into the shared helper implementation moved in the next patch.

Patch 2 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 keeps the helpers exposed to mm
selftests through vm_util.h and adds tools/lib/mm/ to the MEMORY
MANAGEMENT - MISC entry in MAINTAINERS.

Patch 3 moves hugepage_settings.[ch] from selftests/mm to tools/lib/mm/.
It keeps the helper visible to selftests through vm_util.h where
possible, uses direct <mm/hugepage_settings.h> includes for users that do
not include vm_util.h, and removes the remaining kselftest dependency
from the implementation. The existing HugeTLB diagnostic messages are
preserved as TAP-comment-style fprintf(stderr, ...) diagnostics. The
explicit x86 protection_keys 32-bit and 64-bit build rules are also
updated to preserve prerequisite paths after the source move.

Patch 4 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. It also restores HugeTLB settings after each hugetlb benchmark
run and validates numeric command-line arguments instead of relying on
atoi().

Patch 5 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 v4:
- Address review feedback from Mike and Sashiko
- Add a preparatory patch so shared file helpers return errors instead of exiting
- Reduce include churn by keeping shared helpers exposed through vm_util.h
- Preserve HugeTLB diagnostics and restore HugeTLB state more carefully
- Fix selftests/mm build details after moving helpers to tools/lib/mm
- Tighten gup_bench argument handling and gup_test setup/sparse-dump coverage

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:
v3: https://lore.kernel.org/all/20260521111801.173019-1-sarthak.sharma@arm.com/
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 (5):
  selftests/mm: make file helpers return errors
  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                     |  82 +++
 tools/lib/mm/file_utils.h                     |  12 +
 .../selftests => lib}/mm/hugepage_settings.c  | 103 ++-
 .../selftests => lib}/mm/hugepage_settings.h  |   0
 tools/mm/.gitignore                           |   2 +
 tools/mm/Makefile                             |  10 +-
 tools/mm/gup_bench.c                          | 433 +++++++++++++
 tools/testing/selftests/mm/Makefile           |  12 +-
 tools/testing/selftests/mm/compaction_test.c  |   2 +-
 tools/testing/selftests/mm/cow.c              |   1 -
 .../selftests/mm/folio_split_race_test.c      |   1 -
 tools/testing/selftests/mm/guard-regions.c    |   1 -
 tools/testing/selftests/mm/gup_longterm.c     |   1 -
 tools/testing/selftests/mm/gup_test.c         | 606 +++++++++++-------
 tools/testing/selftests/mm/hmm-tests.c        |   6 +-
 tools/testing/selftests/mm/hugetlb-madvise.c  |   1 -
 tools/testing/selftests/mm/hugetlb-mmap.c     |   1 -
 tools/testing/selftests/mm/hugetlb-mremap.c   |   1 -
 tools/testing/selftests/mm/hugetlb-shm.c      |   1 -
 .../selftests/mm/hugetlb-soft-offline.c       |   2 +-
 tools/testing/selftests/mm/hugetlb-vmemmap.c  |   1 -
 tools/testing/selftests/mm/hugetlb_dio.c      |   1 -
 .../selftests/mm/hugetlb_fault_after_madv.c   |   1 -
 .../selftests/mm/hugetlb_madv_vs_map.c        |   1 -
 tools/testing/selftests/mm/khugepaged.c       |  14 +-
 tools/testing/selftests/mm/ksm_tests.c        |   1 -
 tools/testing/selftests/mm/migration.c        |   5 +-
 tools/testing/selftests/mm/pagemap_ioctl.c    |   1 -
 .../testing/selftests/mm/prctl_thp_disable.c  |   1 -
 tools/testing/selftests/mm/protection_keys.c  |   2 +-
 tools/testing/selftests/mm/run_vmtests.sh     |  37 +-
 tools/testing/selftests/mm/soft-dirty.c       |   1 -
 .../selftests/mm/split_huge_page_test.c       |   6 +-
 tools/testing/selftests/mm/thuge-gen.c        |   1 -
 tools/testing/selftests/mm/transhuge-stress.c |   1 -
 tools/testing/selftests/mm/uffd-common.h      |   1 -
 tools/testing/selftests/mm/uffd-wp-mremap.c   |   2 +-
 .../selftests/mm/va_high_addr_switch.c        |   1 -
 tools/testing/selftests/mm/vm_util.c          |  82 +--
 tools/testing/selftests/mm/vm_util.h          |   7 +-
 42 files changed, 1067 insertions(+), 392 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 (89%)
 rename tools/{testing/selftests => lib}/mm/hugepage_settings.h (100%)
 create mode 100644 tools/mm/gup_bench.c


base-commit: da0a06486ac3ce47c6ffb603d2fd332229d41592
--
2.39.5
Re: [PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing
Posted by Andrew Morton 1 week, 4 days ago
On Wed, 27 May 2026 19:54:27 +0530 Sarthak Sharma <sarthak.sharma@arm.com> wrote:

> 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 prepares the existing file helpers for sharing, then moves
> the common helper code to tools/lib/mm/ so it can be shared by both
> selftests and tools/mm.

Thanks.  I'll duck this for now, see what reviewers have to say.

Sashiko still has a couple of nags.  Minor stuff, arguably ignorable.
	https://sashiko.dev/#/patchset/20260527142432.230127-1-sarthak.sharma@arm.com
Re: [PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing
Posted by Sarthak Sharma 1 week, 3 days ago
Hi Andrew!

On 5/28/26 12:17 AM, Andrew Morton wrote:
> On Wed, 27 May 2026 19:54:27 +0530 Sarthak Sharma <sarthak.sharma@arm.com> wrote:
> 
>> 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 prepares the existing file helpers for sharing, then moves
>> the common helper code to tools/lib/mm/ so it can be shared by both
>> selftests and tools/mm.
> 
> Thanks.  I'll duck this for now, see what reviewers have to say.
> 
> Sashiko still has a couple of nags.  Minor stuff, arguably ignorable.
> 	https://sashiko.dev/#/patchset/20260527142432.230127-1-sarthak.sharma@arm.com

Thanks! I went through Sashiko's review.

Both the points are valid but look very minor to me: one is a temporary
x86 build issue fixed by the next patch and the other is stricter
argument validation for -F in gup_bench.

I don't feel they require a v5 on their own. Let's wait for reviewer
feedback. If a respin is needed then I'll fold these cleanups in as well.
Re: [PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing
Posted by John Hubbard 1 week, 2 days ago
On 5/28/26 10:57 PM, Sarthak Sharma wrote:
> On 5/28/26 12:17 AM, Andrew Morton wrote:
>> On Wed, 27 May 2026 19:54:27 +0530 Sarthak Sharma <sarthak.sharma@arm.com> wrote:
...
> Thanks! I went through Sashiko's review.
> 
> Both the points are valid but look very minor to me: one is a temporary
> x86 build issue fixed by the next patch and the other is stricter

This is the sort of claim that an AI will make, in kernel code: "it's
just a temporary build issue". I've seen this happen during sessions
when I'm interrogating an AI about something.

Don't be misled by AI's evaluations, as unless it is guided very
firmly (sashiko for example has fairly firm guidance, although still
a work in progress) it will provide routinely terrible advice about
how to deal with the kernel.

I'm sure we have something in the "how to contribute" docs that
explain that patchsets must be bisectable and that there are no
"minor" build "issues"!

I'd request that you study those docs and the surrounding ones,
it won't take long and it will help immunize you against the
various AI suggestions that seem to be unavoidable problems in
2026.

thanks,
-- 
John Hubbard
Re: [PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing
Posted by Sarthak Sharma 1 week ago
Hi John!

On 5/30/26 1:04 AM, John Hubbard wrote:
> On 5/28/26 10:57 PM, Sarthak Sharma wrote:
>> On 5/28/26 12:17 AM, Andrew Morton wrote:
>>> On Wed, 27 May 2026 19:54:27 +0530 Sarthak Sharma <sarthak.sharma@arm.com> wrote:
> ...
>> Thanks! I went through Sashiko's review.
>>
>> Both the points are valid but look very minor to me: one is a temporary
>> x86 build issue fixed by the next patch and the other is stricter
> 
> This is the sort of claim that an AI will make, in kernel code: "it's
> just a temporary build issue". I've seen this happen during sessions
> when I'm interrogating an AI about something.
> 
> Don't be misled by AI's evaluations, as unless it is guided very
> firmly (sashiko for example has fairly firm guidance, although still
> a work in progress) it will provide routinely terrible advice about
> how to deal with the kernel.
> 
> I'm sure we have something in the "how to contribute" docs that
> explain that patchsets must be bisectable and that there are no
> "minor" build "issues"!
> 
> I'd request that you study those docs and the surrounding ones,
> it won't take long and it will help immunize you against the
> various AI suggestions that seem to be unavoidable problems in
> 2026.
> 
> thanks,

Thanks for the guidance. You're right, I shouldn't have called it a
minor issue just because it was fixed in the next patch.

I have sent a fixup that moves the Makefile hunk from patch 3 to patch
2, so every patch is buildable on its own. If I need to send a v5 after
reviewer feedback, I'll fold this fixup into patch 2 directly.
Re: [PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing
Posted by Dev Jain 1 week, 3 days ago

On 29/05/26 11:27 am, Sarthak Sharma wrote:
> Hi Andrew!
> 
> On 5/28/26 12:17 AM, Andrew Morton wrote:
>> On Wed, 27 May 2026 19:54:27 +0530 Sarthak Sharma <sarthak.sharma@arm.com> wrote:
>>
>>> 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 prepares the existing file helpers for sharing, then moves
>>> the common helper code to tools/lib/mm/ so it can be shared by both
>>> selftests and tools/mm.
>>
>> Thanks.  I'll duck this for now, see what reviewers have to say.
>>
>> Sashiko still has a couple of nags.  Minor stuff, arguably ignorable.
>> 	https://sashiko.dev/#/patchset/20260527142432.230127-1-sarthak.sharma@arm.com
> 
> Thanks! I went through Sashiko's review.
> 
> Both the points are valid but look very minor to me: one is a temporary
> x86 build issue fixed by the next patch and the other is stricter

For the sake of bisection, we try to make patches such that each patch
when applied one by one, does not break the build. Sashiko says that
applying this patch breaks mm-selftests build for x86, so this needs
to be fixed : )

Although if there is no other major review comment, instead of respinning
you could simply reply to this patch with a fix patch and Andrew can
incorporate that : )

> argument validation for -F in gup_bench.

> 
> I don't feel they require a v5 on their own. Let's wait for reviewer
> feedback. If a respin is needed then I'll fold these cleanups in as well.
>
Re: [PATCH v4 0/5] selftests/mm: separate GUP microbenchmarking from functional testing
Posted by Sarthak Sharma 1 week, 3 days ago
Hi Dev!

On 5/29/26 11:36 AM, Dev Jain wrote:
> 
> 
> On 29/05/26 11:27 am, Sarthak Sharma wrote:
>> Hi Andrew!
>>
>> On 5/28/26 12:17 AM, Andrew Morton wrote:
>>> On Wed, 27 May 2026 19:54:27 +0530 Sarthak Sharma <sarthak.sharma@arm.com> wrote:
>>>
>>>> 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 prepares the existing file helpers for sharing, then moves
>>>> the common helper code to tools/lib/mm/ so it can be shared by both
>>>> selftests and tools/mm.
>>>
>>> Thanks.  I'll duck this for now, see what reviewers have to say.
>>>
>>> Sashiko still has a couple of nags.  Minor stuff, arguably ignorable.
>>> 	https://sashiko.dev/#/patchset/20260527142432.230127-1-sarthak.sharma@arm.com
>>
>> Thanks! I went through Sashiko's review.
>>
>> Both the points are valid but look very minor to me: one is a temporary
>> x86 build issue fixed by the next patch and the other is stricter
> 
> For the sake of bisection, we try to make patches such that each patch
> when applied one by one, does not break the build. Sashiko says that
> applying this patch breaks mm-selftests build for x86, so this needs
> to be fixed : )
> 
> Although if there is no other major review comment, instead of respinning
> you could simply reply to this patch with a fix patch and Andrew can
> incorporate that : )

Thanks, that makes sense.

I'll wait for reviewer feedback for now. If no major comment comes in,
I'll send a fix patch to move the x86 Makefile change from patch 3 to
patch 2.

> 
>> argument validation for -F in gup_bench.
> 
>>
>> I don't feel they require a v5 on their own. Let's wait for reviewer
>> feedback. If a respin is needed then I'll fold these cleanups in as well.
>>
>