Skip to contentSkip to conversation

selftests/mm: move the HMM migration benchmark out of selftests

PATCH Superseded Balbir Singh 3 participants 4 messages Nov 26

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/mm: move the HMM migration benchmark out of selftests

The HMM selftest runs benchmark_thp_migration on every invocation. The benchmark repeatedly migrates buffers in both directions to measure latency and throughput with and without THP. Run it on demand so the regular suite spends its time checking correctness.

Move the benchmark into its own hmm-bench binary and share the device fixture, buffer helpers and migration ioctls with hmm-tests. To run it:

make -C tools/testing/performance-tests/mm sudo modprobe test_hmm
sudo tools/testing/performance-tests/mm/hmm-bench

Drop the 128-PMD buffer to bound the amount of memory migrated in one measurement. With 2 MiB PMDs, the largest buffer falls from 256 MiB to 16 MiB. The remaining sizes still cover buffers smaller than a PMD, a single PMD and multiple PMDs, with and without MADV_HUGEPAGE.

Call fflush(stdout) after printing the results for each buffer size. The kselftest harness ends the test child with _exit(0), so timing results still buffered in stdout can be lost when output is redirected to a file or pipe.

Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Shuah Khan <[email protected]>

---
On mm-everything-2026-11-24-10-33, hmm.hmm_device_private.migrate_fault fails with -ENOENT on the second migration to the device. I reproduced this in QEMU with the selftest binaries built before and after this patch. In the same guest, both binaries pass with test_hmm built from the parent of 5cbbd205947d ("lib/test_hmm: invalidate all mirrors on device-private migration") and both fail with test_hmm from that commit.

 MAINTAINERS                                   |   1 +
 tools/testing/performance-tests/mm/.gitignore |   1 +
 tools/testing/performance-tests/mm/Makefile   |  13 +
 .../testing/performance-tests/mm/hmm-bench.c  | 191 +++++++++
 tools/testing/selftests/mm/Makefile           |   1 +
 tools/testing/selftests/mm/hmm-common.h       | 202 +++++++++
 tools/testing/selftests/mm/hmm-tests.c        | 384 +-----------------
 7 files changed, 410 insertions(+), 383 deletions(-)
 create mode 100644 tools/testing/performance-tests/mm/.gitignore
 create mode 100644 tools/testing/performance-tests/mm/Makefile
 create mode 100644 tools/testing/performance-tests/mm/hmm-bench.c
 create mode 100644 tools/testing/selftests/mm/hmm-common.h
MAINTAINERS +1 -0
index 8a3548854767..e97699c6f90b 100644
@@ -12218,6 +12218,7 @@ F:	Documentation/mm/hmm.rst
 F:	include/linux/hmm*
 F:	lib/test_hmm*
 F:	mm/hmm*
