From: Hao Li <hao.li@linux.dev>
To: vbabka@kernel.org, harry@kernel.org, akpm@linux-foundation.org
Cc: cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Hao Li <hao.li@linux.dev>
Subject: [PATCH v3 1/2] mm/slub: introduce helpers for node partial slab state
Date: Fri, 29 May 2026 11:50:51 +0800 [thread overview]
Message-ID: <20260529035120.81304-2-hao.li@linux.dev> (raw)
In-Reply-To: <20260529035120.81304-1-hao.li@linux.dev>
Wrap partial slab count inc/dec and flag set/clear into
helper functions to reduce code duplication.
Note that __add_partial() is called locklessly in
early_kmem_cache_node_alloc(), but since there is no such use case for
removal, __remove_partial() does not exist.
Suggested-by: Harry Yoo <harry@kernel.org>
Signed-off-by: Hao Li <hao.li@linux.dev>
---
mm/slub.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index b9f10b869914..45aa0a834f97 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3521,15 +3521,21 @@ static inline void slab_clear_node_partial(struct slab *slab)
/*
* Management of partially allocated slabs.
*/
+static inline void set_node_partial_state(struct kmem_cache_node *n,
+ struct slab *slab)
+{
+ slab_set_node_partial(slab);
+ n->nr_partial++;
+}
+
static inline void
__add_partial(struct kmem_cache_node *n, struct slab *slab, enum add_mode mode)
{
- n->nr_partial++;
if (mode == ADD_TO_TAIL)
list_add_tail(&slab->slab_list, &n->partial);
else
list_add(&slab->slab_list, &n->partial);
- slab_set_node_partial(slab);
+ set_node_partial_state(n, slab);
}
static inline void add_partial(struct kmem_cache_node *n,
@@ -3539,13 +3545,19 @@ static inline void add_partial(struct kmem_cache_node *n,
__add_partial(n, slab, mode);
}
+static inline void clear_node_partial_state(struct kmem_cache_node *n,
+ struct slab *slab)
+{
+ slab_clear_node_partial(slab);
+ n->nr_partial--;
+}
+
static inline void remove_partial(struct kmem_cache_node *n,
struct slab *slab)
{
lockdep_assert_held(&n->list_lock);
list_del(&slab->slab_list);
- slab_clear_node_partial(slab);
- n->nr_partial--;
+ clear_node_partial_state(n, slab);
}
/*
@@ -8271,8 +8283,7 @@ static int __kmem_cache_do_shrink(struct kmem_cache *s)
if (free == slab->objects) {
list_move(&slab->slab_list, &discard);
- slab_clear_node_partial(slab);
- n->nr_partial--;
+ clear_node_partial_state(n, slab);
dec_slabs_node(s, node, slab->objects);
} else if (free <= SHRINK_PROMOTE_MAX)
list_move(&slab->slab_list, promote + free - 1);
--
2.54.0
next prev parent reply other threads:[~2026-05-29 3:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 3:50 [PATCH v3 0/2] mm/slub: batch partial slab list operations Hao Li
2026-05-29 3:50 ` Hao Li [this message]
2026-05-29 3:50 ` [PATCH v3 2/2] mm/slub: detach and reattach partial slabs in batch Hao Li
2026-05-29 8:01 ` [PATCH v3 0/2] mm/slub: batch partial slab list operations Vlastimil Babka (SUSE)
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=20260529035120.81304-2-hao.li@linux.dev \
--to=hao.li@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--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 \
/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