Skip to content

Commit 7e23073

Browse files
Hao LiVlastimil Babka (SUSE)
authored andcommitted
mm/slub: introduce helpers for node partial slab state
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> Link: https://patch.msgid.link/20260529035120.81304-2-hao.li@linux.dev Reviewed-by: Harry Yoo (Oracle) <harry@kernel.org> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
1 parent e562904 commit 7e23073

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

mm/slub.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,15 +3521,21 @@ static inline void slab_clear_node_partial(struct slab *slab)
35213521
/*
35223522
* Management of partially allocated slabs.
35233523
*/
3524+
static inline void set_node_partial_state(struct kmem_cache_node *n,
3525+
struct slab *slab)
3526+
{
3527+
slab_set_node_partial(slab);
3528+
n->nr_partial++;
3529+
}
3530+
35243531
static inline void
35253532
__add_partial(struct kmem_cache_node *n, struct slab *slab, enum add_mode mode)
35263533
{
3527-
n->nr_partial++;
35283534
if (mode == ADD_TO_TAIL)
35293535
list_add_tail(&slab->slab_list, &n->partial);
35303536
else
35313537
list_add(&slab->slab_list, &n->partial);
3532-
slab_set_node_partial(slab);
3538+
set_node_partial_state(n, slab);
35333539
}
35343540

35353541
static inline void add_partial(struct kmem_cache_node *n,
@@ -3539,13 +3545,19 @@ static inline void add_partial(struct kmem_cache_node *n,
35393545
__add_partial(n, slab, mode);
35403546
}
35413547

3548+
static inline void clear_node_partial_state(struct kmem_cache_node *n,
3549+
struct slab *slab)
3550+
{
3551+
slab_clear_node_partial(slab);
3552+
n->nr_partial--;
3553+
}
3554+
35423555
static inline void remove_partial(struct kmem_cache_node *n,
35433556
struct slab *slab)
35443557
{
35453558
lockdep_assert_held(&n->list_lock);
35463559
list_del(&slab->slab_list);
3547-
slab_clear_node_partial(slab);
3548-
n->nr_partial--;
3560+
clear_node_partial_state(n, slab);
35493561
}
35503562

35513563
/*
@@ -8266,8 +8278,7 @@ static int __kmem_cache_do_shrink(struct kmem_cache *s)
82668278

82678279
if (free == slab->objects) {
82688280
list_move(&slab->slab_list, &discard);
8269-
slab_clear_node_partial(slab);
8270-
n->nr_partial--;
8281+
clear_node_partial_state(n, slab);
82718282
dec_slabs_node(s, node, slab->objects);
82728283
} else if (free <= SHRINK_PROMOTE_MAX)
82738284
list_move(&slab->slab_list, promote + free - 1);

0 commit comments

Comments
 (0)