From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12AC675801 for ; Sat, 1 Aug 2026 13:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785590449; cv=none; b=qs1FangYTtsZPz3JOIMCbvHR4pJvo+PKl/e8/r70v38u0XbN4MG+t5fRpObxl20pGm8ppBx8FHfss9XWbZyxQsJkbIzFR3ASj3EQzDe0k1Xe7VkzHFvRzC4LK1tTMzKldsST5lF1mYh/0JjHSqQ19Uy9lUdLnpbtTRvalT+WM7Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785590449; c=relaxed/simple; bh=WpFByUrvITiePYPWMb/YUVmpf+CDTlNaQq2ceKpnsFY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c6G8nxhvJlDX9oigYzmXkfIQGIvr8Ic3zLoDpX+xi4DP8/oq22Oaw4H4Z2cA6pib5D6ICa0q3uQ1z650EuSAVbFVSxn33T8PNLRtWwzSU2MM1LSw58C3g0ADbxJ4LhoiTPK6PVk1cryKzwtYSY1eGqvyqJXFnEewHQTmuQeVcZg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=nQ8qK7jP; arc=none smtp.client-ip=95.215.58.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nQ8qK7jP" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785590444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t13C+xMvQNSfcgbBPqp8o7L1VMr2wxshCbQ8fbg+xWM=; b=nQ8qK7jPPB/d/j9bllq7oXQohbv6EqlhGdVUbElepHCkBR1/wz6UI64F/A9sGIoFuZls89 GaR9uE90m5KQGBBHVxfTNZ0TjZ6l+9FKgrAD5JXX3iF1ufT/GvBH+PNPjShlrdcA72kX20 m59R5IME/ugvYQ96DEFgx3azQZs/u+E= From: Usama Arif To: David Rientjes Cc: Usama Arif , Andrew Morton , David Hildenbrand , Christoph Lameter , Vlastimil Babka , Mathieu Desnoyers , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [patch 1/3] lib: test_vmstat: add synthetic benchmark for vm stats Date: Sat, 1 Aug 2026 06:20:37 -0700 Message-ID: <20260801132038.2926647-1-usama.arif@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Thu, 30 Jul 2026 21:26:23 -0700 (PDT) David Rientjes wrote: > From: Christoph Lameter > > 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. > > Signed-off-by: Christoph Lameter > Signed-off-by: David Rientjes > --- > lib/Kconfig.debug | 10 +++++ > lib/Makefile | 1 + > lib/test_vmstat.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 106 insertions(+) > create mode 100644 lib/test_vmstat.c > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 1244dcac2294..6d743c8e27fa 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -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 > diff --git a/lib/Makefile b/lib/Makefile > index 7f75cc6edf94..5f3ebabd0224 100644 > --- a/lib/Makefile > +++ b/lib/Makefile > @@ -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 > diff --git a/lib/test_vmstat.c b/lib/test_vmstat.c > new file mode 100644 > index 000000000000..f63f439ab9d2 > --- /dev/null > +++ b/lib/test_vmstat.c > @@ -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 > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#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. > + 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); > + > + 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? > + > + 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"); > >