From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CA7F2DB780 for ; Fri, 31 Jul 2026 04:26:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785471987; cv=none; b=E/99MH7vYoGoTMtA/z+2peq+d0sUjWkzs7hv01lwb0vV1fKFSNUFQqkVrnmONyIU1c5K1C6u3B94g6kF2Hv37LCfTFN7hFp9QHmU/0IRSipVjNVqyV1msHPNm7lnSQb20ZTmSuSBSAqbInQCeOxOh0N3TVuhDil2d2aJ2QfT86U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785471987; c=relaxed/simple; bh=s9tdmPT/jMksEsAbkNjv33R3eNRN3Sz1ytEnHhIkLqA=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=fWzn921oMycNpPPQocfCrhb9s2XrOyF0Mbt/OTx4ydTtn1cdnjD2RJJirFz5C60h5Y64N7k0yAzc42BlrVGAezQdg8FxlU/a83kPhJHlnR0qoiDIFPd9MBCH0ul6eIK+RCyoZzsZ+m22U3wZ+XcRlyJZrDt4qG39demdZNVClxk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TEILZ1+g; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TEILZ1+g" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2cede6375caso58705ad.0 for ; Thu, 30 Jul 2026 21:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785471985; x=1786076785; darn=vger.kernel.org; h=content-type:mime-version:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WYx+7/vOEZAK67zN7a62VWu2wkdimiEvpJwaQveLjY8=; b=TEILZ1+gxb+/1omC9sZcW8H857r/UCXHudnVcGJwGEcGP13ZMQvirOwTKCt6awvc7i yZdU2W+7KqSbAczsXLyaKPx6y3b7k85JLKg+OC7uiYohu1qhPSIKDO1jxqSwowsZ9LZk epIi4fKI41cMd/aq3bT9EpjyjI6vntV67HAg31qukAOGdEhd/AL+UsG59nuCTTotjfNE u64+g2EQpneXsvEGcBY4fQ34wCJcTDu9knBoeAAdouZLZQSHGLNEg3TiaX8heLXSzYPQ 459r+rogv+bl0DNxCYCMmhq9n26SfWvh0PoLVxfUNuLo9yPq+VjbYFPbl/1JcFChvUP9 ZOpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785471985; x=1786076785; h=content-type:mime-version:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WYx+7/vOEZAK67zN7a62VWu2wkdimiEvpJwaQveLjY8=; b=VFOdfHSIqm7qNppjM1/kf6LXfARhbsUTKhzK187eZOWIduK03G31WjUf/HjjHpk9Or OCV/T1IaVXlZdOE9zPz0XgmJGxu61Sbr5YvOLj5uuQWfLcfLl2wyeG2vudNCtMVe6e86 Gc3MLiri0l37wN5FjB6ABfzSn+J0V6l4+0ERMGB3UzKiT8hnwftZdCVxsgpJdWB57N4Z rI8e0LGiUG+69B3bQRDFIyxJM2V40LbkTcwxVRDMxtrcKb4zcjxXD03rJ9PQJqNo/8ka uDyWEKIIWI/+7q12/dV8vxePEA0zpX9cQrW7DdnMrLTHZYmG/Cx8FPUokKQSZwZpYlYo qnxA== X-Forwarded-Encrypted: i=1; AHgh+Rq7euS80DWt6j7tHuNVmNcyLpwRoCIljw9rwjRk6sbFCtB/IiWGfTcike4waJZ/EQpAx5wvRF4ifUe+peo=@vger.kernel.org X-Gm-Message-State: AOJu0YyZ/ztZsuyGkbuTYF4hOrPD0Exxm15ofd2y4Wvy/1VnWkJavWhe e0o1JxyBlEknDPR6SF61jflHSOpR9uFER6ciPdZPdtg6grYKRasW8lLaQhzjR6k5/Q== X-Gm-Gg: AR+sD1388/KN7dq7dWrzxSGJVCqKMwZ3iJaEAyQLHA1oXMYi+ciMLDk6wit1PkzwUCZ lPWNPoM6bquvbJ+D0zYzjZP11gCPF18QzS2oucr/Pp7pfXOH1Qeg0SA7yD/lu+I94m8Dok5EZVG CS/IHlp222lL/1zpV7MAbDkQQctgy6OmtUR1fFkTYCQdgSQ9Q+axMlDmfM47NL6UA7KYk9Q7Bso WBFur3G9SUIFaF3u2/dm27hUyzo3JQrkwXhEJR2z68Zxxssv7W9DFh4IXLvSNVqeiDETBGx1Ub3 UnBIlsboDt9lnG9mkc/nVeoeEZf2H7pbV727Mz2eZruBARy9cAYXv4BAVvvCuoxlaak38oLjSj8 nzkChit93rKWlK++V0TJopd38lNg1eW1mVk2c/imDA/wOkDtpzeEYX1S2bLYZ4684lJF8D4OCWJ dCtSdBfxCtg6eierIbX5XY5mTpbfuoIRlJSGniViYaQ+eurKyIkeI63oXE/jqGtEWjIr32RIvc2 WTCYxhxYka+f4IIs7k9jbzB2HgW6UDUYT60sRkMfLkNqDqmwthZ9PW7Rbuhp5QDxh0oCkrFlzH3 c9Ak6+NrZ8s8aXMWzJD4z12fEw== X-Received: by 2002:a17:903:2c0f:b0:2cf:9ec1:ea6e with SMTP id d9443c01a7336-2d046e9a9f7mr1524175ad.8.1785471984911; Thu, 30 Jul 2026 21:26:24 -0700 (PDT) Received: from [2a00:79e0:2eb4:9:a061:9e19:11a8:45b6] ([2a00:79e0:2eb4:9:a061:9e19:11a8:45b6]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84ed57861e8sm207186b3a.8.2026.07.30.21.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 21:26:24 -0700 (PDT) Date: Thu, 30 Jul 2026 21:26:23 -0700 (PDT) From: David Rientjes To: Andrew Morton , David Hildenbrand , Christoph Lameter cc: Vlastimil Babka , Mathieu Desnoyers , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [patch 1/3] lib: test_vmstat: add synthetic benchmark for vm stats In-Reply-To: Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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); + + 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); + + 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");