Re: [patch 1/3] lib: test_vmstat: add synthetic benchmark for vm stats
From: David Rientjes
Date: Sun Aug 02 2026 - 19:05:50 EST
On Sat, 1 Aug 2026, Usama Arif wrote:
> > 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 <cl@xxxxxxxxxx>
> > + */
> > +
> > +#include <linux/jiffies.h>
> > +#include <linux/compiler.h>
> > +#include <linux/init.h>
> > +#include <linux/module.h>
> > +#include <linux/mm.h>
> > +#include <asm/timex.h>
> > +
> > +#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?
>
Fixed both, thanks!