[PATCH v2 2/2] mm/slub: introduce helper to decrement partial slab count and clear flag

From: Hao Li

Date: Thu May 28 2026 - 05:54:57 EST


Wrap the partial slab count decrement and slab_clear_node_partial() into
a helper function to reduce code duplication.

Suggested-by: Harry Yoo <harry@xxxxxxxxxx>
Signed-off-by: Hao Li <hao.li@xxxxxxxxx>
---
mm/slub.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index eb60b3da23ff..71305290c8ca 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3539,13 +3539,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);
}

/*
@@ -3786,8 +3792,7 @@ static bool get_partial_node_bulk(struct kmem_cache *s,
if (!first)
first = slab;
last = slab;
- slab_clear_node_partial(slab);
- n->nr_partial--;
+ clear_node_partial_state(n, slab);

total_free += slab_free;
if (total_free >= pc->max_objects)
@@ -8286,8 +8291,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