linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hao Li <hao.li@linux.dev>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Harry Yoo <harry.yoo@oracle.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Christoph Lameter <cl@linux.com>,
	 David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	Ming Lei <ming.lei@redhat.com>
Subject: Re: [PATCH slab/for-next-fixes] mm/slab: allow sheaf refill if blocking is not allowed
Date: Thu, 5 Mar 2026 09:39:28 +0800	[thread overview]
Message-ID: <le2aabnh7doxt3zo3l2l35urng4kdxeacttv3qyefabzpv32pl@qs3e2yemq7sa> (raw)
In-Reply-To: <3952b84e-9342-4628-9778-92ae155e9727@kernel.org>

On Wed, Mar 04, 2026 at 11:14:51AM +0100, Vlastimil Babka (SUSE) wrote:
> On 3/4/26 8:44 AM, Hao Li wrote:
> > On Mon, Mar 02, 2026 at 10:55:37AM +0100, Vlastimil Babka (SUSE) wrote:
> >> @@ -4632,11 +4631,8 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
> >>  	if (!full)
> >>  		return NULL;
> >>  
> >> -	/*
> >> -	 * we can reach here only when gfpflags_allow_blocking
> >> -	 * so this must not be an irq
> >> -	 */
> >> -	local_lock(&s->cpu_sheaves->lock);
> >> +	if (!local_trylock(&s->cpu_sheaves->lock))
> >> +		goto barn_put;
> > 
> > A quick question to make sure I understand this correctly.
> > 
> > My understanding is that after this patch, there is now a new case where
> > allocations with __GFP_KSWAPD_RECLAIM set (e.g GFP_ATOMIC) can also reach this
> > lock-reacquire path.
> > 
> > If we were to keep using local_lock here:
> > 
> > 1. On non-RT kernels it seems fine, since alloc_from_pcs() already does a
> >    local_trylock(&s->cpu_sheaves->lock) check.
> > 
> > 2. But on PREEMPT_RT, local_lock could potentially schedule away, which may add
> >    latency. So the idea of using local_trylock here is to fail fast and return
> >    without incurring that latency - is that the intent behind this change?
> 
> Great question, thanks!
> 
> So the main intent is that lockdep would complain if it saw this
> local_lock() happening in e.g. an irq handler. It doesn't know that it's
> safe from deadlocks because we already succeeded a trylock before and
> thus the irq handler didn't interrupt anyone holding the lock.
> 
> Trying to teach lockdep such things leads to the complicated initial
> design of kmalloc_nolock() before it could be simplified by sheaves.

Oh, yes - I hadn't considered the impact of lockdep. This is a good point!

> 
> On !RT it makes no difference as the trylock will succeed always. On RT
> it may not, but indeed they may prefer avoiding the latency as you say.

Yes, make sense, thanks!

-- 
Thanks,
Hao


      reply	other threads:[~2026-03-05  1:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02  9:55 Vlastimil Babka (SUSE)
2026-03-04  3:05 ` Harry Yoo
2026-03-04  9:58   ` Vlastimil Babka
2026-03-04 10:03     ` Harry Yoo
2026-03-04  7:44 ` Hao Li
2026-03-04 10:14   ` Vlastimil Babka (SUSE)
2026-03-05  1:39     ` Hao Li [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=le2aabnh7doxt3zo3l2l35urng4kdxeacttv3qyefabzpv32pl@qs3e2yemq7sa \
    --to=hao.li@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ming.lei@redhat.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox