From: Vlastimil Babka <vbabka@suse.com>
To: Marcelo Tosatti <mtosatti@redhat.com>, Michal Hocko <mhocko@suse.com>
Cc: Leonardo Bras <leobras.c@gmail.com>,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
linux-mm@kvack.org, Johannes Weiner <hannes@cmpxchg.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Vlastimil Babka <vbabka@suse.cz>,
Hyeonggon Yoo <42.hyeyoo@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Waiman Long <longman@redhat.com>,
Boqun Feng <boqun.feng@gmail.com>,
Frederic Weisbecker <fweisbecker@suse.de>
Subject: Re: [PATCH 0/4] Introduce QPW for per-cpu operations
Date: Mon, 23 Feb 2026 19:09:47 +0100 [thread overview]
Message-ID: <1fd2efef-888b-4d3c-9c72-bdb2d594336f@suse.com> (raw)
In-Reply-To: <aZiSHT5DwIZwc/cH@tpad>
On 2/20/26 17:55, Marcelo Tosatti wrote:
>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/slab.h>
> #include <linux/timex.h>
> #include <linux/preempt.h>
> #include <linux/irqflags.h>
> #include <linux/vmalloc.h>
>
> MODULE_LICENSE("GPL");
> MODULE_AUTHOR("Gemini AI");
> MODULE_DESCRIPTION("A simple kmalloc performance benchmark");
>
> static int size = 64; // Default allocation size in bytes
> module_param(size, int, 0644);
>
> static int iterations = 1000000; // Default number of iterations
> module_param(iterations, int, 0644);
>
> static int __init kmalloc_bench_init(void) {
> void **ptrs;
> cycles_t start, end;
> uint64_t total_cycles;
> int i;
> pr_info("kmalloc_bench: Starting test (size=%d, iterations=%d)\n", size, iterations);
>
> // Allocate an array to store pointers to avoid immediate kfree-reuse optimization
> ptrs = vmalloc(sizeof(void *) * iterations);
> if (!ptrs) {
> pr_err("kmalloc_bench: Failed to allocate pointer array\n");
> return -ENOMEM;
> }
>
> preempt_disable();
> start = get_cycles();
>
> for (i = 0; i < iterations; i++) {
> ptrs[i] = kmalloc(size, GFP_ATOMIC);
> }
>
> end = get_cycles();
>
> total_cycles = end - start;
> preempt_enable();
While preempt_disable() simplifies things, it can misrepresent the cost of
preempt_disable() that's part of the locking - that will become nested and
then the nested preempt_disable() is typically cheaper, etc.
Also the way it kmallocs all iterations and then kfree all iterations may
skew the probabilities of fastpaths, cache hotness etc.
When introducing sheaves I had a similar microbenchmark, but there was
different amounts of inner-loop iteraions, no outer preempt_disable(), and
linear vs randomized array. See:
https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/linux.git/commit/?h=slub-percpu-sheaves-v6-benchmarking&id=04028eeffba18a4f821a7194bc9d14f7488bd7d9
(at this point the SLUB_HAS_SHEAVES parts should be removed and the
kmem_cache_print_stats() stuff also shouldn't be interesting for QPW
evaluation).
>
> pr_info("kmalloc_bench: Total cycles for %d allocs: %llu\n", iterations, total_cycles);
> pr_info("kmalloc_bench: Avg cycles per kmalloc: %llu\n", total_cycles / iterations);
>
> // Cleanup
> for (i = 0; i < iterations; i++) {
> kfree(ptrs[i]);
> }
> vfree(ptrs);
>
> return 0;
> }
>
> static void __exit kmalloc_bench_exit(void) {
> pr_info("kmalloc_bench: Module unloaded\n");
> }
>
>
next prev parent reply other threads:[~2026-02-23 18:09 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 14:34 Marcelo Tosatti
2026-02-06 14:34 ` [PATCH 1/4] Introducing qpw_lock() and per-cpu queue & flush work Marcelo Tosatti
2026-02-06 15:20 ` Marcelo Tosatti
2026-02-07 0:16 ` Leonardo Bras
2026-02-11 12:09 ` Marcelo Tosatti
2026-02-14 21:32 ` Leonardo Bras
2026-02-06 14:34 ` [PATCH 2/4] mm/swap: move bh draining into a separate workqueue Marcelo Tosatti
2026-02-06 14:34 ` [PATCH 3/4] swap: apply new queue_percpu_work_on() interface Marcelo Tosatti
2026-02-07 1:06 ` Leonardo Bras
2026-02-06 14:34 ` [PATCH 4/4] slub: " Marcelo Tosatti
2026-02-07 1:27 ` Leonardo Bras
2026-02-06 23:56 ` [PATCH 0/4] Introduce QPW for per-cpu operations Leonardo Bras
2026-02-10 14:01 ` Michal Hocko
2026-02-11 12:01 ` Marcelo Tosatti
2026-02-11 12:11 ` Marcelo Tosatti
2026-02-14 21:35 ` Leonardo Bras
2026-02-11 16:38 ` Michal Hocko
2026-02-11 16:50 ` Marcelo Tosatti
2026-02-11 16:59 ` Vlastimil Babka
2026-02-11 17:07 ` Michal Hocko
2026-02-14 22:02 ` Leonardo Bras
2026-02-16 11:00 ` Michal Hocko
2026-02-19 15:27 ` Marcelo Tosatti
2026-02-19 19:30 ` Michal Hocko
2026-02-20 14:30 ` Marcelo Tosatti
2026-02-23 9:18 ` Michal Hocko
2026-02-23 21:56 ` Frederic Weisbecker
2026-02-20 10:48 ` Vlastimil Babka
2026-02-20 12:31 ` Michal Hocko
2026-02-20 17:35 ` Marcelo Tosatti
2026-02-20 17:58 ` Vlastimil Babka
2026-02-20 19:01 ` Marcelo Tosatti
2026-02-23 9:11 ` Michal Hocko
2026-02-20 16:51 ` Marcelo Tosatti
2026-02-20 16:55 ` Marcelo Tosatti
2026-02-20 22:38 ` Leonardo Bras
2026-02-23 18:09 ` Vlastimil Babka [this message]
2026-02-20 21:58 ` Leonardo Bras
2026-02-23 9:06 ` Michal Hocko
2026-02-19 13:15 ` Marcelo Tosatti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1fd2efef-888b-4d3c-9c72-bdb2d594336f@suse.com \
--to=vbabka@suse.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=boqun.feng@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=cl@linux.com \
--cc=fweisbecker@suse.de \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=leobras.c@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=mhocko@suse.com \
--cc=mtosatti@redhat.com \
--cc=muchun.song@linux.dev \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=tglx@linutronix.de \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox