mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Catalin Marinas" <catalin.marinas@gmail.com>
To: "Ingo Molnar" <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2.6.20-rc1 00/10] Kernel memory leak detector 0.13
Date: Sat, 16 Dec 2006 23:39:30 +0000	[thread overview]
Message-ID: <b0943d9e0612161539s50fd6086v9246d6b0ffac949a@mail.gmail.com> (raw)
In-Reply-To: <20061216165738.GA5165@elte.hu>

Hi Ingo,

On 16/12/06, Ingo Molnar <mingo@elte.hu> wrote:
> FYI, i'm working on integrating kmemleak into -rt. Firstly, i needed the
> fixes below when applying it ontop of 2.6.19-rt15.

Do you need these fixes to avoid a compiler error? If yes, this is
caused by a bug in gcc-4.x. The kmemleak container_of macro has
protection for non-constant offsets passed to container_of but the
faulty gcc always returns true for builtin_contant_p, even when this
is not the case. Previous versions (3.4) or one of the latest 4.x gcc
don't have this bug.

I wouldn't extend kmemleak to work around a gcc bug which was already fixed.

> Secondly, i'm wondering about the following recursion:
>
>  [<c045a7e1>] rt_spin_lock_slowlock+0x98/0x1dc
>  [<c045b16b>] rt_spin_lock+0x13/0x4b
>  [<c018f155>] kfree+0x3a/0xce
>  [<c0192e79>] hash_delete+0x58/0x5f
>  [<c019309b>] memleak_free+0xe9/0x1e6
>  [<c018ed2e>] __cache_free+0x27/0x414
>  [<c018f1d0>] kfree+0xb5/0xce
>  [<c02788dd>] acpi_ns_get_node+0xb1/0xbb
>  [<c02772fa>] acpi_ns_root_initialize+0x30f/0x31d
>  [<c0280194>] acpi_initialize_subsystem+0x58/0x87
>  [<c06a4641>] acpi_early_init+0x4f/0x12e
>  [<c06888bc>] start_kernel+0x41b/0x44b
>
> kfree() within kfree() ... this probably works on the upstream SLAB
> allocator but makes it pretty nasty to sort out SLAB locking in -rt.

I test kmemleak with lockdep enabled but I eliminated all the
dependencies on the vanilla kernel. When kfree(hnode) is called (in
hash_delete), no kmemleak locks are held and hence no dependency on
the kmemleak locks (since kmemleak is protected against re-entrance).
My understanding is that slab __cache_free is re-entrant anyway
(noticed this when using radix-tree instead of hash in kmemleak and
got some lockdep reports on l3->list_lock and memleak_lock) and
calling it again from kmemleak doesn't seem to have any problem on the
vanilla kernel.

In the -rt kernel, is there any protection against a re-entrant
__cache_free (via cache_flusharray -> free_block -> slab_destroy) or
this is not needed?

> Wouldnt it be better to just preallocate the hash nodes, like lockdep
> does, to avoid conceptual nesting? Basically debugging infrastructure
> should rely on other infrastructure as little as possible.

It would indeed be better to avoid using the slab infrastructure (and
not worry about kmemleak re-entrance and lock dependecies). I'll have
a look on how this is done in lockdep since the preallocation size
isn't known. There are also the memleak_object structures that need to
be allocated/freed. To avoid any locking dependencies, I ended up
delaying the memleak_object structures freeing in an RCU manner. It
might work if I do the same with the hash nodes.

> also, the number of knobs in the Kconfig is quite large:

I had some reasons and couldn't find a unified solution, but probably
only for one or two if them:

>  CONFIG_DEBUG_MEMLEAK=y
>  CONFIG_DEBUG_MEMLEAK_HASH_BITS=16

For my limited configurations (an x86 laptop and several ARM embedded
platforms), 16 bits were enough. I'm not sure this is enough on a
server machine for example.

>  CONFIG_DEBUG_MEMLEAK_TRACE_LENGTH=4

I thought this is a user preference. I could hard-code it to 16.
What's the trace length used by lockdep?

>  CONFIG_DEBUG_MEMLEAK_PREINIT_OBJECTS=512

I can probably hard-code this as well. This is a buffer to temporary
store memory allocations before kmemleak is fully initialised.
Kmemleak gets initialised quite early in the start_kernel function and
shouldn't be that different in other kernel configurations.

