Skip to contentSkip to conversation

mm: vmstat_kunit: add synthetic benchmark for mm stats

PATCH Superseded David Rientjes 2 participants 3 messages Oct 9 – Oct 20

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 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

Assisted-by Gemini:gemini-3.8-flash

---
v5:
- added dependency on CONFIG_VM_EVENT_COUNTERS
- expanded commit description

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
index f53047aa8d3c..ab65720521a5 100644
@@ -17164,6 +17164,7 @@ F:	mm/ptdump.c
 F:	mm/sparse-vmemmap.c
 F:	mm/sparse.c
 F:	mm/sparse.h
+F:	mm/tests/vmstat_kunit.c
 F:	mm/util.c
 F:	mm/vmpressure.c
 F:	mm/vmstat.c
mm/Kconfig +12 -0
index 604c58199acb..85817820f867 100644
@@ -1511,6 +1511,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.
+
 source "mm/damon/Kconfig"
 
 endmenu
mm/Makefile +1 -0
index e7245cb88c66..3d4f2c43b8d3 100644
@@ -147,4 +147,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

#1 lore raw
Quoted 39 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_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

Assisted-by Gemini:gemini-3.8-flash
Quoted 8 lines

---
v5:
- added dependency on CONFIG_VM_EVENT_COUNTERS
- expanded commit description

Once we're happy with this change, I'll apply the same treatment to the proposed pgalloc and slab tests.

I've added the rationale for the change to the commit description as primairly being used by developers to benchmark and monitor any regressions in functions that are known to be super hot and impact workload performance.

This is the simplest of the three tests that Christoph provided back in 2009, the others are pgalloc and slab tests, see
https://marc.info/?l=linux-mm&m=178547194364290 and
https://marc.info/?l=linux-mm&m=178547193264283 for those. Based on the feedback to move to kunit, I forked this one off independently because it was the simplest to address all the feedback and pave the way for the other two to be upstreamed afterwards.

Is this acceptable for merge? If we're happy with this, I'll move onto the pgalloc and slab variants.

#2 lore raw
Quoted 63 lines · David Rientjes
Quoted 39 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_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

Assisted-by Gemini:gemini-3.8-flash
Quoted 8 lines

---
v5:
- added dependency on CONFIG_VM_EVENT_COUNTERS
- expanded commit description

Once we're happy with this change, I'll apply the same treatment to the proposed pgalloc and slab tests.

I've added the rationale for the change to the commit description as primairly being used by developers to benchmark and monitor any regressions in functions that are known to be super hot and impact workload performance.

This is the simplest of the three tests that Christoph provided back in 2009, the others are pgalloc and slab tests, see
https://marc.info/?l=linux-mm&m=178547194364290 and
https://marc.info/?l=linux-mm&m=178547193264283 for those. Based on the feedback to move to kunit, I forked this one off independently because it was the simplest to address all the feedback and pave the way for the other two to be upstreamed afterwards.

Quoted 2 lines

Is this acceptable for merge? If we're happy with this, I'll move onto the pgalloc and slab variants.

Works for me. The tests are rather small and I see value in them.

Signature · 3 lines
Cheers,

David