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=1796204279; b=cGJoCO2+nddyRfAJ9+Qr2ojDo8HcaS3RLWZsXQpXOzxyONrqFA5yovpkmKjz8afFFFrw fJ87N37m5kqQRowb2Mpfqu16LDRa7o09BCztfjg+3Qpc2mELXVMssAwkQmIesrLt1UdLZ P+y6YFAv2ELVR6v3cHFDqohHXypwvykhocyl/+JbzvTPJGh46fkV9x7OCrRUEoUfYGELw 7AfinvaVxSDLnpfi6yIoVKC2xm0ziytuph0w/D/9Kfd+8MsQbBbCkE8H1i7ETl0T9cev3 yokQLCDh3da4PUlhndnDCpnn6NAZsp7YcGjecSvrx69qifrFQFJfv0TC/ztm5PBwoFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796204279; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:Content-Language:To:Cc:References:From:Autocrypt:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=58VaoayUxkgaQybKqbIxBiEC/bXpTw3N8vIyMxhgl2s=; b=B4vxyJXnJZBrUDwQ/8k/6w2BPAplUX+ym4mb5F6bkUTT3VUi3PN/WPb5Dell9dej5SUK eM0O+NW0OWxW563JurJv9dxkMYV5dQUUbl0jnM0jcDuHmjFwB4oOO7NCK3zMu5os3Vojd SAkA1sAouiI3yh8cWYbLZjSsf01huN9xM0fc+xFC0EpkQRFrcA2n24cu5CHZqAAyKwtVP LryhdvCg8Dv7TQJBcukKKpxgjlkbwzbt7ZOsK9R3DXAePtPgJm4GGchF3GY6hp7iK1Ofv pdUfiSmgczMj0zDSVS4WF2mKro5AMd1LRtU8CFzVsLUreS63iHeK4ZRL3D4szp2aSNw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fC+1Aq5g; 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 378DF606A322 for ; Wed, 2 Dec 2026 09:37:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fC+1Aq5g Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E2BE1F00893; Wed, 2 Dec 2026 09:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796204278; bh=58VaoayUxkgaQybKqbIxBiEC/bXpTw3N8vIyMxhgl2s=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=fC+1Aq5gRDFIhMIBBKDXDZNPDdde2/oNvD/NgrTHioHEgTFpunnd0q9Tl0SYjLDFc tcCJb8ZvPGuNrMCFieCmpSAkiAE14y8/VIzEZZspayZvnJ36OG/4eLcuDzHYtrnL1p XHSSvU72LWF00VhU/SIwty7XFH8rXPTv/BpERKJZCQxwsDbvPpLK4e5/0kBepLCfwD vYTAQ6WA5rTQ4RaUzNH/BxLM6KZmcJifeHt47TtseUbBzjhjaCPgjEjMgKi/oI4pwl fqhDDdph0bpe5onbk0b8ISbTTpbsuoLcuPV64vmEs+iKkI+JVKBSXNqdWVyMSphk87 Um2ZbQAkWkJnQ== Message-ID: Date: Wed, 2 Dec 2026 10:37:54 +0100 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 User-Agent: Mozilla Thunderbird Subject: Re: [patch v2 1/2] mm: page_alloc_kunit: add synthetic benchmark for the page allocator Content-Language: en-US To: David Rientjes , Andrew Morton , David Hildenbrand Cc: 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 References: <20261129212551.1812084-1-rientjes@google.com> <20261129212551.1812084-2-rientjes@google.com> From: "Vlastimil Babka (SUSE)" Autocrypt: addr=vbabka@kernel.org; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcqHfTD8k4yK0xxt3xW+6Exqp9n9bydiy tcSAw/TahjW6yrA+6JhSBv1v2tIm+itQc073zjSX8OFL51qQVzRFr7H2UQG33lw2QrvHRXqD Ot7ViKam7v0Ho9wEWiQOOZlHItOOXFphWb2yq3nzrKe45oWoSgkxKb97MVsQ+q2SYjJRBBH4 8qKhphADYxkIP6yut/eaj9ImvRUZZRi0DTc8xfnvHGTjKbJzC2xpFcY0DQbZzuwsIZ8OPJCc LM4S7mT25NE5kUTG/TKQCk922vRdGVMoLA7dIQrgXnRXtyT61sg8PG4wcfOnuWf8577aXP1x 6mzw3/jh3F+oSBHb/GcLC7mvWreJifUL2gEdssGfXhGWBo6zLS3qhgtwjay0Jl+kza1lo+Cv BB2T79D4WGdDuVa4eOrQ02TxqGN7G0Biz5ZLRSFzQSQwLn8fbwARAQABzSNWbGFzdGltaWwg QmFia2EgPHZiYWJrYUBrZXJuZWwub3JnPsLBsAQTAQoAWhYhBKlA1DSZLC6OmRA9UCJPp+fM g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vwn75KqSk4UzAkDzWSmO4ZHuahKtQgZNsMYV+PGayRBX9b9zbldzopoLBdqHc4n jQARAQABwsF8BBgBCgAmAhsMFiEEqUDUNJksLo6ZED1QIk+n58yCpmQFAmfIHFQFCRYU6J8A CgkQIk+n58yCpmS2PA//bqN1LfcotmArgElsa+0EGZSQlYgK48pm8WAeTXTngudP9IJ4SuKY HR5RNjHcBeqN+Me0zxRqYzRb8nGanHEkDyf4Im8DQM8d6vbyU+FcPmG4skud4kgS1zMHnlVd SXfSIwKC/hKgdHG8aBV7545Lz9X6Iohea+94wneD0aw/hqF+QWewGZhWJriWAZtvEkzNjQOi 4U9F/trLten/x7bpphDSnDMKJtITbtzATT1Dq7o7VpIUK1nCTQALMuMjKCdi8OdU/+V+R3O4 0PXWvX8qrvqYapVbZ+9KqT74FsuB0Ya9uXwgBF2Q6cRuETZk5vqaqKxzqoQZCO8AOz/58j6O 2RHNy/mZEN+7tJ5Tsq42zVJ4jxsT8b9YplavCMsnBgDeRWhcbYhCyttoL7nYISyWg4kQYZ/P wIV3OuNv2f8iKYsxNsRuClOAF82+gvqOy1/1pprFjy8uo2pkoOrb63aOP3vO5VHnRKgra6dq NcaZ+c6J4H+nEJGi2SkHAUJz5oBzuThvPudLvPA/SK8sKoM01IRxSihev/S/5WLazXB1PGem OCbvzC1IjWJJraxiDJ5IygokapUa2RP7+WBR22skQ3SSl6G107QgWKSyTOGWEaRmV53vxQLV jXuCmzSSasTL60zq5yGrT4/DYQVSNEUiUbG4pYekxJujNeEDkUlky0Y= In-Reply-To: <20261129212551.1812084-2-rientjes@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/29/26 22:25, David Rientjes 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. > 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?