mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kmemleak: Do not use off-slab management with SLAB_NOLEAKTRACE
@ 2009-10-14 15:31 Catalin Marinas
  2009-10-15 18:59 ` Pekka Enberg
  0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2009-10-14 15:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Tetsuo Handa, Pekka Enberg, Christoph Lameter

With the slab allocator, if off-slab management is enabled for the
kmem_caches used by kmemleak, it leads to recursive calls into
kmemleak_alloc(). Off-slab management can be triggered by other config
options increasing the slab size, e.g. DEBUG_PAGEALLOC.

Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
 mm/slab.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 7dfa481..646db30 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -2261,9 +2261,11 @@ kmem_cache_create (const char *name, size_t size, size_t align,
 	/*
 	 * Determine if the slab management is 'on' or 'off' slab.
 	 * (bootstrapping cannot cope with offslab caches so don't do
-	 * it too early on.)
+	 * it too early on. Always use on-slab management when
+	 * SLAB_NOLEAKTRACE to avoid recursive calls into kmemleak)
 	 */
-	if ((size >= (PAGE_SIZE >> 3)) && !slab_early_init)
+	if ((size >= (PAGE_SIZE >> 3)) && !slab_early_init &&
+	    !(flags & SLAB_NOLEAKTRACE))
 		/*
 		 * Size is large, assume best to place the slab management obj
 		 * off-slab (should allow better packing of objs).


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

* Re: [PATCH] kmemleak: Do not use off-slab management with SLAB_NOLEAKTRACE
  2009-10-14 15:31 [PATCH] kmemleak: Do not use off-slab management with SLAB_NOLEAKTRACE Catalin Marinas
@ 2009-10-15 18:59 ` Pekka Enberg
  2009-10-16 12:08   ` Catalin Marinas
  0 siblings, 1 reply; 4+ messages in thread
From: Pekka Enberg @ 2009-10-15 18:59 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: linux-kernel, Tetsuo Handa, Christoph Lameter

Hi Catalin,

Catalin Marinas wrote:
> With the slab allocator, if off-slab management is enabled for the
> kmem_caches used by kmemleak, it leads to recursive calls into
> kmemleak_alloc(). Off-slab management can be triggered by other config
> options increasing the slab size, e.g. DEBUG_PAGEALLOC.
> 
> Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Cc: Pekka Enberg <penberg@cs.helsinki.fi>
> Cc: Christoph Lameter <cl@linux-foundation.org>
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

Forcing slabs to use on-slab management is pretty bad from memory 
consumption point of view. Wouldn't it be better to annotate the 
recursive calls somehow?

			Pekka

> ---
>  mm/slab.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/slab.c b/mm/slab.c
> index 7dfa481..646db30 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -2261,9 +2261,11 @@ kmem_cache_create (const char *name, size_t size, size_t align,
>  	/*
>  	 * Determine if the slab management is 'on' or 'off' slab.
>  	 * (bootstrapping cannot cope with offslab caches so don't do
> -	 * it too early on.)
> +	 * it too early on. Always use on-slab management when
> +	 * SLAB_NOLEAKTRACE to avoid recursive calls into kmemleak)
>  	 */
> -	if ((size >= (PAGE_SIZE >> 3)) && !slab_early_init)
> +	if ((size >= (PAGE_SIZE >> 3)) && !slab_early_init &&
> +	    !(flags & SLAB_NOLEAKTRACE))
>  		/*
>  		 * Size is large, assume best to place the slab management obj
>  		 * off-slab (should allow better packing of objs).
> 


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

* Re: [PATCH] kmemleak: Do not use off-slab management with SLAB_NOLEAKTRACE
  2009-10-15 18:59 ` Pekka Enberg
@ 2009-10-16 12:08   ` Catalin Marinas
  2009-10-16 12:17     ` Pekka Enberg
  0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2009-10-16 12:08 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: linux-kernel, Tetsuo Handa, Christoph Lameter

Hi Pekka,

On Thu, 2009-10-15 at 21:59 +0300, Pekka Enberg wrote:
> Catalin Marinas wrote:
> > With the slab allocator, if off-slab management is enabled for the
> > kmem_caches used by kmemleak, it leads to recursive calls into
> > kmemleak_alloc(). Off-slab management can be triggered by other config
> > options increasing the slab size, e.g. DEBUG_PAGEALLOC.
> > 
> > Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> > Cc: Pekka Enberg <penberg@cs.helsinki.fi>
> > Cc: Christoph Lameter <cl@linux-foundation.org>
> > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> 
> Forcing slabs to use on-slab management is pretty bad from memory 
> consumption point of view. Wouldn't it be better to annotate the 
> recursive calls somehow?

The are annotated using SLAB_NOLEAKTRACE but off-slab management uses a
general cachep and we cannot use this flag on them as we end up ignoring
kmalloc allocations. An alternative is to use GFP_ flag rather than a
SLAB_ one to track the recursive calls.

I could also rework the way hooks were added to slab.c but currently
they follow the same places as kmemcheck_slab_alloc and
lockdep_trace_alloc.

Anyway, the kmemleak caches only need off-slab management when
DEBUG_PAGEALLOC is enabled but in this case the memory consumption is
high anyway.

-- 
Catalin


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

* Re: [PATCH] kmemleak: Do not use off-slab management with  SLAB_NOLEAKTRACE
  2009-10-16 12:08   ` Catalin Marinas
@ 2009-10-16 12:17     ` Pekka Enberg
  0 siblings, 0 replies; 4+ messages in thread
From: Pekka Enberg @ 2009-10-16 12:17 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: linux-kernel, Tetsuo Handa, Christoph Lameter

On Fri, Oct 16, 2009 at 3:08 PM, Catalin Marinas
<catalin.marinas@arm.com> wrote:
> On Thu, 2009-10-15 at 21:59 +0300, Pekka Enberg wrote:
>> Catalin Marinas wrote:
>> > With the slab allocator, if off-slab management is enabled for the
>> > kmem_caches used by kmemleak, it leads to recursive calls into
>> > kmemleak_alloc(). Off-slab management can be triggered by other config
>> > options increasing the slab size, e.g. DEBUG_PAGEALLOC.
>> >
>> > Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
>> > Cc: Pekka Enberg <penberg@cs.helsinki.fi>
>> > Cc: Christoph Lameter <cl@linux-foundation.org>
>> > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
>>
>> Forcing slabs to use on-slab management is pretty bad from memory
>> consumption point of view. Wouldn't it be better to annotate the
>> recursive calls somehow?
>
> The are annotated using SLAB_NOLEAKTRACE but off-slab management uses a
> general cachep and we cannot use this flag on them as we end up ignoring
> kmalloc allocations. An alternative is to use GFP_ flag rather than a
> SLAB_ one to track the recursive calls.
>
> I could also rework the way hooks were added to slab.c but currently
> they follow the same places as kmemcheck_slab_alloc and
> lockdep_trace_alloc.
>
> Anyway, the kmemleak caches only need off-slab management when
> DEBUG_PAGEALLOC is enabled but in this case the memory consumption is
> high anyway.

Oh, right, I misread the patch, sorry. Please feel free to put the
patch in kmemleak.git:

Reviewed-by: Pekka Enberg <penberg@cs.helsinki.fi>

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

end of thread, other threads:[~2009-10-16 12:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-14 15:31 [PATCH] kmemleak: Do not use off-slab management with SLAB_NOLEAKTRACE Catalin Marinas
2009-10-15 18:59 ` Pekka Enberg
2009-10-16 12:08   ` Catalin Marinas
2009-10-16 12:17     ` Pekka Enberg

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

Powered by JetHome