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.

debugobject: Make it work with deferred page initialization - again

debugobjects uses __GFP_HIGH for allocations as it might be invoked
within locked regions. That worked perfectly fine until v6.18. It still
works correctly when deferred page initialization is disabled and works
by chance when no page allocation is required before deferred page
initialization has completed.

Since v6.18 allocations w/o a reclaim flag cause new_slab() to end up in
alloc_frozen_pages_nolock_noprof(), which returns early when deferred
page initialization has not yet completed. As the deferred page
initialization takes quite a while the debugobject pool is depleted and
debugobjects are disabled.

This can be worked around when PREEMPT_COUNT is enabled as that allows
debugobjects to add __GFP_KSWAPD_RECLAIM to the GFP flags when the context
is preemtible. When PREEMPT_COUNT is disabled the context is unknown and
the reclaim bit can't be set because the caller might hold locks which
might deadlock in the allocator.

In preemptible context the reclaim bit is harmless and not a performance
issue as that's usually invoked from slow path initialization context.

That makes debugobjects depend on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT.

Fixes: af92793e52c3 ("slab: Introduce kmalloc_nolock() and kfree_nolock().")
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Link: https://patch.msgid.link/87pl6gznti.ffs@tglx

+19 -1
+1
lib/Kconfig.debug
··· 723 723 724 724 config DEBUG_OBJECTS 725 725 bool "Debug object operations" 726 + depends on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT 726 727 depends on DEBUG_KERNEL 727 728 help 728 729 If you say Y here, additional code will be inserted into the
+18 -1
lib/debugobjects.c
··· 398 398 399 399 atomic_inc(&cpus_allocating); 400 400 while (pool_should_refill(&pool_global)) { 401 + gfp_t gfp = __GFP_HIGH | __GFP_NOWARN; 401 402 HLIST_HEAD(head); 402 403 403 - if (!kmem_alloc_batch(&head, obj_cache, __GFP_HIGH | __GFP_NOWARN)) 404 + /* 405 + * Allow reclaim only in preemptible context and during 406 + * early boot. If not preemptible, the caller might hold 407 + * locks causing a deadlock in the allocator. 408 + * 409 + * If the reclaim flag is not set during early boot then 410 + * allocations, which happen before deferred page 411 + * initialization has completed, will fail. 412 + * 413 + * In preemptible context the flag is harmless and not a 414 + * performance issue as that's usually invoked from slow 415 + * path initialization context. 416 + */ 417 + if (preemptible() || system_state < SYSTEM_SCHEDULING) 418 + gfp |= __GFP_KSWAPD_RECLAIM; 419 + 420 + if (!kmem_alloc_batch(&head, obj_cache, gfp)) 404 421 break; 405 422 406 423 guard(raw_spinlock_irqsave)(&pool_lock);