mm: slab_kunit: add synthetic benchmark for the slab allocator
Subsystems (2)
PATCH 2/2 mm: slab_kunit: add synthetic benchmark for the slab allocator
From: 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 kmalloc() and kfree(), which are used throughout the kernel in hot code paths.
This is the third 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. 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 benchmark covers, for kmalloc object sizes that are powers of two:
- allocating a batch of objects and then freeing them, from a single thread
- allocating and immediately freeing an object, from a single thread
- both of the above concurrently on all online CPUs
- allocating objects on all CPUs but one and freeing them all from that one CPU (remote free)
- allocating objects on one CPU while all other CPUs concurrently free them (1 alloc N free)
Allocations use __GFP_NORETRY | __GFP_NOWARN so that the benchmark does not invoke the oom killer on small systems; if memory runs out, the results are reported for the objects that could be allocated.
This is a performance benchmark and is complementary to the functional tests in lib/tests/slub_kunit.c.
The test is run by KUnit or doing modprobe slab_kunit directly.
Sample output (abbreviated):
KTAP version 1
1..1
KTAP version 1
# Subtest: slab
# module: slab_kunit
1..6
# slab_test_kmalloc_then_kfree: size 8: 10000 ops: kmalloc -> 996 cycles (248 ns/op), kfree -> 449 cycles (111 ns/op)
...
ok 1 slab_test_kmalloc_then_kfree
# slab_test_kmalloc_kfree_pair: size 8: 10000 ops: kmalloc/kfree pair -> 832 cycles (206 ns/op)
...
ok 2 slab_test_kmalloc_kfree_pair
# slab_test_concurrent_kmalloc_then_kfree: size 8: 4 cpus, 40000 ops: kmalloc -> 951 cycles (236 ns/op), kfree -> 530 cycles (131 ns/op)
...
ok 3 slab_test_concurrent_kmalloc_then_kfree
# slab_test_concurrent_kmalloc_kfree_pair: size 8: 4 cpus, 40000 ops: kmalloc/kfree pair -> 1071 cycles (263 ns/op)
...
ok 4 slab_test_concurrent_kmalloc_kfree_pair
# slab_test_remote_free: size 8: 4 cpus, 30000 ops: kmalloc -> 1118 cycles (280 ns/op), remote kfree -> 420 cycles (103 ns/op)
...
ok 5 slab_test_remote_free
# slab_test_alloc_n_free: size 8: 4 cpus, 30000 ops: kmalloc -> 902 cycles (223 ns/op), remote wait+kfree -> 2705 cycles (665 ns/op)
...
ok 6 slab_test_alloc_n_free # slab: pass:6 fail:0 skip:0 total:6
# Totals: pass:6 fail:0 skip:0 total:6
ok 1 slab
--- MAINTAINERS | 1 + mm/Kconfig | 14 + mm/Makefile | 1 + mm/tests/slab_kunit.c | 614 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 630 insertions(+) create mode 100644 mm/tests/slab_kunit.c
MAINTAINERS +1 -0
@@ -18012,6 +18012,7 @@ F: mm/mempool.c F: mm/slab.h F: mm/slab_common.c F: mm/slub.c +F: mm/tests/slab_kunit.c F: scripts/gdb/linux/slab.py F: tools/cgroup/memcg_slabinfo.py F: tools/include/linux/slab.h
mm/Kconfig +14 -0
@@ -1504,6 +1504,20 @@ config PAGE_ALLOC_KUNIT_TEST If unsure, say N. +config SLAB_KUNIT_TEST + tristate "KUnit test for the slab allocator" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test and benchmark the performance of the + slab allocator: allocating and freeing kmalloc objects of various + sizes from a single thread, concurrently on all CPUs, and freeing + objects on a different CPU than the one that allocated them. + + For functional tests of the slab allocator, see SLUB_KUNIT_TEST. + + If unsure, say N. + config ARCH_HAS_CHECK_WX bool
mm/Makefile +1 -0
@@ -151,4 +151,5 @@ 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_PAGE_ALLOC_KUNIT_TEST) += tests/page_alloc_kunit.o +obj-$(CONFIG_SLAB_KUNIT_TEST) += tests/slab_kunit.o obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
mm/tests/slab_kunit.c new file +614 -0
614 lines not on this page · raw message