lib: add synthetic MM benchmarks
Subsystems (4)
cover lib: add synthetic MM benchmarks
A blast to the past :)
We've been carrying these synthetic benchmarks in our kernel tree since 2009 because they've been helpful to identify regressions in hot paths, as well as quantifying any improvements that have been made for new changes. Hopefully they can be useful to others as well.
The synthetic benchmarks are run by loading the module at runtime. The modprobe will fail intentionally so that the module gets insta-unloaded. The test results are emitted to the kernel log.
Proposed with permission from Christoph.
--- lib/Kconfig.debug | 30 ++++ lib/Makefile | 3 + lib/test_pagealloc.c | 337 ++++++++++++++++++++++++++++++++++++++ lib/test_slab.c | 375 +++++++++++++++++++++++++++++++++++++++++++ lib/test_vmstat.c | 95 +++++++++++ 5 files changed, 840 insertions(+) create mode 100644 lib/test_pagealloc.c create mode 100644 lib/test_slab.c create mode 100644 lib/test_vmstat.c
PATCH 1/3 lib: test_vmstat: add synthetic benchmark for vm stats
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of VM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
The test is run by inserting the module: modprobe test_vmstat The module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.
--- lib/Kconfig.debug | 10 +++++ lib/Makefile | 1 + lib/test_vmstat.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 lib/test_vmstat.c
lib/Kconfig.debug +10 -0
@@ -3427,6 +3427,16 @@ config TEST_KEXEC_HANDOVER If unsure, say N. +config TEST_VMSTAT + tristate "VM Statistics Benchmark" + default n + help + A synthetic benchmark measuring the performance of VM statistics, + useful to analyze any improvements or regressions in functions that + are frequently used in hot code paths. + + If unsure, say N. + config RATELIMIT_KUNIT_TEST tristate "KUnit Test for correctness and stress of ratelimit" if !KUNIT_ALL_TESTS depends on KUNIT
lib/Makefile +1 -0
@@ -105,6 +105,7 @@ obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o obj-$(CONFIG_TEST_KEXEC_HANDOVER) += test_kho.o +obj-$(CONFIG_TEST_VMSTAT) += test_vmstat.o obj-$(CONFIG_TEST_FPU) += test_fpu.o test_fpu-y := test_fpu_glue.o test_fpu_impl.o
lib/test_vmstat.c new file +95 -0
95 lines not on this page · raw message
Re: [patch 1/3] lib: test_vmstat: add synthetic benchmark for vm stats
Quoted 77 lines · On Thu, 30 Jul 2026 21:26:23 -0700 (PDT) David Rientjes <[email protected]>…
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of VM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
The test is run by inserting the module: modprobe
test_vmstatThe module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.Signed-off-by Christoph Lameter <[email protected]>Signed-off-by David Rientjes <[email protected]>--- lib/Kconfig.debug | 10 +++++ lib/Makefile | 1 + lib/test_vmstat.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 lib/test_vmstat.clib/Kconfig.debug +10
-0@@ -3427,6 +3427,16 @@ config TEST_KEXEC_HANDOVER If unsure, say N. +config TEST_VMSTAT + tristate "VM Statistics Benchmark" + default n + help + A synthetic benchmark measuring the performance of VM statistics, + useful to analyze any improvements or regressions in functions that + are frequently used in hot code paths. + + If unsure, say N. + config RATELIMIT_KUNIT_TEST tristate "KUnit Test for correctness and stress of ratelimit" if !KUNIT_ALL_TESTS depends on KUNITlib/Makefile +1
-0@@ -105,6 +105,7 @@ obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o obj-$(CONFIG_TEST_KEXEC_HANDOVER) += test_kho.o +obj-$(CONFIG_TEST_VMSTAT) += test_vmstat.o obj-$(CONFIG_TEST_FPU) += test_fpu.o test_fpu-y := test_fpu_glue.o test_fpu_impl.olib/test_vmstat.c new file +19
-0@@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Test module for in-kernel synthetic vm statistics performance. +* +* execute +* +* modprobe test_vmstat +* +* to run this test +* +* (C) 2009 Linux Foundation, Christoph Lameter <[email protected]> +*/ + +#include <linux/jiffies.h> +#include <linux/compiler.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/mm.h> +#include <asm/timex.h>
lib/test_vmstat.c line 29
Quoted 10 lines
lib/test_vmstat.c new file +10
-0+ +#define TEST_COUNT 10000 + +static int vmstat_test_init (void ) +{ +unsigned int i; +cycles_t time1, time2, time; +int rem; +struct page *page =alloc_page (GFP_KERNEL ); +
Good to check page != NULL before using it below.
Quoted 7 lines
lib/test_vmstat.c new file +7
-0+pr_alert ("VMstat testing\n" ); +pr_alert ("=====================\n" ); +pr_alert ("1. inc_zone_page_state() then dec_zone_page_state()\n" ); + time1 =get_cycles (); +for (i =0 ; i <TEST_COUNT ; i++) +inc_zone_page_state (page,NR_FREE_CMA_PAGES ); +
lib/test_vmstat.c line 46
Quoted 10 lines
lib/test_vmstat.c new file +10
-0+ time2 =get_cycles (); + time = time2 - time1; + +pr_alert ("%i times inc_zone_page_state() " , i); + time =div_u64_rem (time,TEST_COUNT , &rem); +pr_cont ("-> %llu cycles " , (unsigned long long ) time); + + time1 =get_cycles (); +for (i =0 ; i <TEST_COUNT ; i++) +__dec_zone_page_state (page,NR_FREE_CMA_PAGES );
Why use inc_zone_page_state() but the __ variant for decrement?
Checking the 2 functions, __dec_zone_page_state() might cause problems if preemption is enabled?
Quoted 51 lines
lib/test_vmstat.c new file +49
-0+ + time2 =get_cycles (); + time = time2 - time1; + +pr_cont ("__dec_z_p_s() " ); + time =div_u64_rem (time,TEST_COUNT , &rem); +pr_cont ("-> %llu cycles\n" , (unsigned long long ) time); + +pr_alert ("2. inc_zone_page_state()/dec_zone_page_state()\n" ); + time1 =get_cycles (); +for (i =0 ; i <TEST_COUNT ; i++) { +inc_zone_page_state (page,NR_FREE_CMA_PAGES ); +dec_zone_page_state (page,NR_FREE_CMA_PAGES ); + } + + time2 =get_cycles (); + time = time2 - time1; + +pr_alert ("%i times inc/dec " , i); + time =div_u64_rem (time,TEST_COUNT , &rem); +pr_cont ("-> %llu cycles\n" , (unsigned long long ) time); + +pr_alert ("3. count_vm_event()\n" ); + time1 =get_cycles (); +for (i =0 ; i <TEST_COUNT ; i++) +count_vm_event (SLABS_SCANNED ); + + time2 =get_cycles (); + time = time2 - time1; + +count_vm_events (SLABS_SCANNED , -TEST_COUNT ); +pr_alert ("%i count_vm_events " , i); + time =div_u64_rem (time,TEST_COUNT , &rem); +pr_cont ("-> %llu cycles\n" , (unsigned long long ) time); +__free_page (page); +return -EAGAIN ;/* Fail will directly unload the module */ +} + +static void vmstat_test_exit (void ) +{ +pr_alert ("test exit\n" ); +} + +module_init(vmstat_test_init) +module_exit(vmstat_test_exit) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Christoph Lameter"); +MODULE_DESCRIPTION("VM statistics test");
Re: [patch 1/3] lib: test_vmstat: add synthetic benchmark for vm stats
Quoted 58 lines · Usama Arif
Quoted 25 lines
lib/test_vmstat.c new file +19
-0@@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Test module for in-kernel synthetic vm statistics performance. +* +* execute +* +* modprobe test_vmstat +* +* to run this test +* +* (C) 2009 Linux Foundation, Christoph Lameter <[email protected]> +*/ + +#include <linux/jiffies.h> +#include <linux/compiler.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/mm.h> +#include <asm/timex.h> lib/test_vmstat.c line 29
Quoted 10 lines
lib/test_vmstat.c new file +10
-0+ +#define TEST_COUNT 10000 + +static int vmstat_test_init (void ) +{ +unsigned int i; +cycles_t time1, time2, time; +int rem; +struct page *page =alloc_page (GFP_KERNEL ); +Good to check page != NULL before using it below.
Quoted 7 lines
lib/test_vmstat.c new file +7
-0+pr_alert ("VMstat testing\n" ); +pr_alert ("=====================\n" ); +pr_alert ("1. inc_zone_page_state() then dec_zone_page_state()\n" ); + time1 =get_cycles (); +for (i =0 ; i <TEST_COUNT ; i++) +inc_zone_page_state (page,NR_FREE_CMA_PAGES ); +lib/test_vmstat.c line 46
Quoted 10 lines
lib/test_vmstat.c new file +10
-0+ time2 =get_cycles (); + time = time2 - time1; + +pr_alert ("%i times inc_zone_page_state() " , i); + time =div_u64_rem (time,TEST_COUNT , &rem); +pr_cont ("-> %llu cycles " , (unsigned long long ) time); + + time1 =get_cycles (); +for (i =0 ; i <TEST_COUNT ; i++) +__dec_zone_page_state (page,NR_FREE_CMA_PAGES );Why use
inc_zone_page_state()but the __ variant for decrement?
Quoted 3 lines
Checking the 2 functions,
__dec_zone_page_state()might cause problems if preemption is enabled?
Fixed both, thanks!
PATCH v2 1/1 lib: test_vmstat: add synthetic benchmark for vm stats
In reply to David RientjesFrom: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of VM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
The test is run by inserting the module: modprobe test_vmstat The module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.
---
v2:
- added bash wrapper to ksft per David
- integrated into ksft
- added MAINTAINERS entry per David
- fixed alloc_page() error code per Usama
Adding single test for now to solicit feedback before updating the other two.
MAINTAINERS | 1 + lib/Kconfig.debug | 10 +++ lib/Makefile | 1 + lib/test_vmstat.c | 100 ++++++++++++++++++++++ tools/testing/selftests/mm/Makefile | 2 + tools/testing/selftests/mm/config | 1 + tools/testing/selftests/mm/ksft_vmstat.sh | 4 + tools/testing/selftests/mm/run_vmtests.sh | 5 ++ tools/testing/selftests/mm/test_vmstat.sh | 71 +++++++++++++++ 9 files changed, 195 insertions(+) create mode 100644 lib/test_vmstat.c create mode 100755 tools/testing/selftests/mm/ksft_vmstat.sh create mode 100755 tools/testing/selftests/mm/test_vmstat.sh
MAINTAINERS +1 -0
@@ -17004,6 +17004,7 @@ F: mm/sparse.c F: mm/util.c F: mm/vmpressure.c F: mm/vmstat.c +F: lib/test_vmstat.c N: include\/linux\/page[-_][a-zA-Z]* MEMORY MANAGEMENT - EXECMEM
lib/Kconfig.debug +10 -0
@@ -3427,6 +3427,16 @@ config TEST_KEXEC_HANDOVER If unsure, say N. +config TEST_VMSTAT + tristate "VM Statistics Benchmark" + default n + help + A synthetic benchmark measuring the performance of VM statistics, + useful to analyze any improvements or regressions in functions that + are frequently used in hot code paths. + + If unsure, say N. + config RATELIMIT_KUNIT_TEST tristate "KUnit Test for correctness and stress of ratelimit" if !KUNIT_ALL_TESTS depends on KUNIT
lib/Makefile +1 -0
@@ -105,6 +105,7 @@ obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o obj-$(CONFIG_TEST_KEXEC_HANDOVER) += test_kho.o +obj-$(CONFIG_TEST_VMSTAT) += test_vmstat.o obj-$(CONFIG_TEST_FPU) += test_fpu.o test_fpu-y := test_fpu_glue.o test_fpu_impl.o
lib/test_vmstat.c new file +100 -0
100 lines not on this page · raw message
tools/testing/selftests/mm/Makefile +2 -0
@@ -173,8 +173,10 @@ TEST_PROGS += ksft_thp.sh TEST_PROGS += ksft_userfaultfd.sh TEST_PROGS += ksft_vma_merge.sh TEST_PROGS += ksft_vmalloc.sh +TEST_PROGS += ksft_vmstat.sh TEST_FILES := test_vmalloc.sh +TEST_FILES := test_vmstat.sh TEST_FILES += test_hmm.sh TEST_FILES += va_high_addr_switch.sh TEST_FILES += charge_reserved_hugetlb.sh
tools/testing/selftests/mm/config +1 -0
@@ -2,6 +2,7 @@ CONFIG_SYSVIPC=y CONFIG_USERFAULTFD=y CONFIG_PTE_MARKER_UFFD_WP=y CONFIG_TEST_VMALLOC=m +CONFIG_TEST_VMSTAT=m CONFIG_DEVICE_PRIVATE=y CONFIG_TEST_HMM=m CONFIG_GUP_TEST=y
tools/testing/selftests/mm/ksft_vmstat.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh -e +# SPDX-License-Identifier: GPL-2.0 + +./run_vmtests.sh -t vmstat
tools/testing/selftests/mm/run_vmtests.sh +5 -0
@@ -47,6 +47,8 @@ separated by spaces: tests for very large virtual address space - vmalloc vmalloc smoke tests +- vmstat + vmstat performance test - hmm hmm smoke tests - madv_guard
@@ -338,6 +340,9 @@ fi # VADDR64 # vmalloc stability smoke test CATEGORY="vmalloc" run_test bash ./test_vmalloc.sh smoke +# vmstat performance test +CATEGORY="vmstat" run_test bash ./test_vmstat.sh performance + CATEGORY="mremap" run_test ./mremap_dontunmap CATEGORY="hmm" run_test bash ./test_hmm.sh smoke
tools/testing/selftests/mm/test_vmstat.sh new file +71 -0
71 lines not on this page · raw message
Re: [patch v2] lib: test_vmstat: add synthetic benchmark for vm stats
Quoted 19 lines · David Rientjes
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of VM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
The test is run by inserting the module: modprobe
test_vmstatThe module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.Signed-off-by Christoph Lameter <[email protected]>Signed-off-by David Rientjes <[email protected]>---
v2:
- added bash wrapper to ksft per David
- integrated into ksft
- addedMAINTAINERSentry per David
- fixedalloc_page()error code per Usama
Quoted 3 lines
Adding single test for now to solicit feedback before updating the other two.
Any feedback for this one? If this one looks good then I can also apply the same treatment for test_pagealloc and test_slab.
Re: [patch v2] lib: test_vmstat: add synthetic benchmark for vm stats
Quoted 21 lines · David Rientjes
Quoted 19 lines · David Rientjes
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of VM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
The test is run by inserting the module: modprobe
test_vmstatThe module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.Signed-off-by Christoph Lameter <[email protected]>Signed-off-by David Rientjes <[email protected]>---
v2:
- added bash wrapper to ksft per David
- integrated into ksft
- addedMAINTAINERSentry per David
- fixedalloc_page()error code per Usama
Quoted 7 lines
Quoted 3 lines
Adding single test for now to solicit feedback before updating the other two.
Any feedback for this one? If this one looks good then I can also apply the same treatment for
test_pageallocandtest_slab.
Andrew, David, any thoughts on whether this one is acceptable for merge? If this looks structually correct and is staged for inclusion, then I'll do the same treatment to the other two proposed tests as well.
Thanks!
Re: [patch v2] lib: test_vmstat: add synthetic benchmark for vm stats
Quoted 27 lines · On Fri, 21 Aug 2026 16:52:17 -0700 (PDT) David Rientjes <[email protected]>…
Quoted 25 lines · David Rientjes
Quoted 22 lines · David Rientjes
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of VM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
The test is run by inserting the module: modprobe
test_vmstatThe module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.Signed-off-by Christoph Lameter <[email protected]>Signed-off-by David Rientjes <[email protected]>---
v2:
- added bash wrapper to ksft per David
- integrated into ksft
- addedMAINTAINERSentry per David
- fixedalloc_page()error code per UsamaAdding single test for now to solicit feedback before updating the other two.
Quoted 7 lines
Quoted 3 lines
Any feedback for this one? If this one looks good then I can also apply the same treatment for
test_pageallocandtest_slab.Andrew, David, any thoughts on whether this one is acceptable for merge? If this looks structually correct and is staged for inclusion, then I'll do the same treatment to the other two proposed tests as well.
FWIW, I found a similar high level topics including whether performance tests should be in the tree, and where tests should be added, are being discussed on another thread [1].
[1] https://lore.kernel.org/aogrd9knfBUGH885@gremlin
Thanks,
SJ
[...]
David Hildenbrand (Arm)
maintainerRe: [patch v2] lib: test_vmstat: add synthetic benchmark for vm stats
In reply to David RientjesQuoted 27 lines · David Rientjes
Quoted 25 lines · David Rientjes
Quoted 22 lines · David Rientjes
From: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of VM statistics. This is used to analyze any improvements or regressions in functions that are frequently used in hot code paths.
The test is run by inserting the module: modprobe
test_vmstatThe module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.Signed-off-by Christoph Lameter <[email protected]>Signed-off-by David Rientjes <[email protected]>---
v2:
- added bash wrapper to ksft per David
- integrated into ksft
- addedMAINTAINERSentry per David
- fixedalloc_page()error code per UsamaAdding single test for now to solicit feedback before updating the other two.
Quoted 7 lines
Quoted 3 lines
Any feedback for this one? If this one looks good then I can also apply the same treatment for
test_pageallocandtest_slab.Andrew, David, any thoughts on whether this one is acceptable for merge? If this looks structually correct and is staged for inclusion, then I'll do the same treatment to the other two proposed tests as well.
Please send new revisions next time not as reply to previous revisions, makes it easier to miss them ;)
I still dislike placing them in lib/ but as discussed, we can handle that separately (CCing Sarthak).
As replied to v1, is there any chance we could convert some of that to kunit?
Signature · 3 lines
Cheers, David
PATCH 2/3 lib: test_slab: add synthetic benchmark for slab
In reply to David RientjesFrom: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of the slab allocator. This is used to analyze any improvements or regressions in slab allocation or freeing functions.
The test is run by inserting the module: modprobe test_slab The module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.
--- lib/Kconfig.debug | 10 ++ lib/Makefile | 1 + lib/test_slab.c | 375 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 386 insertions(+) create mode 100644 lib/test_slab.c
lib/Kconfig.debug +10 -0
@@ -3437,6 +3437,16 @@ config TEST_VMSTAT If unsure, say N. +config TEST_SLAB + tristate "Slab Allocator Benchmark" + default n + help + A synthetic benchmark that measures slab allocator performance, + specifically focusing on single thread testing by repeatedly + allocating then freeing memory and concurrent or remote allocations. + + If unsure, say N. + config RATELIMIT_KUNIT_TEST tristate "KUnit Test for correctness and stress of ratelimit" if !KUNIT_ALL_TESTS depends on KUNIT
lib/Makefile +1 -0
@@ -106,6 +106,7 @@ obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o obj-$(CONFIG_TEST_KEXEC_HANDOVER) += test_kho.o obj-$(CONFIG_TEST_VMSTAT) += test_vmstat.o +obj-$(CONFIG_TEST_SLAB) += test_slab.o obj-$(CONFIG_TEST_FPU) += test_fpu.o test_fpu-y := test_fpu_glue.o test_fpu_impl.o
lib/test_slab.c new file +375 -0
375 lines not on this page · raw message
PATCH 3/3 lib: test_pagealloc: add synthetic benchmark for page allocator
In reply to David RientjesFrom: Christoph Lameter <[email protected]>
Add a synthetic benchmark that can be used to measure performance of the buddy allocator, including repeatedly allocating and freeing memory as well as concurrent and remote allocations.
The test is run by inserting the module: modprobe test_pagealloc The module insertion will always fail so that it is automatically unloaded; the results are in the kernel log.
--- lib/Kconfig.debug | 10 ++ lib/Makefile | 1 + lib/test_pagealloc.c | 337 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 348 insertions(+) create mode 100644 lib/test_pagealloc.c
lib/Kconfig.debug +10 -0
@@ -3447,6 +3447,16 @@ config TEST_SLAB If unsure, say N. +config TEST_PAGEALLOC + tristate "Page Allocator Benchmark" + default n + help + A benchmark measuring the performance of the page allocator, useful + to analyze any improvements or regressions when repeatedly allocating + and freeing memory as well as concurrent and remote allocations. + + If unsure, say N. + config RATELIMIT_KUNIT_TEST tristate "KUnit Test for correctness and stress of ratelimit" if !KUNIT_ALL_TESTS depends on KUNIT
lib/Makefile +1 -0
@@ -107,6 +107,7 @@ obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o obj-$(CONFIG_TEST_KEXEC_HANDOVER) += test_kho.o obj-$(CONFIG_TEST_VMSTAT) += test_vmstat.o obj-$(CONFIG_TEST_SLAB) += test_slab.o +obj-$(CONFIG_TEST_PAGEALLOC) += test_pagealloc.o obj-$(CONFIG_TEST_FPU) += test_fpu.o test_fpu-y := test_fpu_glue.o test_fpu_impl.o
lib/test_pagealloc.c new file +337 -0
337 lines not on this page · raw message
David Hildenbrand (Arm)
maintainerQuoted 2 lines · David Rientjes
A blast to the past :)
:)
Quoted 8 lines
We've been carrying these synthetic benchmarks in our kernel tree since 2009 because they've been helpful to identify regressions in hot paths, as well as quantifying any improvements that have been made for new changes. Hopefully they can be useful to others as well.
The synthetic benchmarks are run by loading the module at runtime. The modprobe will fail intentionally so that the module gets insta-unloaded. The test results are emitted to the kernel log.
Ideally we'd have an easy way to actually use them in autoamtic tests.
E.g., loading fails -> error, loading works -> no error (and unload)
Quoted 12 lines
Proposed with permission from Christoph.
--- lib/Kconfig.debug | 30 ++++ lib/Makefile | 3 + lib/test_pagealloc.c | 337 ++++++++++++++++++++++++++++++++++++++ lib/test_slab.c | 375 +++++++++++++++++++++++++++++++++++++++++++ lib/test_vmstat.c | 95 +++++++++++ 5 files changed, 840 insertions(+) create mode 100644 lib/test_pagealloc.c create mode 100644 lib/test_slab.c create mode 100644 lib/test_vmstat.c
This looks similar to tools/testing/selftests/mm/test_vmalloc.sh and friends, that can actually be executed as part of our selftests and do a modprobe.
Can we have similar scripts to execute them?
But I also wonder if these test modules could be placed then in tools/testing/selftests/mm/ instead (or some subdirectory for test modules).
Last but not least: MAINTAINERS should cover them.
Signature · 3 lines
Cheers, David
Quoted 33 lines · David Hildenbrand (Arm)
Quoted 2 lines · David Rientjes
A blast to the past :)
:)
Quoted 8 lines
We've been carrying these synthetic benchmarks in our kernel tree since 2009 because they've been helpful to identify regressions in hot paths, as well as quantifying any improvements that have been made for new changes. Hopefully they can be useful to others as well.
The synthetic benchmarks are run by loading the module at runtime. The modprobe will fail intentionally so that the module gets insta-unloaded. The test results are emitted to the kernel log.
Ideally we'd have an easy way to actually use them in autoamtic tests.
E.g., loading fails -> error, loading works -> no error (and unload)
Quoted 12 lines
Proposed with permission from Christoph.
--- lib/Kconfig.debug | 30 ++++ lib/Makefile | 3 + lib/test_pagealloc.c | 337 ++++++++++++++++++++++++++++++++++++++ lib/test_slab.c | 375 +++++++++++++++++++++++++++++++++++++++++++ lib/test_vmstat.c | 95 +++++++++++ 5 files changed, 840 insertions(+) create mode 100644 lib/test_pagealloc.c create mode 100644 lib/test_slab.c create mode 100644 lib/test_vmstat.c
Quoted 5 lines
This looks similar to
tools/testing/selftests/mm/test_vmalloc.shand friends, that can actually be executed as part of our selftests and do a modprobe.Can we have similar scripts to execute them?
Thanks for looking at these tests!
Good call, I agree these could be loaded with a wrapper similar to test_vmalloc.sh.
All three of these tests don't take module parameters (yet?) so right now this wrapper would just do the equivalent of check_test_requirements(), usage(), and run_test() where we'd pass in a single option for now, "performance".
Quoted 3 lines
But I also wonder if these test modules could be placed then in
tools/testing/selftests/mm/instead (or some subdirectory for test modules).
I thought about the same and just followed what appears to be the standard convention (like test_vmalloc above) for lib/ for now. If they should all be moved under tools/ somewhere, perhaps we handle that in a separate series?
Quoted 2 lines
Last but not least:
MAINTAINERSshould cover them.
Ack.
Quoted 5 lines
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerQuoted 9 lines
Quoted 4 lines
But I also wonder if these test modules could be placed then in
tools/testing/selftests/mm/instead (or some subdirectory for test modules).I thought about the same and just followed what appears to be the standard convention (like
test_vmallocabove) forlib/for now. If they should all be moved undertools/somewhere, perhaps we handle that in a separate series?
Yes. Right now the lie effectively unmaintained (no mm M: entry) in lib.
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerQuoted 51 lines · David Rientjes
Quoted 33 lines · David Hildenbrand (Arm)
Quoted 2 lines · David Rientjes
A blast to the past :)
:)
Quoted 8 lines
We've been carrying these synthetic benchmarks in our kernel tree since 2009 because they've been helpful to identify regressions in hot paths, as well as quantifying any improvements that have been made for new changes. Hopefully they can be useful to others as well.
The synthetic benchmarks are run by loading the module at runtime. The modprobe will fail intentionally so that the module gets insta-unloaded. The test results are emitted to the kernel log.
Ideally we'd have an easy way to actually use them in autoamtic tests.
E.g., loading fails -> error, loading works -> no error (and unload)
Quoted 12 lines
Proposed with permission from Christoph.
--- lib/Kconfig.debug | 30 ++++ lib/Makefile | 3 + lib/test_pagealloc.c | 337 ++++++++++++++++++++++++++++++++++++++ lib/test_slab.c | 375 +++++++++++++++++++++++++++++++++++++++++++ lib/test_vmstat.c | 95 +++++++++++ 5 files changed, 840 insertions(+) create mode 100644 lib/test_pagealloc.c create mode 100644 lib/test_slab.c create mode 100644 lib/test_vmstat.cQuoted 5 lines
This looks similar to
tools/testing/selftests/mm/test_vmalloc.shand friends, that can actually be executed as part of our selftests and do a modprobe.Can we have similar scripts to execute them?
Thanks for looking at these tests!
Good call, I agree these could be loaded with a wrapper similar to
test_vmalloc.sh.All three of these tests don't take module parameters (yet?) so right now this wrapper would just do the equivalent of
check_test_requirements(),usage(), andrun_test()where we'd pass in a single option for now, "performance".
Quoted 8 lines
Quoted 3 lines
But I also wonder if these test modules could be placed then in
tools/testing/selftests/mm/instead (or some subdirectory for test modules).I thought about the same and just followed what appears to be the standard convention (like
test_vmallocabove) forlib/for now. If they should all be moved undertools/somewhere, perhaps we handle that in a separate series?
Yes. lib/ is just absolutely the wrong place for that.
Maybe lib/tests/mm
But then, I wonder if they could just be somewhere in tests/ directly ...
Anyhow, it was also raised whether some of these could be written as kunit tests. It's been a long time since I worked on these, so just mentioning it.
Signature · 3 lines
Cheers, David
Quoted 61 lines · David Hildenbrand (Arm)
Quoted 51 lines · David Rientjes
Quoted 33 lines · David Hildenbrand (Arm)
Quoted 2 lines · David Rientjes
A blast to the past :)
:)
Quoted 8 lines
We've been carrying these synthetic benchmarks in our kernel tree since 2009 because they've been helpful to identify regressions in hot paths, as well as quantifying any improvements that have been made for new changes. Hopefully they can be useful to others as well.
The synthetic benchmarks are run by loading the module at runtime. The modprobe will fail intentionally so that the module gets insta-unloaded. The test results are emitted to the kernel log.
Ideally we'd have an easy way to actually use them in autoamtic tests.
E.g., loading fails -> error, loading works -> no error (and unload)
Quoted 12 lines
Proposed with permission from Christoph.
--- lib/Kconfig.debug | 30 ++++ lib/Makefile | 3 + lib/test_pagealloc.c | 337 ++++++++++++++++++++++++++++++++++++++ lib/test_slab.c | 375 +++++++++++++++++++++++++++++++++++++++++++ lib/test_vmstat.c | 95 +++++++++++ 5 files changed, 840 insertions(+) create mode 100644 lib/test_pagealloc.c create mode 100644 lib/test_slab.c create mode 100644 lib/test_vmstat.cQuoted 5 lines
This looks similar to
tools/testing/selftests/mm/test_vmalloc.shand friends, that can actually be executed as part of our selftests and do a modprobe.Can we have similar scripts to execute them?
Thanks for looking at these tests!
Good call, I agree these could be loaded with a wrapper similar to
test_vmalloc.sh.All three of these tests don't take module parameters (yet?) so right now this wrapper would just do the equivalent of
check_test_requirements(),usage(), andrun_test()where we'd pass in a single option for now, "performance".Quoted 8 lines
Quoted 3 lines
But I also wonder if these test modules could be placed then in
tools/testing/selftests/mm/instead (or some subdirectory for test modules).I thought about the same and just followed what appears to be the standard convention (like
test_vmallocabove) forlib/for now. If they should all be moved undertools/somewhere, perhaps we handle that in a separate series?
Quoted 8 lines
Yes.
lib/is just absolutely the wrong place for that.Maybe
lib/tests/mmBut then, I wonder if they could just be somewhere in tests/ directly ...
Anyhow, it was also raised whether some of these could be written as kunit tests. It's been a long time since I worked on these, so just mentioning it.
I also think it would be best to try to add them as kunit. I'm not exactly sure if kunit would accept such benchmark kind of code. Some research is required there.
Thanks,
Usama
Quoted 9 lines · Usama Anjum
Quoted 9 lines
Quoted 4 lines
I thought about the same and just followed what appears to be the standard convention (like
test_vmallocabove) forlib/for now. If they should all be moved undertools/somewhere, perhaps we handle that in a separate series?Yes.
lib/is just absolutely the wrong place for that.Maybe
lib/tests/mm
Quoted 8 lines
Quoted 4 lines
But then, I wonder if they could just be somewhere in tests/ directly ...
Anyhow, it was also raised whether some of these could be written as kunit tests. It's been a long time since I worked on these, so just mentioning it.
I also think it would be best to try to add them as kunit. I'm not exactly sure if kunit would accept such benchmark kind of code. Some research is required there.
Sounds good, I'll transition these to kunit tests, move to mm/tests/ alongside the other MM kunit test, and send a v3 for just the vmstat test as a separate thread. If all looks good, I can do this for slab and pgalloc as well as a follow-up step.
Quoted 16 lines · David Rientjes
Quoted 14 lines · Usama Anjum
Quoted 13 lines
Quoted 4 lines
I thought about the same and just followed what appears to be the standard convention (like
test_vmallocabove) forlib/for now. If they should all be moved undertools/somewhere, perhaps we handle that in a separate series?Yes.
lib/is just absolutely the wrong place for that.Maybe
lib/tests/mmBut then, I wonder if they could just be somewhere in tests/ directly ...
Anyhow, it was also raised whether some of these could be written as kunit tests. It's been a long time since I worked on these, so just mentioning it.
Quoted 8 lines
Quoted 3 lines
I also think it would be best to try to add them as kunit. I'm not exactly sure if kunit would accept such benchmark kind of code. Some research is required there.
Sounds good, I'll transition these to kunit tests, move to
mm/tests/alongside the other MM kunit test, and send a v3 for just the vmstat test as a separate thread. If all looks good, I can do this for slab and pgalloc as well as a follow-up step.
Yeah, sounds like a plan. Thank you for working on these. These would help everyone.
Signature · 2 lines
Thanks, Usama