Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

slab: fix slab accounting imbalance due to defer_deactivate_slab()

Since commit af92793e52c3 ("slab: Introduce kmalloc_nolock() and
kfree_nolock().") there's a possibility in alloc_single_from_new_slab()
that we discard the newly allocated slab if we can't spin and we fail to
trylock. As a result we don't perform inc_slabs_node() later in the
function. Instead we perform a deferred deactivate_slab() which can
either put the unacounted slab on partial list, or discard it
immediately while performing dec_slabs_node(). Either way will cause an
accounting imbalance.

Fix this by not marking the slab as frozen, and using free_slab()
instead of deactivate_slab() for non-frozen slabs in
free_deferred_objects(). For CONFIG_SLUB_TINY, that's the only possible
case. By not using discard_slab() we avoid dec_slabs_node().

Fixes: af92793e52c3 ("slab: Introduce kmalloc_nolock() and kfree_nolock().")
Link: https://patch.msgid.link/20251023-fix-slab-accounting-v2-1-0e62d50986ea@suse.cz
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

+5 -3
+5 -3
mm/slub.c
··· 3422 3422 3423 3423 if (!allow_spin && !spin_trylock_irqsave(&n->list_lock, flags)) { 3424 3424 /* Unlucky, discard newly allocated slab */ 3425 - slab->frozen = 1; 3426 3425 defer_deactivate_slab(slab, NULL); 3427 3426 return NULL; 3428 3427 } ··· 6470 6471 struct slab *slab = container_of(pos, struct slab, llnode); 6471 6472 6472 6473 #ifdef CONFIG_SLUB_TINY 6473 - discard_slab(slab->slab_cache, slab); 6474 + free_slab(slab->slab_cache, slab); 6474 6475 #else 6475 - deactivate_slab(slab->slab_cache, slab, slab->flush_freelist); 6476 + if (slab->frozen) 6477 + deactivate_slab(slab->slab_cache, slab, slab->flush_freelist); 6478 + else 6479 + free_slab(slab->slab_cache, slab); 6476 6480 #endif 6477 6481 } 6478 6482 }