public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* debugobject: Make it work with deferred page initialization - again
@ 2026-02-07 13:27 Thomas Gleixner
  2026-02-07 19:23 ` Alexei Starovoitov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Thomas Gleixner @ 2026-02-07 13:27 UTC (permalink / raw)
  To: LKML; +Cc: Vlastimil Babka, Peter Zijlstra, Alexei Starovoitov, linux-mm

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@linutronix.de>
---
 lib/Kconfig.debug  |    1 +
 lib/debugobjects.c |   19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -753,6 +753,7 @@ source "mm/Kconfig.debug"
 
 config DEBUG_OBJECTS
 	bool "Debug object operations"
+	depends on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT
 	depends on DEBUG_KERNEL
 	help
 	  If you say Y here, additional code will be inserted into the
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -398,9 +398,26 @@ static void fill_pool(void)
 
 	atomic_inc(&cpus_allocating);
 	while (pool_should_refill(&pool_global)) {
+		gfp_t gfp = __GFP_HIGH | __GFP_NOWARN;
 		HLIST_HEAD(head);
 
-		if (!kmem_alloc_batch(&head, obj_cache, __GFP_HIGH | __GFP_NOWARN))
+		/*
+		 * Allow reclaim only in preemptible context and during
+		 * early boot. If not preemptible, the caller might hold
+		 * locks causing a deadlock in the allocator.
+		 *
+		 * If the reclaim flag is not set during early boot then
+		 * allocations, which happen before deferred page
+		 * initialization has completed, will fail.
+		 *
+		 * In preemptible context the flag is harmless and not a
+		 * performance issue as that's usually invoked from slow
+		 * path initialization context.
+		 */
+		if (preemptible() || system_state < SYSTEM_SCHEDULING)
+			gfp |= __GFP_KSWAPD_RECLAIM;
+
+		if (!kmem_alloc_batch(&head, obj_cache, gfp))
 			break;
 
 		guard(raw_spinlock_irqsave)(&pool_lock);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: debugobject: Make it work with deferred page initialization - again
  2026-02-07 13:27 debugobject: Make it work with deferred page initialization - again Thomas Gleixner
@ 2026-02-07 19:23 ` Alexei Starovoitov
  2026-02-09 11:39 ` Vlastimil Babka
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2026-02-07 19:23 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Vlastimil Babka, Peter Zijlstra, Alexei Starovoitov,
	linux-mm

On Sat, Feb 7, 2026 at 5:27 AM Thomas Gleixner <tglx@kernel.org> wrote:
>
> 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@linutronix.de>

Tricky. The patch makes sense to me.

Acked-by: Alexei Starovoitov <ast@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: debugobject: Make it work with deferred page initialization - again
  2026-02-07 13:27 debugobject: Make it work with deferred page initialization - again Thomas Gleixner
  2026-02-07 19:23 ` Alexei Starovoitov
@ 2026-02-09 11:39 ` Vlastimil Babka
  2026-02-10  7:37 ` Sebastian Andrzej Siewior
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Vlastimil Babka @ 2026-02-09 11:39 UTC (permalink / raw)
  To: Thomas Gleixner, LKML; +Cc: Peter Zijlstra, Alexei Starovoitov, linux-mm

On 2/7/26 14:27, Thomas Gleixner wrote:
> 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@linutronix.de>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  lib/Kconfig.debug  |    1 +
>  lib/debugobjects.c |   19 ++++++++++++++++++-
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -753,6 +753,7 @@ source "mm/Kconfig.debug"
>  
>  config DEBUG_OBJECTS
>  	bool "Debug object operations"
> +	depends on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT
>  	depends on DEBUG_KERNEL
>  	help
>  	  If you say Y here, additional code will be inserted into the
> --- a/lib/debugobjects.c
> +++ b/lib/debugobjects.c
> @@ -398,9 +398,26 @@ static void fill_pool(void)
>  
>  	atomic_inc(&cpus_allocating);
>  	while (pool_should_refill(&pool_global)) {
> +		gfp_t gfp = __GFP_HIGH | __GFP_NOWARN;
>  		HLIST_HEAD(head);
>  
> -		if (!kmem_alloc_batch(&head, obj_cache, __GFP_HIGH | __GFP_NOWARN))
> +		/*
> +		 * Allow reclaim only in preemptible context and during
> +		 * early boot. If not preemptible, the caller might hold
> +		 * locks causing a deadlock in the allocator.
> +		 *
> +		 * If the reclaim flag is not set during early boot then
> +		 * allocations, which happen before deferred page
> +		 * initialization has completed, will fail.
> +		 *
> +		 * In preemptible context the flag is harmless and not a
> +		 * performance issue as that's usually invoked from slow
> +		 * path initialization context.
> +		 */
> +		if (preemptible() || system_state < SYSTEM_SCHEDULING)
> +			gfp |= __GFP_KSWAPD_RECLAIM;
> +
> +		if (!kmem_alloc_batch(&head, obj_cache, gfp))
>  			break;
>  
>  		guard(raw_spinlock_irqsave)(&pool_lock);


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: debugobject: Make it work with deferred page initialization - again
  2026-02-07 13:27 debugobject: Make it work with deferred page initialization - again Thomas Gleixner
  2026-02-07 19:23 ` Alexei Starovoitov
  2026-02-09 11:39 ` Vlastimil Babka
@ 2026-02-10  7:37 ` Sebastian Andrzej Siewior
  2026-02-10 10:51 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
  2026-02-10 13:10 ` tip-bot2 for Thomas Gleixner
  4 siblings, 0 replies; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-02-10  7:37 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: LKML, Vlastimil Babka, Peter Zijlstra, Alexei Starovoitov,
	linux-mm

On 2026-02-07 14:27:05 [+0100], Thomas Gleixner wrote:
> 
> 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@linutronix.de>

Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Sebastian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip: core/debugobjects] debugobject: Make it work with deferred page initialization - again
  2026-02-07 13:27 debugobject: Make it work with deferred page initialization - again Thomas Gleixner
                   ` (2 preceding siblings ...)
  2026-02-10  7:37 ` Sebastian Andrzej Siewior
@ 2026-02-10 10:51 ` tip-bot2 for Thomas Gleixner
  2026-02-10 13:10 ` tip-bot2 for Thomas Gleixner
  4 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Thomas Gleixner @ 2026-02-10 10:51 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Thomas Gleixner, Thomas Gleixner, Sebastian Andrzej Siewior,
	Alexei Starovoitov, Vlastimil Babka, x86, linux-kernel

The following commit has been merged into the core/debugobjects branch of tip:

Commit-ID:     998d5a6164d9fb33224f24b3e36dac0a8b0496e5
Gitweb:        https://git.kernel.org/tip/998d5a6164d9fb33224f24b3e36dac0a8b0496e5
Author:        Thomas Gleixner <tglx@kernel.org>
AuthorDate:    Sat, 07 Feb 2026 14:27:05 +01:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 10 Feb 2026 11:47:35 +01:00

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@linutronix.de>
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
---
 lib/Kconfig.debug  |  1 +
 lib/debugobjects.c | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ba36939..a874146 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -723,6 +723,7 @@ source "mm/Kconfig.debug"
 
 config DEBUG_OBJECTS
 	bool "Debug object operations"
+	depends on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT
 	depends on DEBUG_KERNEL
 	help
 	  If you say Y here, additional code will be inserted into the
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 89a1d67..12f50de 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -398,9 +398,26 @@ static void fill_pool(void)
 
 	atomic_inc(&cpus_allocating);
 	while (pool_should_refill(&pool_global)) {
+		gfp_t gfp = __GFP_HIGH | __GFP_NOWARN;
 		HLIST_HEAD(head);
 
-		if (!kmem_alloc_batch(&head, obj_cache, __GFP_HIGH | __GFP_NOWARN))
+		/*
+		 * Allow reclaim only in preemptible context and during
+		 * early boot. If not preemptible, the caller might hold
+		 * locks causing a deadlock in the allocator.
+		 *
+		 * If the reclaim flag is not set during early boot then
+		 * allocations, which happen before deferred page
+		 * initialization has completed, will fail.
+		 *
+		 * In preemptible context the flag is harmless and not a
+		 * performance issue as that's usually invoked from slow
+		 * path initialization context.
+		 */
+		if (preemptible() || system_state < SYSTEM_SCHEDULING)
+			gfp |= __GFP_KSWAPD_RECLAIM;
+
+		if (!kmem_alloc_batch(&head, obj_cache, gfp))
 			break;
 
 		guard(raw_spinlock_irqsave)(&pool_lock);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [tip: core/debugobjects] debugobject: Make it work with deferred page initialization - again
  2026-02-07 13:27 debugobject: Make it work with deferred page initialization - again Thomas Gleixner
                   ` (3 preceding siblings ...)
  2026-02-10 10:51 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
@ 2026-02-10 13:10 ` tip-bot2 for Thomas Gleixner
  4 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Thomas Gleixner @ 2026-02-10 13:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Thomas Gleixner, Sebastian Andrzej Siewior, Alexei Starovoitov,
	Vlastimil Babka, x86, linux-kernel

The following commit has been merged into the core/debugobjects branch of tip:

Commit-ID:     fd3634312a04f336dcbfb481060219f0cd320738
Gitweb:        https://git.kernel.org/tip/fd3634312a04f336dcbfb481060219f0cd320738
Author:        Thomas Gleixner <tglx@kernel.org>
AuthorDate:    Sat, 07 Feb 2026 14:27:05 +01:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 10 Feb 2026 13:26:19 +01:00

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
---
 lib/Kconfig.debug  |  1 +
 lib/debugobjects.c | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ba36939..a874146 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -723,6 +723,7 @@ source "mm/Kconfig.debug"
 
 config DEBUG_OBJECTS
 	bool "Debug object operations"
+	depends on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT
 	depends on DEBUG_KERNEL
 	help
 	  If you say Y here, additional code will be inserted into the
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 89a1d67..12f50de 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -398,9 +398,26 @@ static void fill_pool(void)
 
 	atomic_inc(&cpus_allocating);
 	while (pool_should_refill(&pool_global)) {
+		gfp_t gfp = __GFP_HIGH | __GFP_NOWARN;
 		HLIST_HEAD(head);
 
-		if (!kmem_alloc_batch(&head, obj_cache, __GFP_HIGH | __GFP_NOWARN))
+		/*
+		 * Allow reclaim only in preemptible context and during
+		 * early boot. If not preemptible, the caller might hold
+		 * locks causing a deadlock in the allocator.
+		 *
+		 * If the reclaim flag is not set during early boot then
+		 * allocations, which happen before deferred page
+		 * initialization has completed, will fail.
+		 *
+		 * In preemptible context the flag is harmless and not a
+		 * performance issue as that's usually invoked from slow
+		 * path initialization context.
+		 */
+		if (preemptible() || system_state < SYSTEM_SCHEDULING)
+			gfp |= __GFP_KSWAPD_RECLAIM;
+
+		if (!kmem_alloc_batch(&head, obj_cache, gfp))
 			break;
 
 		guard(raw_spinlock_irqsave)(&pool_lock);

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-10 13:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-07 13:27 debugobject: Make it work with deferred page initialization - again Thomas Gleixner
2026-02-07 19:23 ` Alexei Starovoitov
2026-02-09 11:39 ` Vlastimil Babka
2026-02-10  7:37 ` Sebastian Andrzej Siewior
2026-02-10 10:51 ` [tip: core/debugobjects] " tip-bot2 for Thomas Gleixner
2026-02-10 13:10 ` tip-bot2 for Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox