From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795231330; b=gbK/y4AXTYxLW08gq19b8aSly3QVcR1Ze8Qjk4m4xUYRudyMje1s4SKEH7OvkS2MaOPE tHzHMRqTvwOoYhY/EHNu/iehJr9MjcSvxEQPF3rzkze3h2xclzWs/8nRFVqM78wkqS+4S fiUodxw1sKZWD34lrCsms0y667e/FsNYPdFNVP4Kze/RkSvEFo1qwJ2XguVlk4yjjCobe gt4ISuC5jEZVRk1cY36GlrfzTs3efgX6NubONqVJRdU7om4ZeL33AKccjpscHpiSebBae 34HyCr7hwViWgmkCd7tsyvFWnHBalLztYvOFchbThsxEdZmPHeH6IJcWBSUz66mzRsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795231330; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=wJxQz2m/K4F+lN/T8oNb0kDlh/Igk7L/ApJAeElpCcc=; b=nJ3zWjMyoTKflCd9mPHB4gjgEmqyzO2MHD1g0XauGZzMzPLDRzwW0DqN2UpMfd1E3amS z2HapDGY6czo5DHzIkCtlPAbcGrtySEfkbqnbL5KzepKCR3TzD95qDvjsinZexwgCTGO3 Q/1DJucSoPi3TfMTl6gz0tSbuLyTxfJ1pUv5UN7kVxpN4E36CQuHqiKz+lLKWxf56/sed 6YN+hmkQ0JP3nOmbP5cDpbQHjpBPvPa18MiBBAupyl/eVv1IqQKFiCiTk5ciYj93xEe3N FaCMbZm15PaLDeEt+6vkWZo3I9aCcNbJfcgry+WRNKNZf+pQmS1JvZPfgKtBFnFwljw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Cf9eb8zl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 979EE606A6A8 for ; Sat, 21 Nov 2026 03:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Cf9eb8zl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F3E51F000C0; Sat, 21 Nov 2026 03:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1795231329; bh=wJxQz2m/K4F+lN/T8oNb0kDlh/Igk7L/ApJAeElpCcc=; h=Date:To:From:In-Reply-To:References:Subject; b=Cf9eb8zl083lbGitTnYIeEhFHaZQPlF3XBvO1d2fcVcdWhr4ytjZfmK/fv2jZ1OO7 ergTqMPEJbw3rcSUwjEaHNTBXTmkC6APGwkTF4ypEPpQgvGxeG+g0K5o6CuliIOt2q SZIlWLweZtDXewhqCWOgNvgQg6tlcSLM6zzXOyyk= Date: Fri, 20 Nov 2026 19:22:08 -0800 To: mm-commits@vger.kernel.org,vbabka@kernel.org,sarthak.sharma@arm.com, rientjes@google.com,mathieu.desnoyers@efficios.com,david@kernel.org, cl@gentwo.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <21183f5b-2697-cbe6-6370-dbd27c5e2b60@google.com> References: <21183f5b-2697-cbe6-6370-dbd27c5e2b60@google.com> Subject: + mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats.patch added to mm-unstable branch Message-Id: <20261121032209.6F3E51F000C0@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 Link: https://patch.msgid.link/21183f5b-2697-cbe6-6370-dbd27c5e2b60@google.com Signed-off-by: Christoph Lameter Signed-off-by: David Rientjes Signed-off-by: Andrew Morton Cc: David Hildenbrand Cc: Vlastimil Babka Cc: Mathieu Desnoyers Cc: Sarthak Sharma MAINTAINERS | 1 mm/Kconfig | 12 ++ mm/Makefile | 1 mm/tests/vmstat_kunit.c | 157 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) --- a/MAINTAINERS~mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats +++ a/MAINTAINERS @@ -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 --- a/mm/Kconfig~mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats +++ a/mm/Kconfig @@ -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 --- a/mm/Makefile~mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats +++ a/mm/Makefile @@ -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 diff --git a/mm/tests/vmstat_kunit.c a/mm/tests/vmstat_kunit.c new file mode 100644 --- /dev/null +++ a/mm/tests/vmstat_kunit.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * KUnit synthetic performance benchmark for VM statistics. + * + * (C) 2009 Linux Foundation, Christoph Lameter + * (C) 2026 Google LLC, David Rientjes + */ +#include +#include +#include +#include +#include +#include + +#define TEST_COUNT 10000 + +static void vmstat_test_free_page(void *arg) +{ + __free_page((struct page *)arg); +} + +/* + * Test 1: Sequential inc_zone_page_state() followed by dec_zone_page_state(). + * Net change to zone counters is 0. + */ +static void vmstat_test_inc_dec_zone_page_state(struct kunit *test) +{ + struct page *page; + cycles_t time1, time2, time; + u64 t1_ns, t2_ns; + u64 inc_cycles, dec_cycles; + u64 inc_ns, dec_ns; + unsigned int i; + + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, vmstat_test_free_page, page), 0); + + /* Benchmark inc_zone_page_state() */ + time1 = get_cycles(); + t1_ns = ktime_get_ns(); + for (i = 0; i < TEST_COUNT; i++) + inc_zone_page_state(page, NR_MLOCK); + t2_ns = ktime_get_ns(); + time2 = get_cycles(); + + time = time2 - time1; + inc_cycles = div_u64(time, TEST_COUNT); + inc_ns = div_u64(t2_ns - t1_ns, TEST_COUNT); + + /* Benchmark dec_zone_page_state() */ + time1 = get_cycles(); + t1_ns = ktime_get_ns(); + for (i = 0; i < TEST_COUNT; i++) + dec_zone_page_state(page, NR_MLOCK); + t2_ns = ktime_get_ns(); + time2 = get_cycles(); + + time = time2 - time1; + dec_cycles = div_u64(time, TEST_COUNT); + dec_ns = div_u64(t2_ns - t1_ns, TEST_COUNT); + + if (inc_cycles || dec_cycles) + kunit_info(test, "%u ops: inc_zone_page_state -> %llu cycles (%llu ns/op), dec_zone_page_state -> %llu cycles (%llu ns/op)\n", + TEST_COUNT, inc_cycles, inc_ns, dec_cycles, dec_ns); + else + kunit_info(test, "%u ops: inc_zone_page_state -> %llu ns/op, dec_zone_page_state -> %llu ns/op\n", + TEST_COUNT, inc_ns, dec_ns); +} + +/* + * Test 2: Paired inc_zone_page_state() and dec_zone_page_state(). + * Net change to zone counters is 0. + */ +static void vmstat_test_interleaved_zone_page_state(struct kunit *test) +{ + struct page *page; + cycles_t time1, time2, time; + u64 t1_ns, t2_ns; + u64 avg_cycles, avg_ns; + unsigned int i; + + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, vmstat_test_free_page, page), 0); + + time1 = get_cycles(); + t1_ns = ktime_get_ns(); + for (i = 0; i < TEST_COUNT; i++) { + inc_zone_page_state(page, NR_MLOCK); + dec_zone_page_state(page, NR_MLOCK); + } + t2_ns = ktime_get_ns(); + time2 = get_cycles(); + + time = time2 - time1; + avg_cycles = div_u64(time, TEST_COUNT); + avg_ns = div_u64(t2_ns - t1_ns, TEST_COUNT); + + if (avg_cycles) + kunit_info(test, "%u ops: inc/dec pair -> %llu cycles (%llu ns/op)\n", + TEST_COUNT, avg_cycles, avg_ns); + else + kunit_info(test, "%u ops: inc/dec pair -> %llu ns/op\n", + TEST_COUNT, avg_ns); +} + +/* + * Test 3: count_vm_event() benchmark. + * Restores counter balance with count_vm_events(item, -TEST_COUNT). + */ +static void vmstat_test_count_vm_event(struct kunit *test) +{ + cycles_t time1, time2, time; + u64 t1_ns, t2_ns; + u64 avg_cycles, avg_ns; + unsigned int i; + + time1 = get_cycles(); + t1_ns = ktime_get_ns(); + for (i = 0; i < TEST_COUNT; i++) + count_vm_event(SLABS_SCANNED); + t2_ns = ktime_get_ns(); + time2 = get_cycles(); + + /* Restore balance */ + count_vm_events(SLABS_SCANNED, -TEST_COUNT); + + time = time2 - time1; + avg_cycles = div_u64(time, TEST_COUNT); + avg_ns = div_u64(t2_ns - t1_ns, TEST_COUNT); + + if (avg_cycles) + kunit_info(test, "%u ops: count_vm_event -> %llu cycles (%llu ns/op)\n", + TEST_COUNT, avg_cycles, avg_ns); + else + kunit_info(test, "%u ops: count_vm_event -> %llu ns/op\n", + TEST_COUNT, avg_ns); +} + +static struct kunit_case vmstat_test_cases[] = { + KUNIT_CASE(vmstat_test_inc_dec_zone_page_state), + KUNIT_CASE(vmstat_test_interleaved_zone_page_state), + KUNIT_CASE(vmstat_test_count_vm_event), + {} +}; + +static struct kunit_suite vmstat_test_suite = { + .name = "vmstat", + .test_cases = vmstat_test_cases, +}; +kunit_test_suite(vmstat_test_suite); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Christoph Lameter "); +MODULE_AUTHOR("David Rientjes "); +MODULE_DESCRIPTION("KUnit benchmark test for VM statistics"); _ Patches currently in -mm which might be from cl@gentwo.org are mm-vmstat_kunit-add-synthetic-benchmark-for-mm-stats.patch