>  CONFIG_DEBUG_MEMLEAK_SECONDARY_ALIASES=y
>  CONFIG_DEBUG_MEMLEAK_TASK_STACKS=y

These could be eliminated as well.

There are also:

CONFIG_DEBUG_MEMLEAK_REPORT_THLD - can be removed
CONFIG_DEBUG_MEMLEAK_REPORTS_NR - can be removed
CONFIG_DEBUG_KEEP_INIT - this might be useful for other tools that
store the backtrace and display it at a later time. Could be made more
generic.

> plus the Kconfig dependency on SLAB_DEBUG makes it less likely for
> people to spontaneously try kmemleak. I'd suggest to offer KMEMLEAK
> unconditionally (when KERNEL_DEBUG is specified) and simply select
> SLAB_DEBUG.

I just followed the DEBUG_SLAB_LEAK configuration but I don't have any
problem with making it more visible.

Thanks for your comments.

-- 
Catalin

  reply	other threads:[~2006-12-16 23:39 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-16 15:34 Catalin Marinas
2006-12-16 15:34 ` [PATCH 2.6.20-rc1 01/10] Base support for kmemleak Catalin Marinas
2006-12-16 15:34 ` [PATCH 2.6.20-rc1 02/10] Kmemleak documentation Catalin Marinas
2006-12-16 15:34 ` [PATCH 2.6.20-rc1 03/10] Add the memory allocation/freeing hooks for kmemleak Catalin Marinas
2006-12-16 15:34 ` [PATCH 2.6.20-rc1 04/10] Modules support " Catalin Marinas
2006-12-16 15:35 ` [PATCH 2.6.20-rc1 05/10] Add kmemleak support for i386 Catalin Marinas
2006-12-16 15:35 ` [PATCH 2.6.20-rc1 06/10] Add kmemleak support for ARM Catalin Marinas
2006-12-16 15:35 ` [PATCH 2.6.20-rc1 07/10] Remove some of the kmemleak false positives Catalin Marinas
2006-12-16 15:35 ` [PATCH 2.6.20-rc1 08/10] Keep the __init functions after initialization Catalin Marinas
2006-12-16 15:35 ` [PATCH 2.6.20-rc1 09/10] Testing module for kmemleak Catalin Marinas
2006-12-16 15:36 ` [PATCH 2.6.20-rc1 10/10] Update the MAINTAINERS file " Catalin Marinas
2006-12-16 16:57 ` [PATCH 2.6.20-rc1 00/10] Kernel memory leak detector 0.13 Ingo Molnar
2006-12-16 23:39   ` Catalin Marinas [this message]
2006-12-17  8:58     ` Ingo Molnar
2006-12-17  9:09       ` Ingo Molnar
2006-12-17  9:28         ` Ingo Molnar
2006-12-17  9:41           ` Ingo Molnar
2006-12-17  9:49             ` Ingo Molnar
2006-12-17 12:05             ` Catalin Marinas
2006-12-27 16:14             ` Catalin Marinas
2006-12-27 16:23               ` Arjan van de Ven
2006-12-27 16:30                 ` Catalin Marinas
2006-12-27 16:47               ` Ingo Molnar
2006-12-27 16:56                 ` Ingo Molnar
2006-12-27 17:02                 ` Catalin Marinas
2006-12-17 11:58           ` Catalin Marinas
2006-12-17 13:28             ` Ingo Molnar
2006-12-17 11:09       ` Mike Galbraith
2006-12-17 23:05       ` Catalin Marinas
2006-12-18  7:29         ` Ingo Molnar
2006-12-18 10:28           ` Catalin Marinas
2006-12-18 11:21             ` Ingo Molnar
2006-12-18 12:26               ` Catalin Marinas
2006-12-18 19:56                 ` Ingo Molnar
2006-12-19  9:36                   ` Catalin Marinas
2006-12-27 13:52           ` Catalin Marinas
2006-12-27 15:08             ` Ingo Molnar
2006-12-27 17:30               ` Ingo Molnar
2006-12-28  0:15                 ` Catalin Marinas
2006-12-28  9:44                   ` Ingo Molnar
2006-12-28 11:50                     ` Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b0943d9e0612161539s50fd6086v9246d6b0ffac949a@mail.gmail.com \
    --to=catalin.marinas@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®