From: Vlastimil Babka <vbabka@suse.cz>
To: xiongwei.song@windriver.com, rientjes@google.com, cl@linux.com,
penberg@kernel.org, iamjoonsoo.kim@lge.com,
akpm@linux-foundation.org, roman.gushchin@linux.dev,
42.hyeyoo@gmail.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
chengming.zhou@linux.dev
Subject: Re: [PATCH 3/4] mm/slub: simplify get_partial_node()
Date: Tue, 2 Apr 2024 11:41:58 +0200 [thread overview]
Message-ID: <69089796-9a3b-41a1-9b7c-18c773b96aa2@suse.cz> (raw)
In-Reply-To: <20240331021926.2732572-4-xiongwei.song@windriver.com>
On 3/31/24 4:19 AM, xiongwei.song@windriver.com wrote:
> From: Xiongwei Song <xiongwei.song@windriver.com>
>
> The break conditions can be more readable and simple.
>
> We can check if we need to fill cpu partial after getting the first
> partial slab. If kmem_cache_has_cpu_partial() returns true, we fill
> cpu partial from next iteration, or break up the loop.
>
> Then we can remove the preprocessor condition of
> CONFIG_SLUB_CPU_PARTIAL. Use dummy slub_get_cpu_partial() to make
> compiler silent.
>
> Signed-off-by: Xiongwei Song <xiongwei.song@windriver.com>
> ---
> mm/slub.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 590cc953895d..ec91c7435d4e 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2614,18 +2614,20 @@ static struct slab *get_partial_node(struct kmem_cache *s,
> if (!partial) {
> partial = slab;
> stat(s, ALLOC_FROM_PARTIAL);
> - } else {
> - put_cpu_partial(s, slab, 0);
> - stat(s, CPU_PARTIAL_NODE);
> - partial_slabs++;
> +
> + /* Fill cpu partial if needed from next iteration, or break */
> + if (kmem_cache_has_cpu_partial(s))
That kinda puts back the check removed in patch 1, although only in the
first iteration. Still not ideal.
> + continue;
> + else
> + break;
> }
> -#ifdef CONFIG_SLUB_CPU_PARTIAL
> - if (partial_slabs > s->cpu_partial_slabs / 2)
> - break;
> -#else
> - break;
> -#endif
I'd suggest intead of the changes done in this patch, only change this part
above to:
if ((slub_get_cpu_partial(s) == 0) ||
(partial_slabs > slub_get_cpu_partial(s) / 2))
break;
That gets rid of the #ifdef and also fixes a weird corner case that if we
set cpu_partial_slabs to 0 from sysfs, we still allocate at least one here.
It could be tempting to use >= instead of > to achieve the same effect but
that would have unintended performance effects that would best be evaluated
separately.
>
> + put_cpu_partial(s, slab, 0);
> + stat(s, CPU_PARTIAL_NODE);
> + partial_slabs++;
> +
> + if (partial_slabs > slub_get_cpu_partial(s) / 2)
> + break;
> }
> spin_unlock_irqrestore(&n->list_lock, flags);
> return partial;
next prev parent reply other threads:[~2024-04-02 9:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-31 2:19 [PATCH 0/4] SLUB: improve filling cpu partial a bit in get_partial_node() xiongwei.song
2024-03-31 2:19 ` [PATCH 1/4] mm/slub: remove the check of !kmem_cache_has_cpu_partial() xiongwei.song
2024-04-02 9:45 ` Vlastimil Babka
2024-04-03 0:10 ` Song, Xiongwei
2024-03-31 2:19 ` [PATCH 2/4] mm/slub: add slub_get_cpu_partial() helper xiongwei.song
2024-03-31 2:19 ` [PATCH 3/4] mm/slub: simplify get_partial_node() xiongwei.song
2024-04-02 9:41 ` Vlastimil Babka [this message]
2024-04-03 0:37 ` Song, Xiongwei
2024-04-03 7:25 ` Vlastimil Babka
2024-04-03 11:15 ` Song, Xiongwei
2024-03-31 2:19 ` [PATCH 4/4] mm/slub: don't read slab->cpu_partial_slabs directly xiongwei.song
2024-04-02 9:42 ` Vlastimil Babka
2024-04-03 0:11 ` Song, Xiongwei
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=69089796-9a3b-41a1-9b7c-18c773b96aa2@suse.cz \
--to=vbabka@suse.cz \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--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=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=xiongwei.song@windriver.com \
/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