Skip to content

Commit 40fd0ac

Browse files
committed
slub: avoid list_lock contention from __refill_objects_any()
Kernel test robot has reported a regression in the patch "slab: refill sheaves from all nodes". When taken in isolation like this, there is indeed a tradeoff - we prefer to use remote objects prior to allocating new local slabs. It is replicating a behavior that existed before sheaves for replenishing cpu (partial) slabs - now called get_from_any_partial() to allocate a single object. So the possibility of allocating remote objects is intended even if remote accesses are then slower. But the profiles in the report also suggested a contention on the list_lock spinlock. And that's something we can try to avoid without much tradeoff - if someone else has the spin_lock, it's more likely they are allocating from the node than freeing to it, so we can skip it even if it means allocating a new local slab - contributing to that lock's contention isn't worth it. It should not result in partial slabs accumulating on the remote node. Thus add an allow_spin parameter to __refill_objects_node() and get_partial_node_bulk() to make the attempts from __refill_objects_any() use only a trylock. Reported-by: kernel test robot <oliver.sang@intel.com> Link: https://lore.kernel.org/oe-lkp/202601132136.77efd6d7-lkp@intel.com Link: https://patch.msgid.link/20260129-b4-refill_any_trylock-v1-1-de7420b25840@suse.cz Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent 6f19121 commit 40fd0ac

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

mm/slub.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,7 +3378,8 @@ static inline bool pfmemalloc_match(struct slab *slab, gfp_t gfpflags);
33783378

33793379
static bool get_partial_node_bulk(struct kmem_cache *s,
33803380
struct kmem_cache_node *n,
3381-
struct partial_bulk_context *pc)
3381+
struct partial_bulk_context *pc,
3382+
bool allow_spin)
33823383
{
33833384
struct slab *slab, *slab2;
33843385
unsigned int total_free = 0;
@@ -3390,7 +3391,10 @@ static bool get_partial_node_bulk(struct kmem_cache *s,
33903391

33913392
INIT_LIST_HEAD(&pc->slabs);
33923393

3393-
spin_lock_irqsave(&n->list_lock, flags);
3394+
if (allow_spin)
3395+
spin_lock_irqsave(&n->list_lock, flags);
3396+
else if (!spin_trylock_irqsave(&n->list_lock, flags))
3397+
return false;
33943398

33953399
list_for_each_entry_safe(slab, slab2, &n->partial, slab_list) {
33963400
struct freelist_counters flc;
@@ -6544,7 +6548,8 @@ EXPORT_SYMBOL(kmem_cache_free_bulk);
65446548

65456549
static unsigned int
65466550
__refill_objects_node(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int min,
6547-
unsigned int max, struct kmem_cache_node *n)
6551+
unsigned int max, struct kmem_cache_node *n,
6552+
bool allow_spin)
65486553
{
65496554
struct partial_bulk_context pc;
65506555
struct slab *slab, *slab2;
@@ -6556,7 +6561,7 @@ __refill_objects_node(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int mi
65566561
pc.min_objects = min;
65576562
pc.max_objects = max;
65586563

6559-
if (!get_partial_node_bulk(s, n, &pc))
6564+
if (!get_partial_node_bulk(s, n, &pc, allow_spin))
65606565
return 0;
65616566

65626567
list_for_each_entry_safe(slab, slab2, &pc.slabs, slab_list) {
@@ -6650,7 +6655,8 @@ __refill_objects_any(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int min
66506655
n->nr_partial <= s->min_partial)
66516656
continue;
66526657

6653-
r = __refill_objects_node(s, p, gfp, min, max, n);
6658+
r = __refill_objects_node(s, p, gfp, min, max, n,
6659+
/* allow_spin = */ false);
66546660
refilled += r;
66556661

66566662
if (r >= min) {
@@ -6691,7 +6697,8 @@ refill_objects(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int min,
66916697
return 0;
66926698

66936699
refilled = __refill_objects_node(s, p, gfp, min, max,
6694-
get_node(s, local_node));
6700+
get_node(s, local_node),
6701+
/* allow_spin = */ true);
66956702
if (refilled >= min)
66966703
return refilled;
66976704

0 commit comments

Comments
 (0)