From: Harry Yoo <harry@kernel.org>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.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>,
Alexei Starovoitov <ast@kernel.org>, Hao Li <hao.li@linux.dev>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
kernel-team@meta.com, cgroups@vger.kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH for-next-fixes v2 2/5] mm/slab: handle allow_spin in slab_free_hook() instead of open coding
Date: Thu, 5 Nov 2026 12:09:47 +0000 [thread overview]
Message-ID: <auxxnr3iVYNOOoci@thinkstation> (raw)
In-Reply-To: <f31885cd-57c2-428d-9760-a76a0137f989@kernel.org>
On Wed, Nov 04, 2026 at 02:54:13PM +0100, Vlastimil Babka (SUSE) wrote:
> On 11/3/26 15:47, Harry Yoo (Meta) wrote:
> > kfree_nolock() deliberately skips slab free hooks that should not be
> > called in unknown context. However, there is one more place that
> > needs the same thing: memcg_alloc_abort_single().
> >
> > Instead of open coding slab_free_hook(), let it handle the allow_spin
> > parameter. This is required to correctly handle allocation failures due
> > to memcg charging.
> >
> > There are two functional changes from this.
> >
> > First, memcg_alloc_abort_single() -> slab_free_hook() path no longer
> > calls free hooks that acquire spinlocks if !allow_spin.
>
> Hm, since this is only changed by patch 4, I don't think it needs mentioning
> here, as it's not any functional change yet.
Good point, will adjust.
> > Second, kfree_nolock() now follows init_on_free which has been ignored.
> >
> > Besides that, no functional change intended.
> >
> > Closes: https://lore.kernel.org/asiSUpAYYU8Od4HM@gmail.com
> > Fixes: af92793e52c3 ("slab: Introduce kmalloc_nolock() and kfree_nolock().")
> > Signed-off-by: Harry Yoo (Meta) <harry@kernel.org>
> > ---
> > mm/slub.c | 104 +++++++++++++++++++++++++++++++++-----------------------------
> > 1 file changed, 56 insertions(+), 48 deletions(-)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 45e077c7526c..36e7bb93418a 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -2686,41 +2686,54 @@ struct rcu_delayed_free {
> > * - memcg_slab_post_alloc_hook()
> > * - alloc_tagging_slab_alloc_hook()
> > *
> > + * slab_free_hook() assumes that memcg_slab_free_hook() and
> > + * alloc_tagging_slab_free_hook() are already invoked.
> > + *
> > * Free hooks that must handle missing corresponding alloc hooks:
> > * - kmemleak_free_recursive()
> > * - kfence_free()
> > *
> > - * Free hooks that have no alloc hook counterpart, and thus safe to call:
> > + * Free hooks that have no alloc hook counterpart:
> > * - debug_check_no_locks_freed()
> > * - debug_check_no_obj_freed()
> > * - __kcsan_check_access()
> > */
> > static __always_inline
> > bool slab_free_hook(struct kmem_cache *s, void *x, bool init,
> > - bool after_rcu_delay)
> > + bool after_rcu_delay, bool allow_spin)
>
> Hm 3 bools. Could we bite the bullet and try doing free_flags (extended to
> cover init and after_rcu_delay) here already? :) Given it's not intended for
> a stable backport.
Ack, will try to bite the bullet.
> > @@ -2776,8 +2790,11 @@ bool slab_free_hook(struct kmem_cache *s, void *x, bool init,
> > set_orig_size(s, x, orig_size);
> >
> > }
> > - /* KASAN might put x into memory quarantine, delaying its reuse. */
> > - return !kasan_slab_free(s, x, init, still_accessible, false);
> > + /*
> > + * KASAN might put x into memory quarantine, delaying its reuse.
> > + * Skip quarantine when spinning is not allowed as it uses a spinlock.
> > + */
> > + return !kasan_slab_free(s, x, init, still_accessible, !allow_spin);
> > }
> >
> > static __fastpath_inline
> > @@ -2789,9 +2806,10 @@ bool slab_free_freelist_hook(struct kmem_cache *s, void **head, void **tail,
> > void *next = *head;
> > void *old_tail = *tail;
> > bool init;
> > + bool allow_spin = true;
>
> Then we wouldn't need tricks like this I guess?
Right.
--
Cheers,
Harry / Hyeonggon
next prev parent reply other threads:[~2026-11-05 12:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 14:47 [PATCH for-next-fixes v2 0/5] memcg,slab: kmalloc_nolock() fixes Harry Yoo (Meta)
2026-11-03 14:47 ` [PATCH for-next-fixes v2 1/5] mm/memcontrol: defer obj_cgroup_release() to irq_work Harry Yoo (Meta)
2026-11-04 11:02 ` Vlastimil Babka (SUSE)
2026-11-04 12:00 ` Harry Yoo
2026-11-03 14:47 ` [PATCH for-next-fixes v2 2/5] mm/slab: handle allow_spin in slab_free_hook() instead of open coding Harry Yoo (Meta)
2026-11-04 13:54 ` Vlastimil Babka (SUSE)
2026-11-05 12:09 ` Harry Yoo [this message]
2026-11-03 14:47 ` [PATCH for-next-fixes v2 3/5] mm/slab: call debug_locks and KCSAN checks in kfree_nolock() Harry Yoo (Meta)
2026-11-03 14:47 ` [PATCH for-next-fixes v2 4/5] mm/slab: fix a deadlock in memcg_alloc_abort_single() Harry Yoo (Meta)
2026-11-03 18:40 ` Alexei Starovoitov
2026-11-03 20:21 ` Harry Yoo
2026-11-03 21:11 ` Alexei Starovoitov
2026-11-04 15:35 ` Vlastimil Babka (SUSE)
2026-11-04 16:46 ` Alexei Starovoitov
2026-11-03 14:47 ` [PATCH for-next-fixes v2 5/5] mm/slab: serialize deferred_work_barrier() Harry Yoo (Meta)
2026-11-04 16:24 ` Vlastimil Babka (SUSE)
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=auxxnr3iVYNOOoci@thinkstation \
--to=harry@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=cgroups@vger.kernel.org \
--cc=cl@gentwo.org \
--cc=clrkwllms@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hao.li@linux.dev \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shakeel.butt@linux.dev \
--cc=vbabka@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.