From: Harry Yoo <harry@kernel.org>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Hao Li <hao.li@linux.dev>, Hyunwoo Kim <imv4bel@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Suren Baghdasaryan <surenb@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/slab: take n->list_lock for the list_add() in __refill_objects_node()
Date: Wed, 2 Sep 2026 12:20:34 +0100 [thread overview]
Message-ID: <apgE4TWLFGoqoOos@nixos> (raw)
In-Reply-To: <ae25c193-b95f-40c1-83b6-1c2546467e41@kernel.org>
On Mon, Aug 31, 2026 at 02:55:06PM +0200, Vlastimil Babka (SUSE) wrote:
> On 8/30/26 16:35, Hao Li wrote:
> > On Sun, Aug 30, 2026 at 12:45:17PM +0000, Harry Yoo wrote:
> >> On Sun, Aug 30, 2026 at 04:25:45PM +0900, Hyunwoo Kim wrote:
> > Since introducing a new variable seems unavoidable, what if we temporarily
> > stash this slab in a pointer like below, and then add it to pc.slabs once we
> > acquire the lock.
> >
> > struct slab *leftover_slab = NULL;
> >
> > ...
> > ...
> > if (__slab_try_return_freelist(s, slab, head, count)) {
> > leftover_slab = slab;
> > break;
> > }
> >
> > ...
> > ...
> > if (!list_empty(&pc.slabs)) {
> > spin_lock_irqsave(&n->list_lock, flags);
> >
> > if (leftover_slab)
> > list_add(&leftover_slab->slab_list, &pc.slabs);
> > ...
> > ...
> > }
> >
> > PS: If I recall correctly, Vlastimil's initial patch was actually fine. It was
> > my suggestion to save an extra lock/unlock pair that accidentally led to this
> > trap...
>
> Ah, thanks for the reminder. This [1] was the original attempt.
>
> [1]
> https://lore.kernel.org/all/20260421-b4-refill-optimistic-return-v1-1-24f0bfc1acff@kernel.org/
>
> I wonder if the fix should be to return to that approach and just have
> __slab_try_return_freelist() handle the list_lock. The code would be simpler
> with not "bool locked".
>
> It should be really very rare that we would end up returning a partial list
> and also have additional slabs to return on pc.slabs? So I think there would
> be no noticeable performance downside to the simpler code potentially ending
> up taking the list_lock twice instead of once.
Agreed that it should be rare and not worth the complexity unless
we have data to support that.
Hyunwoo, would you please adjust the feedback and post v2?
--
Cheers,
Harry / Hyeonggon
next prev parent reply other threads:[~2026-09-02 11:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 7:25 [PATCH] mm/slab: take n->list_lock for the list_add() in __refill_objects_node() Hyunwoo Kim
2026-08-30 12:45 ` Harry Yoo
2026-08-30 14:35 ` Hao Li
2026-08-31 12:55 ` Vlastimil Babka (SUSE)
2026-09-01 8:13 ` Hao Li
2026-09-02 11:20 ` Harry Yoo [this message]
2026-09-02 11:24 ` Hyunwoo Kim
2026-09-02 11:27 ` Harry Yoo
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=apgE4TWLFGoqoOos@nixos \
--to=harry@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=hao.li@linux.dev \
--cc=imv4bel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=surenb@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).