From: Harry Yoo <harry.yoo@oracle.com>
To: JaeJoon Jung <rgbi3307@gmail.com>
Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com,
iamjoonsoo.kim@lge.com, akpm@linux-foundation.org,
vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
rgbi3307@naver.com
Subject: Re: [PATCH] mm/slub: Removing unnecessary variable accesses in the get_freelist()
Date: Wed, 10 Sep 2025 10:39:34 +0900 [thread overview]
Message-ID: <aMDW1urp03myzZFi@hyeyoo> (raw)
In-Reply-To: <20250910005957.54108-1-rgbi3307@gmail.com>
Hi Jaejoon,
I updated my email from 42.hyeyoo@gmail.com to harry.yoo@oracle.com
a while ago. Please check up-to-date MAINTAINERS file when sending a patch.
On Wed, Sep 10, 2025 at 09:59:56AM +0900, JaeJoon Jung wrote:
> It pass a NULL pointer to the freelist_new variable
> in the __slab_update_freelist() function so that it don't have to re-fetch
> the variable values inside the while loop.
No, it needs to re-fetch values when cmpxchg fails.
Otherwise it would fall into an infinite loop, no?
at a high level overview, cmpxchg works like this (atomically, of course):
retry:
old = var;
// modify some bits in 'old' and store it to 'new'
new = old + something;
if (var == old) { // compare
var = new; // exchange if the value is expected
} else {
// if var != old, someone else updated the variable. retry
goto retry;
}
and this retry will certainly fail if you don't you re-fetch the value,
modify it, and try cmpxchg again. The 'old' value fetched before failing
cmpxchg will not match anymore because other CPUs already updated that
variable.
> Removing unnecessary variable accesses as shown below
> will reduce the code size of the get_freelist() function and make it faster.
>
> Signed-off-by: JaeJoon Jung <rgbi3307@gmail.com>
> ---
> mm/slub.c | 21 ++++-----------------
> 1 file changed, 4 insertions(+), 17 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index d257141896c9..2e305a17a9d7 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3654,27 +3654,14 @@ __update_cpu_freelist_fast(struct kmem_cache *s,
> */
> static inline void *get_freelist(struct kmem_cache *s, struct slab *slab)
> {
> - struct slab new;
> - unsigned long counters;
> - void *freelist;
> -
> lockdep_assert_held(this_cpu_ptr(&s->cpu_slab->lock));
>
> - do {
> - freelist = slab->freelist;
> - counters = slab->counters;
> -
> - new.counters = counters;
> -
> - new.inuse = slab->objects;
> - new.frozen = freelist != NULL;
...and the frozen and inuse bits are part of counters field,
so they are not updated anymore?
> -
> - } while (!__slab_update_freelist(s, slab,
> - freelist, counters,
> - NULL, new.counters,
> + while (!__slab_update_freelist(s, slab,
> + slab->freelist, slab->counters,
> + NULL, slab->counters,
> "get_freelist"));
>
> - return freelist;
> + return slab->freelist;
> }
>
> /*
> --
> 2.43.0
--
Cheers,
Harry / Hyeonggon
next prev parent reply other threads:[~2025-09-10 1:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 0:59 JaeJoon Jung
2025-09-10 1:39 ` Harry Yoo [this message]
2025-09-10 2:31 ` JaeJoon Jung
2025-09-10 9:06 ` David Hildenbrand
2025-09-10 8:39 ` [syzbot ci] " syzbot ci
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=aMDW1urp03myzZFi@hyeyoo \
--to=harry.yoo@oracle.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rgbi3307@gmail.com \
--cc=rgbi3307@naver.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@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