linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: <hu.shengming@zte.com.cn>
To: <harry@kernel.org>
Cc: <vbabka@kernel.org>, <akpm@linux-foundation.org>,
	<hao.li@linux.dev>, <cl@gentwo.org>, <rientjes@google.com>,
	<roman.gushchin@linux.dev>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <zhang.run@zte.com.cn>,
	<xu.xin16@zte.com.cn>, <yang.tao172@zte.com.cn>,
	<yang.yang29@zte.com.cn>
Subject: Re: [PATCH v3] mm/slub: defer freelist construction until after bulk allocation from a new slab
Date: Wed, 8 Apr 2026 12:21:42 +0800 (CST)	[thread overview]
Message-ID: <20260408122142195kd_6Njq39HPtNW0rnWnF3@zte.com.cn> (raw)
In-Reply-To: <adWxmEzU23nza_pn@hyeyoo>

Harry wrote:
> > > > -        slab->inuse++;
> > > >          allocated++;
> > > >      }
> > > > -    slab->freelist = object;
> > > > +    slab->inuse = target_inuse;
> > > >  
> > > >      if (needs_add_partial) {
> > > > -
> > > > +        build_slab_freelist(s, slab, &iter);
> > > 
> > > When allow_spin is true, it's building the freelist while holding the
> > > spinlock, and that's not great.
> > > 
> > > Hmm, can we do better?
> > > 
> > > Perhaps just allocate object(s) from the slab and build the freelist
> > > with the objects left (if exists), but free the slab if allow_spin
> > > is false AND trylock fails, and accept the fact that the slab may not be
> > > fully free when it's freed due to trylock failure?
> > > 
> > > something like:
> > > 
> > > alloc_from_new_slab() {
> > >     needs_add_partial = (slab->objects > count);
> > >     target_inuse = needs_add_partial ? count : slab->objects;
> > > 
> > >     init_slab_obj_iter(s, slab, &iter, allow_spin);
> > >     while (allocated < target_inuse) {
> > >         p[allocated] = next_slab_obj(s, &iter);
> > >         allocated++;
> > >     }
> > >     slab->inuse = target_inuse;
> > > 
> > >     if (needs_add_partial) {
> > >         build_slab_freelist(s, slab, &iter);
> > >         n = get_node(s, slab_nid(slab))
> > >         if (allow_spin) {
> > >             spin_lock_irqsave(&n->list_lock, flags);
> > >         } else if (!spin_trylock_irqsave(&n->list_lock, flags)) {
> > >             /* 
> > >              * Unlucky, discard newly allocated slab.
> > >              * The slab is not fully free, but it's fine as
> > >              * objects are not allocated to users.
> > >              */
> > >             free_new_slab_nolock(s, slab);
> > >             return 0;
> > >         }
> > >         add_partial(n, slab, ADD_TO_HEAD);
> > >         spin_unlock_irqrestore(&n->list_lock, flags);
> > >     }
> > >     [...]
> > > }
> > > 
> > > And do something similar in alloc_single_from_new_slab() as well.
> > > 
> > 
> > Good point. I'll restructure the path so objects are emitted first, the leftover
> > freelist is built only if needed, and the slab is added to partial afterwards. For
> > the !allow_spin trylock failure case, I'll discard the new slab and return 0. I'll
> > do the same for the single-object path as well.
> 
> Thanks. Please keep in mind that you need to enable SLUB_TINY or slab_debug
> to test the alloc_single_from_new_slab() path.

Sure, will do. I’ll make sure to test the alloc_single_from_new_slab() path as well
by enabling CONFIG_SLUB_TINY or slab_debug to ensure it gets exercised.

--
With Best Regards,
Shengming


      reply	other threads:[~2026-04-08  4:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-06 13:50 hu.shengming
2026-04-07  4:19 ` Harry Yoo (Oracle)
2026-04-07 13:02   ` hu.shengming
2026-04-08  1:38     ` Harry Yoo (Oracle)
2026-04-08  4:21       ` hu.shengming [this message]

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=20260408122142195kd_6Njq39HPtNW0rnWnF3@zte.com.cn \
    --to=hu.shengming@zte.com.cn \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=hao.li@linux.dev \
    --cc=harry@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=xu.xin16@zte.com.cn \
    --cc=yang.tao172@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    --cc=zhang.run@zte.com.cn \
    /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