Skip to content

Commit eecd7cb

Browse files
committed
slab: fix slab accounting imbalance due to defer_deactivate_slab()
Since commit af92793 ("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: af92793 ("slab: Introduce kmalloc_nolock() and kfree_nolock().") Link: https://patch.msgid.link/[email protected] Reviewed-by: Harry Yoo <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 6ed8bfd commit eecd7cb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mm/slub.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,7 +3422,6 @@ static void *alloc_single_from_new_slab(struct kmem_cache *s, struct slab *slab,
34223422

34233423
if (!allow_spin && !spin_trylock_irqsave(&n->list_lock, flags)) {
34243424
/* Unlucky, discard newly allocated slab */
3425-
slab->frozen = 1;
34263425
defer_deactivate_slab(slab, NULL);
34273426
return NULL;
34283427
}
@@ -6471,9 +6470,12 @@ static void free_deferred_objects(struct irq_work *work)
64716470
struct slab *slab = container_of(pos, struct slab, llnode);
64726471

64736472
#ifdef CONFIG_SLUB_TINY
6474-
discard_slab(slab->slab_cache, slab);
6473+
free_slab(slab->slab_cache, slab);
64756474
#else
6476-
deactivate_slab(slab->slab_cache, slab, slab->flush_freelist);
6475+
if (slab->frozen)
6476+
deactivate_slab(slab->slab_cache, slab, slab->flush_freelist);
6477+
else
6478+
free_slab(slab->slab_cache, slab);
64776479
#endif
64786480
}
64796481
}

0 commit comments

Comments
 (0)