+F:	tools/testing/performance-tests/mm/*hmm*
 F:	tools/testing/selftests/mm/*hmm*
 
 HONEYWELL ABP2030PA PRESSURE SENSOR SERIES IIO DRIVER
tools/testing/performance-tests/mm/.gitignore new file +1 -0
new file mode 100644
index 000000000000..d4cc8960680c
@@ -0,0 +1 @@
+/hmm-bench
tools/testing/performance-tests/mm/Makefile new file +13 -0
new file mode 100644
index 000000000000..03a133f4bd28
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_GEN_PROGS := hmm-bench
+
+CFLAGS += -Wall -O2 -I$(top_srcdir) -I$(top_srcdir)/tools/lib
+CFLAGS += $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
+LOCAL_HDRS += $(selfdir)/mm/hmm-common.h $(selfdir)/mm/vm_util.h
+LOCAL_HDRS += $(top_srcdir)/lib/test_hmm_uapi.h
+
+include ../../selftests/lib.mk
+
+$(OUTPUT)/hmm-bench: $(selfdir)/mm/vm_util.c \
+		     $(top_srcdir)/tools/lib/mm/hugepage_settings.c \
+		     $(top_srcdir)/tools/lib/mm/file_utils.c
tools/testing/performance-tests/mm/hmm-bench.c new file +191 -0

191 lines not on this page · raw message

tools/testing/selftests/mm/Makefile +1 -0
index 675ec57d47de..c129ac2c635a 100644
@@ -6,6 +6,7 @@
 # If you do not YOUR TESTS WILL NOT RUN IN THE CI.
 
 LOCAL_HDRS += $(selfdir)/mm/local_config.h_gen $(top_srcdir)/mm/gup_test.h
+LOCAL_HDRS += $(selfdir)/mm/hmm-common.h
 LOCAL_HDRS += $(selfdir)/mm/mseal_helpers.h
 
 include local_config.mk
tools/testing/selftests/mm/hmm-common.h new file +202 -0

202 lines not on this page · raw message

tools/testing/selftests/mm/hmm-tests.c +1 -383

441 lines not on this page · raw message

Signature · 1 line
2.56.0
#1 lore raw
Quoted 17 lines · Balbir Singh

The HMM selftest runs benchmark_thp_migration on every invocation. The benchmark repeatedly migrates buffers in both directions to measure latency and throughput with and without THP. Run it on demand so the regular suite spends its time checking correctness.

Move the benchmark into its own hmm-bench binary and share the device fixture, buffer helpers and migration ioctls with hmm-tests. To run it:

make -C tools/testing/performance-tests/mm sudo modprobe test_hmm
sudo tools/testing/performance-tests/mm/hmm-bench

Drop the 128-PMD buffer to bound the amount of memory migrated in one measurement. With 2 MiB PMDs, the largest buffer falls from 256 MiB to 16 MiB. The remaining sizes still cover buffers smaller than a PMD, a single PMD and multiple PMDs, with and without MADV_HUGEPAGE.

Quoted 4 lines

Call fflush(stdout) after printing the results for each buffer size. The kselftest harness ends the test child with _exit(0), so timing results still buffered in stdout can be lost when output is redirected to a file or pipe.

There was recently a discussion on where to put performance tests. Usually it's much rather tools to test performance.

So what about tools/mm/ instead, where we also placed gup_bench.c ?

Signature · 3 lines
Cheers,

David
#2 lore raw
Quoted 18 lines · David Hildenbrand (Arm)
Quoted 17 lines · Balbir Singh

The HMM selftest runs benchmark_thp_migration on every invocation. The benchmark repeatedly migrates buffers in both directions to measure latency and throughput with and without THP. Run it on demand so the regular suite spends its time checking correctness.

Move the benchmark into its own hmm-bench binary and share the device fixture, buffer helpers and migration ioctls with hmm-tests. To run it:

make -C tools/testing/performance-tests/mm sudo modprobe test_hmm
sudo tools/testing/performance-tests/mm/hmm-bench

Drop the 128-PMD buffer to bound the amount of memory migrated in one measurement. With 2 MiB PMDs, the largest buffer falls from 256 MiB to 16 MiB. The remaining sizes still cover buffers smaller than a PMD, a single PMD and multiple PMDs, with and without MADV_HUGEPAGE.

Quoted 13 lines
Quoted 4 lines

Call fflush(stdout) after printing the results for each buffer size. The kselftest harness ends the test child with _exit(0), so timing results still buffered in stdout can be lost when output is redirected to a file or pipe.

There was recently a discussion on where to put performance tests. Usually it's much rather tools to test performance.

So what about tools/mm/ instead, where we also placed gup_bench.c ?

Signature · 3 lines
Cheers,

David

I don't feel strongly about the location, happy to put it where it can be found and run. My motivation to put it where I did was to easily reuse lib.mk and hmm-common.h and other mm helpers from the test case (due to the dependence between the tests and benchmark). Let me refactor and see if I can find a good way of reusing bits and see how it looks like when I move it out to tools/mm

Thanks,
Balbir

#3 lore raw
In reply to David Hildenbrand (Arm)
Quoted 18 lines · David Hildenbrand (Arm)
Quoted 17 lines · Balbir Singh

The HMM selftest runs benchmark_thp_migration on every invocation. The benchmark repeatedly migrates buffers in both directions to measure latency and throughput with and without THP. Run it on demand so the regular suite spends its time checking correctness.

Move the benchmark into its own hmm-bench binary and share the device fixture, buffer helpers and migration ioctls with hmm-tests. To run it:

make -C tools/testing/performance-tests/mm sudo modprobe test_hmm
sudo tools/testing/performance-tests/mm/hmm-bench

Drop the 128-PMD buffer to bound the amount of memory migrated in one measurement. With 2 MiB PMDs, the largest buffer falls from 256 MiB to 16 MiB. The remaining sizes still cover buffers smaller than a PMD, a single PMD and multiple PMDs, with and without MADV_HUGEPAGE.

Quoted 9 lines
Quoted 4 lines

Call fflush(stdout) after printing the results for each buffer size. The kselftest harness ends the test child with _exit(0), so timing results still buffered in stdout can be lost when output is redirected to a file or pipe.

There was recently a discussion on where to put performance tests. Usually it's much rather tools to test performance.

So what about tools/mm/ instead, where we also placed gup_bench.c ?

The slimmed down test runs very quickly and with less memory pressure already, so maybe not a big issue keeping that in hmm-tests either, i see the value of having all HMM tests in one test. But tools/mm sounds a logical place if want to separate tests.

--Mika