linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Harry Yoo <harry.yoo@oracle.com>
Cc: bpf <bpf@vger.kernel.org>, linux-mm <linux-mm@kvack.org>,
	 Vlastimil Babka <vbabka@suse.cz>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Michal Hocko <mhocko@suse.com>,
	 Sebastian Sewior <bigeasy@linutronix.de>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH v4 6/6] slab: Introduce kmalloc_nolock() and kfree_nolock().
Date: Mon, 8 Sep 2025 17:08:43 -0700	[thread overview]
Message-ID: <CAADnVQ+aLojadnDgnOwJCTAE319can=rW7ELh2Xy5M-d2TWcHQ@mail.gmail.com> (raw)
In-Reply-To: <aJt1FHnavjRv5CzI@hyeyoo>

On Tue, Aug 12, 2025 at 10:08 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>

Sorry for the delay. I addressed all other comments
and will respin soon.
Only below question remains..

> > > > >  {
> > > > > @@ -3732,9 +3808,13 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
> > > > >       if (unlikely(!node_match(slab, node))) {
> > > > >               /*
> > > > >                * same as above but node_match() being false already
> > > > > -              * implies node != NUMA_NO_NODE
> > > > > +              * implies node != NUMA_NO_NODE.
> > > > > +              * Reentrant slub cannot take locks necessary to
> > > > > +              * deactivate_slab, hence ignore node preference.
> > > >
> > > > Now that we have defer_deactivate_slab(), we need to either update the
> > > > code or comment?
> > > >
> > > > 1. Deactivate slabs when node / pfmemalloc mismatches
> > > > or 2. Update comments to explain why it's still undesirable
> > >
> > > Well, defer_deactivate_slab() is a heavy hammer.
> > > In !SLUB_TINY it pretty much never happens.
> > >
> > > This bit:
> > >
> > > retry_load_slab:
> > >
> > >         local_lock_cpu_slab(s, flags);
> > >         if (unlikely(c->slab)) {
> > >
> > > is very rare. I couldn't trigger it at all in my stress test.
> > >
> > > But in this hunk the node mismatch is not rare, so ignoring node preference
> > > for kmalloc_nolock() is a much better trade off.
>
> But users would have requested that specific node instead of
> NUMA_NO_NODE because (at least) they think it's worth it.
> (e.g., allocating kernel data structures tied to specified node)
>
> I don't understand why kmalloc()/kmem_cache_alloc() try harder
> (by deactivating cpu slab) to respect the node parameter,
> but kmalloc_nolock() does not.

Because kmalloc_nolock() tries to be as least intrusive as possible
to kmalloc slabs that the rest of the kernel is using.
There won't be kmem_cache_alloc _nolock() version, because
the algorithm retries from a different bucket when the primary one
is locked. So it's only kmalloc_nolock() flavor and it takes
from generic kmalloc slab buckets with or without memcg.
My understanding that c->slab is effectively a cache and in the long
run all c->slab-s should be stable. A given cpu should be kmalloc-ing
the memory suitable for this local cpu.
In that sense deactivate_slab is a heavy hammer. kmalloc_nolock()
is for users who cannot control their running context. imo such
users shouldn't affect the cache property of c->slab hence ignoring
node preference for !allow_spin is not great, but imo it's a better
trade off than defer_deactivate_slab.
defer_deactivate_slab() is there for a rare race in retry_load_slab.
It can be done for !node_match(c->slab, node) too,
but it feels like a worse-r evil. Especially since kmalloc_nolock()
doesn't support __GFP_THISNODE.


  reply	other threads:[~2025-09-09  0:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-18  2:16 [PATCH v4 0/6] slab: Re-entrant kmalloc_nolock() Alexei Starovoitov
2025-07-18  2:16 ` [PATCH v4 1/6] locking/local_lock: Expose dep_map in local_trylock_t Alexei Starovoitov
2025-07-18  2:16 ` [PATCH v4 2/6] locking/local_lock: Introduce local_lock_is_locked() Alexei Starovoitov
2025-07-18  2:16 ` [PATCH v4 3/6] mm: Allow GFP_ACCOUNT to be used in alloc_pages_nolock() Alexei Starovoitov
2025-07-18  2:16 ` [PATCH v4 4/6] mm: Introduce alloc_frozen_pages_nolock() Alexei Starovoitov
2025-07-18  2:16 ` [PATCH v4 5/6] slab: Make slub local_(try)lock more precise for LOCKDEP Alexei Starovoitov
2025-07-18  2:16 ` [PATCH v4 6/6] slab: Introduce kmalloc_nolock() and kfree_nolock() Alexei Starovoitov
2025-07-22 15:52   ` Harry Yoo
2025-08-06  2:40     ` Alexei Starovoitov
2025-08-12 15:11       ` Harry Yoo
2025-08-12 17:08         ` Harry Yoo
2025-09-09  0:08           ` Alexei Starovoitov [this message]
2025-09-09  2:05             ` Harry Yoo
2025-09-09  2:32               ` Alexei Starovoitov

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='CAADnVQ+aLojadnDgnOwJCTAE319can=rW7ELh2Xy5M-d2TWcHQ@mail.gmail.com' \
    --to=alexei.starovoitov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=bpf@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=harry.yoo@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=memxor@gmail.com \
    --cc=mhocko@suse.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=shakeel.butt@linux.dev \
    --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