From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796522642; b=wtaUliIAKixxbKac0v4OEIwWiiN1q9nMrWQixsWu3NvdOCkyVS8nvQnB6utHKPOe4wVl /cH7uiHOyipyCxleC5NMxQOLx3NQlVUogakLzuwYg2+9UVIsKiCOG+FDyWPYJps6ZHrAp XQlAfz3UIngK/NiAsQGm7HzxfMw4Xbh/lrJV+ifUsZknBTs3bfrRx/sLZWOn+sAYI/Owa Gb2M/Rh0Galq9yh5wKy6Ph7eYgKgLLzXMhsTGsZ/YS8pSEMcRFokgFRVeYbbQQexBuNrB wxXXQjT7nLfLxcjGXaKQzsMsnMXAAYt70Y4Pvbe8kb6snT83daT5D2aaYgE92iE5skg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796522642; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; bh=s1coSBzLO6UdBd8wVQmSkby0Skhfi2qvMh32zXh5xLE=; b=ce+AGEZPhcTgqIJ9iho7mPQy/XB5FM3UALG32HDSIkwN44Hl3tcssm2DlmYrLATNclml JHyA+VZ38PPlijPOugNZoWxcV5bube8smNyyrQLb0jTkx5YhM/L7M8wopDyFuZMKx03Rj u/CGbnDimZt3ktbTMqqGFL2nzo+eS6GUyQCKlFycoON3KzfMJm1sW2g+ga4QaorjJglNM YWVFQLUG/eAG8x+MUtBFQ5c6zI5yltqMzc75sWMVrJcpdXGcXlfLFb9Dxsa2KDVPYR/Li gPOVyraeHZtjkJihwtVf7LDnPJWqosqKV/+3oqX6HcUzIfVNHkWla9Tr5osMK/jiANQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=LhzwnU+e; arc=none smtp.remote-ip=209.85.214.176 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 388A8606A31F for ; Sun, 6 Dec 2026 02:04:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 388A8606A31F 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.a=rsa-sha256 header.s=20260707 header.b=LhzwnU+e Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2f0e8bbc7a4so33285ad.1 for ; Sat, 05 Dec 2026 18:04:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796522641; x=1797127441; 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=s1coSBzLO6UdBd8wVQmSkby0Skhfi2qvMh32zXh5xLE=; b=LhzwnU+e+TU2Mm913JPvcaZA8IEUK6lfzHKcgRzw0ODlrTq6atlUNJDI680AjeT+Ii 1o9s611ycmQ1uyJmYYr9oa2YZF8IN7SVWPUjytoPxtwrYh/RdpdHkX0FweP/q2Ot8cfe ki0H3yKH1qWCrNF609dDIeE0/CyTX5MdUEjWsKWO2gWRE7ID3AXABFl+8c+6tcZFmtHc jA+0AyvoKZYQtjPCmHb9Ea4TIdn0TfHGOP39l8O6g4GqKEOgnYvjMSg+vxKsZGmWkhnz ZhF/2sEJ1NfxCir7QIji/R3XnChuYc9DVjTow8YANl1q+siFWpM11v/tem4sHCjCBBPL mxeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796522641; x=1797127441; 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=s1coSBzLO6UdBd8wVQmSkby0Skhfi2qvMh32zXh5xLE=; b=e6bMJrqfmt5OpHVRVr36xQsaOE4t0Q5fXfczbJj4d18MGfw0Yv0G/eDW9FACdHj6dn GiH1ef1dXE+7KjtOyvjETRvPkll2sz/8pA/6rMEw039clHRP+SmqBRb2YFubwQIhF3i4 KzjW0x6AGaeu4no9iIM+P6iIMYq70oPG7iS6Y4g6ZkFv++ItY9WEQtsvl+C4Nlj8S6WO +oW9ncbMhGYPFlRm8WCV2WqC0MjpBcnix19D32G31yeRkeAbKG74mCN9dChud2Ze+aPR tz1guHHVEnSjvebt5wR5SNKkGETKuUo/UinfWF3myUI2oBjyd00Y4TVpnq4sGjeteSzH 9tLA== X-Forwarded-Encrypted: i=1; AL+hErFIqB3d19CD514s/r4VsZl4/cemEXjsPB6pvxKqKEcdBhkBQKUGbZJAwx6t5xiMxNuBulFCKxGSIfJ9UcM=@vger.kernel.org X-Gm-Message-State: AB4q+uFzrwC98deaOrVSB+zpKssUBWDpyzYk2B0fEd2bOgAQ8f2V1p/8 dcmZh8BuLb0YHJtoqaQGfqqtlQvrgM/hk8a6H/+OSW5LgEFWQ3of7OnbZjziITO9oA== X-Gm-Gg: AZFdTZeedrCUOqqtESv/6P01lh4GbKfipTYLrS9r7H42hjY0cs5UG89IUclgu699wk7 LoHhWNWs3vlqsgnrUsQBaF2DWJSZGbBxxPVxlDRfnQNaojgNjLsOzacrjGnHvA4+7Oa6Z77QtK3 NBPp/wHYbo5CPX2vVsvfTms4y5w31JkyKrE5abW4H2/HHkqBAMm9aL5LDHWLysVR7Io3drDvAy/ Fzq90mdhEXjsPuEP0O3ZB6OdqHQfDC4jqLus18YcCPqz77O26ZEg6eQbMfLWcpxw5zcCLGR/1vm SltQnnBj7EoeE9tqCLTPmXG3V/EQHRUZkhuudPBM7ovaIAFz3YThTYb9s9pg4L2r12N2bziN5qH pGqxVH0v2YbdqdJhDQnjUlMHwBQiOpvb8/QHxdaEh7Vso4Qc3Pm6EqE/I6KNRl3e3BiDlvaeGyG R7Un7QDd1lDLgLJTOGTPS+0eEu/g/Ad9ryWLBl/W7kSVo/6jiQd61cAvAcWUU0LH7tC2Rqy8crA 4QghDYWq/TK8TE/29RML+WHk9B0SgbKLOmf+0Ja5Aug+z4+IC9nIZxqgd6lgvikMEdPi+G958O4 kKUNofsthDOXQsPjMpFBg4of8Q7C0jCJGX6fw14DqTWCUeO813ivBvp9xTTz2QLYfyoPMX3rnyh C1XTuWysDgj2EOybg+wcvqW+urVcbO5JnUHEB2fv+cGcFMMyZIoteFMsKkujlqCnvPeqFCmbye4 +L9hXvvtZ4gw9bROAAK7wEqKDxxDNOxBDHQhDZwwsxpA== X-Received: by 2002:a17:903:2985:b0:2e7:e742:8bb5 with SMTP id d9443c01a7336-2f1f4d290f0mr1538035ad.14.1796522640440; Sat, 05 Dec 2026 18:04:00 -0800 (PST) Received: from [2a00:79e0:2eb4:9:4af:b01b:ed89:6bed] ([2a00:79e0:2eb4:9:4af:b01b:ed89:6bed]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ce123461bcbsm3424916a12.3.2026.12.05.18.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 18:03:59 -0800 (PST) Date: Sat, 5 Dec 2026 18:03:58 -0800 (PST) From: David Rientjes To: "Vlastimil Babka (SUSE)" cc: Andrew Morton , David Hildenbrand , Christoph Lameter , Mathieu Desnoyers , Sarthak Sharma , Johannes Weiner , Suren Baghdasaryan , Brendan Jackman , Zi Yan , Harry Yoo , Hao Li , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [patch v2 1/2] mm: page_alloc_kunit: add synthetic benchmark for the page allocator In-Reply-To: Message-ID: <29ac4aa2-ccef-5442-b3bd-5cfb314050b3@google.com> References: <20261129212551.1812084-1-rientjes@google.com> <20261129212551.1812084-2-rientjes@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Wed, 2 Dec 2026, Vlastimil Babka (SUSE) wrote: > > From: Christoph Lameter > > > > Add a synthetic benchmark that can be used to measure performance of the > > page allocator. This is used to analyze any improvements or regressions > > in the allocation and free paths, which are among the hottest paths in MM. > > > > This is the second 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 each page order: > > > > - allocating a batch of pages and then freeing them, from a single thread > > - allocating and immediately freeing a page, from a single thread > > - both of the above concurrently on all online CPUs > > - allocating pages on all CPUs but one and freeing them all from that > > one CPU (remote 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 pages that could be allocated. > > > > The test is run by KUnit or doing modprobe page_alloc_kunit directly. > > > > Sample output (abbreviated): > > KTAP version 1 > > 1..1 > > KTAP version 1 > > # Subtest: page_alloc > > # module: page_alloc_kunit > > 1..5 > > # page_alloc_test_alloc_then_free: order 0: 1000 ops: alloc_pages -> 4074 cycles (1008 ns/op), __free_pages -> 1240 cycles (298 ns/op) > > ... > > ok 1 page_alloc_test_alloc_then_free > > # page_alloc_test_alloc_free_pair: order 0: 1000 ops: alloc/free pair -> 3036 cycles (746 ns/op) > > ... > > ok 2 page_alloc_test_alloc_free_pair > > # page_alloc_test_concurrent_alloc_then_free: order 0: 4 cpus, 4000 ops: alloc_pages -> 4880 cycles (1208 ns/op), __free_pages -> 4832 cycles (1171 ns/op) > > ... > > ok 3 page_alloc_test_concurrent_alloc_then_free > > # page_alloc_test_concurrent_alloc_free_pair: order 0: 4 cpus, 4000 ops: alloc/free pair -> 3695 cycles (892 ns/op) > > ... > > ok 4 page_alloc_test_concurrent_alloc_free_pair > > # page_alloc_test_remote_free: order 0: 4 cpus, 3000 ops: alloc_pages -> 5763 cycles (1442 ns/op), remote __free_pages -> 1707 cycles (414 ns/op) > > ... > > ok 5 page_alloc_test_remote_free > > # page_alloc: pass:5 fail:0 skip:0 total:5 > > # Totals: pass:5 fail:0 skip:0 total:5 > > ok 1 page_alloc > > > > Signed-off-by: Christoph Lameter > > ... you should probably have at least "Co-developed-by: yourself" here, so > that coveres all the updates at google. > Sure, will do. > > Signed-off-by: David Rientjes > > --- > > MAINTAINERS | 1 + > > mm/Kconfig | 12 + > > mm/Makefile | 1 + > > mm/tests/page_alloc_kunit.c | 490 ++++++++++++++++++++++++++++++++++++ > > 4 files changed, 504 insertions(+) > > create mode 100644 mm/tests/page_alloc_kunit.c > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > index f2670f0547b2..741354a460fe 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -17916,6 +17916,7 @@ F: mm/page_reporting.h > > F: mm/show_mem.c > > F: mm/shuffle.c > > F: mm/shuffle.h > > +F: mm/tests/page_alloc_kunit.c > > F: scripts/gdb/linux/page_owner.py > > F: tools/mm/page_owner_filter.c > > F: tools/mm/page_owner_sort.c > > diff --git a/mm/Kconfig b/mm/Kconfig > > index d6131fb7c1e6..1fa0c824fbe9 100644 > > --- a/mm/Kconfig > > +++ b/mm/Kconfig > > @@ -1492,6 +1492,18 @@ config VMSTAT_KUNIT_TEST > > > > If unsure, say N. > > > > +config PAGE_ALLOC_KUNIT_TEST > > + tristate "KUnit test for the page allocator" if !KUNIT_ALL_TESTS > > + depends on KUNIT > > + default KUNIT_ALL_TESTS > > + help > > + Enable this option to test and benchmark the performance of the > > + page allocator: allocating and freeing pages of each order from a > > + single thread, concurrently on all CPUs, and freeing pages on a > > + different CPU than the one that allocated them. > > + > > + If unsure, say N. > > + > > config ARCH_HAS_CHECK_WX > > bool > > > > diff --git a/mm/Makefile b/mm/Makefile > > index f49994e61b03..9e0c4c6c6cbb 100644 > > --- a/mm/Makefile > > +++ b/mm/Makefile > > @@ -150,4 +150,5 @@ 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_PAGE_ALLOC_KUNIT_TEST) += tests/page_alloc_kunit.o > > obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o > > diff --git a/mm/tests/page_alloc_kunit.c b/mm/tests/page_alloc_kunit.c > > new file mode 100644 > > index 000000000000..a1d4b0a1ef3d > > --- /dev/null > > +++ b/mm/tests/page_alloc_kunit.c > > @@ -0,0 +1,490 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * KUnit synthetic performance benchmark for the page allocator. > > + * > > + * (C) 2009 Linux Foundation, Christoph Lameter > > + * (C) 2026 Google LLC, David Rientjes > > + */ > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define TEST_COUNT 1000 > > + > > +/* Highest order used by the concurrent tests, which allocate on every CPU. */ > > +#define CONCURRENT_MAX_ORDER min(5, MAX_PAGE_ORDER) > > + > > +/* > > + * This is a benchmark, not a stress test: fail the allocation rather than > > + * retry hard or invoke the oom killer if the system is short on memory. > > + */ > > +#define TEST_GFP (GFP_KERNEL | __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY) > > + > > +#define BENCH_FMT_LEN 48 > > + > > +struct bench_stat { > > + cycles_t start_cycles; > > + u64 start_ns; > > + u64 cycles; > > + u64 ns; > > + u64 ops; > > +}; > > + > > +static void bench_start(struct bench_stat *stat) > > +{ > > + stat->start_cycles = get_cycles(); > > + stat->start_ns = ktime_get_ns(); > > +} > > + > > +static void bench_stop(struct bench_stat *stat, u64 ops) > > +{ > > + u64 stop_ns = ktime_get_ns(); > > + cycles_t stop_cycles = get_cycles(); > > + > > + stat->cycles = (cycles_t)(stop_cycles - stat->start_cycles); > > + stat->ns = stop_ns - stat->start_ns; > > + stat->ops = ops; > > +} > > + > > +static void bench_add(struct bench_stat *sum, const struct bench_stat *stat) > > +{ > > + sum->cycles += stat->cycles; > > + sum->ns += stat->ns; > > + sum->ops += stat->ops; > > +} > > + > > +/* Format the average cost of an operation; not all arches have get_cycles() */ > > +static const char *bench_fmt(char *buf, const struct bench_stat *stat) > > +{ > > + u64 ops = max(stat->ops, 1); > > + u64 cycles = div64_u64(stat->cycles, ops); > > + u64 ns = div64_u64(stat->ns, ops); > > + > > + if (cycles) > > + scnprintf(buf, BENCH_FMT_LEN, "%llu cycles (%llu ns/op)", cycles, ns); > > + else > > + scnprintf(buf, BENCH_FMT_LEN, "%llu ns/op", ns); > > + return buf; > > +} > > + > > +/* > > + * Test 1: Allocate TEST_COUNT pages of each order, then free them all. > > + */ > > +static void page_alloc_test_alloc_then_free(struct kunit *test) > > +{ > > + char alloc_buf[BENCH_FMT_LEN], free_buf[BENCH_FMT_LEN]; > > + struct bench_stat alloc, free; > > + struct page **pages; > > + unsigned int order; > > + unsigned int nr, i; > > + > > + pages = kunit_kcalloc(test, TEST_COUNT, sizeof(*pages), GFP_KERNEL); > > + KUNIT_ASSERT_NOT_NULL(test, pages); > > + > > + for (order = 0; order <= MAX_PAGE_ORDER; order++) { > > + bench_start(&alloc); > > + for (nr = 0; nr < TEST_COUNT; nr++) { > > + struct page *page = alloc_pages(TEST_GFP, order); > > + > > + if (!page) > > + break; > > + > > + /* Touch page */ > > + memset(page_address(page), 22, 4); > > I wonder if this is useful at all for the benchmark. Also some of the other > tests do that, some not. Maybe drop it from all of them? > Yeah, these can be removed. I think they were in the original tests back in 2009 but I agree that they are only a liability here. slab_kunit (soon to be slab_bench) does the same thing but not with memset(), will take care of those as well.