mm: vmstat_kunit: add synthetic benchmark for mm stats
Subsystems (2)
PATCH v6 1/1 mm: vmstat_kunit: add synthetic benchmark for mm stats
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of MM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
This is the first of three tests that measure the execution times of critical MM functions anticipated to be used by developers to measure the impact of any core changes that would end up causing workload performance issues. Vmstats are embedded into MM hotpaths, so any regression can cause performance and scalability impact for users. Google has carried these tests internally and kept them updated since Christoph posted them back in 2009 for this purpose.
This can also be used to detect regressions over time, from kernel version to kernel version, independent of development use cases.
The test is run by KUnit or doing modprobe vmstat_kunit directly.
Sample output:
KTAP version 1
1..1
KTAP version 1
# Subtest: vmstat
# module: vmstat_kunit
1..3
# vmstat_test_inc_dec_zone_page_state: 10000 ops: inc_zone_page_state -> 8 cycles (4 ns/op), dec_zone_page_state -> 9 cycles (4 ns/op)
ok 1 vmstat_test_inc_dec_zone_page_state
# vmstat_test_interleaved_zone_page_state: 10000 ops: inc/dec pair -> 17 cycles (8 ns/op)
ok 2 vmstat_test_interleaved_zone_page_state
# vmstat_test_count_vm_event: 10000 ops: count_vm_event -> 4 cycles (2 ns/op)
ok 3 vmstat_test_count_vm_event # vmstat: pass:3 fail:0 skip:0 total:3
# Totals: pass:3 fail:0 skip:0 total:3
ok 1 vmstat
---
v6:
- rebase on top of 7.4-rc1
- resend per akpm
DavidH said "Works for me. The tests are rather small and I see value in them." and I was this >< close to infering that as his Acked-by, but will leave it to him to do that explicitly.
Once we're happy with this change, I'll apply the same treatment to the proposed pgalloc and slab tests.
MAINTAINERS | 1 + mm/Kconfig | 12 +++ mm/Makefile | 1 + mm/tests/vmstat_kunit.c | 157 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 mm/tests/vmstat_kunit.c
MAINTAINERS +1 -0
@@ -17551,6 +17551,7 @@ F: mm/mmzone.c F: mm/pagewalk.c F: mm/pgtable-generic.c F: mm/ptdump.c +F: mm/tests/vmstat_kunit.c F: mm/util.c F: mm/vmpressure.c F: mm/vmstat.c
mm/Kconfig +12 -0
@@ -1490,6 +1490,18 @@ config LAZY_MMU_MODE_KUNIT_TEST If unsure, say N. +config VMSTAT_KUNIT_TEST + tristate "KUnit test for VM statistics" if !KUNIT_ALL_TESTS + depends on VM_EVENT_COUNTERS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test and benchmark the performance of VM + statistics updates (zone page state and VM event counters), which + are used frequently in hot memory management code paths. + + If unsure, say N. + config ARCH_HAS_CHECK_WX bool
mm/Makefile +1 -0
@@ -148,4 +148,5 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_VMSTAT_KUNIT_TEST) += tests/vmstat_kunit.o obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
mm/tests/vmstat_kunit.c new file +157 -0
157 lines not on this page · raw message
Quoted 3 lines · David Rientjes
cause performance and scalability impact for users. Google has carried these tests internally and kept them updated since Christoph posted them back in 2009 for this purpose.
Thank you. I have a couple of more for atomics, slab, tlbs etc that have evolved over time and gathered specifics for the variuos platforms being benchmarked and the issues that it was used to track down. I can dump that stuff somehwere if there is an interest.
+ mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats.patch added to mm-unstable branch
In reply to David RientjesThe patch titled Subject: mm: vmstat_kunit: add synthetic benchmark for mm stats has been added to the -mm mm-unstable branch. Its filename is…
The patch titled
Subject: mm: vmstat_kunit: add synthetic benchmark for mm stats
has been added to the -mm mm-unstable branch. Its filename is
mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Christoph Lameter <[email protected]>
Subject: mm: vmstat_kunit: add synthetic benchmark for mm stats
Date: Wed, 04 Nov 2026 17:53:29 -0800
Add a synthetic benchmark that can be used to measure performance of MM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
This is the first of three tests that measure the execution times of critical MM functions anticipated to be used by developers to measure the impact of any core changes that would end up causing workload performance issues. Vmstats are embedded into MM hotpaths, so any regression can cause performance and scalability impact for users. Google has carried these tests internally and kept them updated since Christoph posted them back in 2009 for this purpose.
This can also be used to detect regressions over time, from kernel version to kernel version, independent of development use cases.
The test is run by KUnit or doing modprobe vmstat_kunit directly.
Sample output:
KTAP version 1
1..1
KTAP version 1
# Subtest: vmstat
# module: vmstat_kunit
1..3
# vmstat_test_inc_dec_zone_page_state: 10000 ops: inc_zone_page_state -> 8 cycles (4 ns/op), dec_zone_page_state -> 9 cycles (4 ns/op)
ok 1 vmstat_test_inc_dec_zone_page_state
# vmstat_test_interleaved_zone_page_state: 10000 ops: inc/dec pair -> 17 cycles (8 ns/op)
ok 2 vmstat_test_interleaved_zone_page_state
# vmstat_test_count_vm_event: 10000 ops: count_vm_event -> 4 cycles (2 ns/op)
ok 3 vmstat_test_count_vm_event # vmstat: pass:3 fail:0 skip:0 total:3
# Totals: pass:3 fail:0 skip:0 total:3
ok 1 vmstat
MAINTAINERS | 1 mm/Kconfig | 12 ++ mm/Makefile | 1 mm/tests/vmstat_kunit.c | 157 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+)
MAINTAINERS renamed from MAINTAINERS~mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats +1 -0
@@ -17556,6 +17556,7 @@ F: mm/mmzone.c F: mm/pagewalk.c F: mm/pgtable-generic.c F: mm/ptdump.c +F: mm/tests/vmstat_kunit.c F: mm/util.c F: mm/vmpressure.c F: mm/vmstat.c
mm/Kconfig renamed from mm/Kconfig~mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats +12 -0
@@ -1482,6 +1482,18 @@ config LAZY_MMU_MODE_KUNIT_TEST If unsure, say N. +config VMSTAT_KUNIT_TEST + tristate "KUnit test for VM statistics" if !KUNIT_ALL_TESTS + depends on VM_EVENT_COUNTERS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test and benchmark the performance of VM + statistics updates (zone page state and VM event counters), which + are used frequently in hot memory management code paths. + + If unsure, say N. + config ARCH_HAS_CHECK_WX bool
mm/Makefile renamed from mm/Makefile~mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats +1 -0
@@ -149,4 +149,5 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_VMSTAT_KUNIT_TEST) += tests/vmstat_kunit.o obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
mm/tests/vmstat_kunit.c new file +157 -0
157 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are
mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats.patch
Quoted 32 lines · David Rientjes
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of MM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
This is the first of three tests that measure the execution times of critical MM functions anticipated to be used by developers to measure the impact of any core changes that would end up causing workload performance issues. Vmstats are embedded into MM hotpaths, so any regression can cause performance and scalability impact for users. Google has carried these tests internally and kept them updated since Christoph posted them back in 2009 for this purpose.
This can also be used to detect regressions over time, from kernel version to kernel version, independent of development use cases.
The test is run by KUnit or doing modprobe
vmstat_kunitdirectly.Sample output:
KTAP version 1
1..1
KTAP version 1
# Subtest: vmstat
# module:vmstat_kunit1..3 # vmstat_test_inc_dec_zone_page_state: 10000 ops: inc_zone_page_state -> 8 cycles (4 ns/op), dec_zone_page_state -> 9 cycles (4 ns/op) ok 1 vmstat_test_inc_dec_zone_page_state # vmstat_test_interleaved_zone_page_state: 10000 ops: inc/dec pair -> 17 cycles (8 ns/op) ok 2 vmstat_test_interleaved_zone_page_state # vmstat_test_count_vm_event: 10000 ops: count_vm_event -> 4 cycles (2 ns/op) ok 3 vmstat_test_count_vm_event
Quoted 7 lines
# vmstat: pass:3 fail:0 skip:0 total:3
# Totals: pass:3 fail:0 skip:0 total:3
ok 1 vmstatAssisted-by Gemini:gemini-3.8-flashSigned-off-by Christoph Lameter <[email protected]>Signed-off-by David Rientjes <[email protected]>
Thanks!
@Andrew, can you do the honors and queue this?
Signature · 3 lines
Cheers, David
+ mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats-fix.patch added to mm-unstable branch
In reply to David RientjesThe patch titled Subject: mm/vmstat_kunit: avoid sparse warning in vm event cleanup has been added to the -mm mm-unstable branch. Its filename is…
The patch titled
Subject: mm/vmstat_kunit: avoid sparse warning in vm event cleanup
has been added to the -mm mm-unstable branch. Its filename is
mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats-fix.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats-fix.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Andrew Morton <[email protected]>
Subject: mm/vmstat_kunit: avoid sparse warning in vm event cleanup
Date: Sun, 22 Nov 2026 18:51:40 -0800
Sparse warns about -TEST_COUNT in an unreachable 1-byte arm64 per-CPU case; the actual counter is 8 bytes. Pass the completed loop count instead to silence the warning, with no behavior change.
mm/tests/vmstat_kunit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/tests/vmstat_kunit.c renamed from mm/tests/vmstat_kunit.c~mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats-fix +2 -2
@@ -107,7 +107,7 @@ static void vmstat_test_interleaved_zone/* * Test 3: count_vm_event() benchmark. -* Restores counter balance with count_vm_events(item, -TEST_COUNT). +* Restores counter balance after measurement. */ static void vmstat_test_count_vm_event (struct kunit *test) {
@@ -124,7 +124,7 @@ static void vmstat_test_count_vm_event(s time2 =get_cycles ();/* Restore balance */ -count_vm_events (SLABS_SCANNED , -TEST_COUNT ); +count_vm_events (SLABS_SCANNED , -(long )i); time = time2 - time1; avg_cycles =div_u64 (time,TEST_COUNT );
_
Patches currently in -mm which might be from [email protected] are
maintainers-add-page_exth-to-memory-management-page-allocator.patch kselftest-mm-rename-read_pmd_pagesize-to-pmd_psize-fix.patch selftests-mm-check-madv_cold-and-madv_pageout-on-partly-advised-thps-fix.patch alloc_tag-introduce-ioctls-to-toggle-allocation-tracepoints-fix-fix.patch alloc_tag-introduce-ioctls-to-toggle-allocation-tracepoints-fix.patch selftests-mm-add-uffdio_move-huge-zeropage-pmd-regression-test-fix.patch selftests-mm-allocate-nr_pages-based-on-pmd-size-for-uffd-pmd_move-tests-fix.patch selftests-mm-retain-move-pmd-coverage-and-verify-huge-pmds.patch lib-test_xarray-check-unused-spare-node-after-range-creation.patch mm-memory-failure-dont-unpoison-a-leaked-raw_hwp_unreliable-folio-fix.patch mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats-fix.patch lib-test_hmm-invalidate-all-mirrors-on-device-private-migration.patch lib-test_hmm-invalidate-all-mirrors-on-device-private-migration-fix.patch mm-prevent-pre-content-bypass-through-mremap-and-remap_file_pages.patch selinux-recheck-backing-file-permissions-on-remap_file_pages.patch mm-madvise-notify-userfaultfd-when-installing-guard-regions.patch mm-highmem-reject-previously-poisoned-pages-in-machine-check-copies.patch selftests-mm-check-that-fsync-reports-hard-poisoned-dirty-page-cache.patch fuse-let-memory-failure-remove-poisoned-page-cache-folios.patch nilfs2-report-mapping-errors-from-fsync.patch ocfs2-unregister-the-jbd2-shrinker-before-journal-shutdown.patch ipc-msg-clamp-negative-msg_info-usage-counts.patch squashfs-fix-leaked-page-locks-when-page-actor-allocation-fails-fix.patch squashfs-sanity-check-directory-metadata-block-location-fix.patch squashfs-fix-variables-in-directory-code-and-add-more-sanity-checks-fix.patch ocfs2-skip-network-flush-when-no-domain-handlers-are-registered.patch selftests-ptrace-check-that-ptrace_set_syscall_info-rejects-invalid-error-values-fix.patch jfs-validate-xattr-entry-bounds-before-replacing-an-attribute.patch drivers-media-v4l2-core-v4l2-vp9c-reduce-inlining.patch