From: Catalin Marinas <catalin.marinas@arm.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: penberg@cs.helsinki.fi, linux-kernel@vger.kernel.org
Subject: Re: How to analyze kmemleak message?
Date: Mon, 23 Feb 2009 12:20:34 +0000 [thread overview]
Message-ID: <1235391634.14987.61.camel@pc1117.cambridge.arm.com> (raw)
In-Reply-To: <200902232029.HGI04666.FLOOFSVFJtHQMO@I-love.SAKURA.ne.jp>
On Mon, 2009-02-23 at 20:29 +0900, Tetsuo Handa wrote:
> Catalin Marinas wrote:
> > This object can no longer be found to be referred by other objects or
> > from the data section, hence it is assumed to be a leak (it could, as
> > well, be a false positive, transient or not).
> Kmemleak scans all data section for addresses returned by kmalloc() etc.
>
> void *p1;
>
> void foo(void)
> {
> void *p2 = kmalloc(1, GFP_KERNEL);
> p1 = kmalloc(1, GFP_KERNEL);
> }
>
> "p1" will be reported by default.
p1 won't be reported as a leak because it is a global variable and the
data section is scanned.
> To report "p2", we need to write "stack=on" to /sys/kernel/debug/kmemleak .
It's the opposite - p2 will be reported as leak by default (stack=off)
unless you enable the stack scanning (stack=on). Note that in the above
case, even if you scan the stacks, once foo() finished the data on the
stack may be overridden by other function calls and p2 will be reported
as a leak.
> > Basically, you need check
> > where the pointer returned by kmalloc/kmem_cache_alloc etc. should be
> > stored and whether it can still be referred from that place (or a
> > different one) later.
> >
> > Kmemleak tries to avoid the reporting of transient leaks by only
> > reporting objects with a life time of more than 5 seconds.
> kjournald's commit interval (default to 5 sec?) + a few seconds
> might be better. (No reason. Just my feeling.)
I don't think it will make any difference but I may try to increase this
if I get too many transient leaks reported.
> I have a question. My module uses kmalloc(PATH_MAX, GFP_KERNEL) which
> won't be released by kfree(). I count up how many bytes are allocated but
> I don't want kmemleak to report such memory as memory leaks.
> Can I do so by
>
> void bar(void)
> {
> static void *p;
> if (!p) {
> p = kmalloc(PATH_MAX, GFP_KERNEL);
> kmemleak_not_leak(p);
> }
> ...
> }
>
> (or kmemleak_ignore() (which one to use and how to use))?
I don't think you need to do anything here. Since p is a static local
variable, isn't it placed in a data section somewhere (and automatically
scanned by kmemleak)?
FYI, kmemleak_ignore() is meant for objects which aren't leaks and which
don't need to be scanned for pointers to other objects (i.e. the code
sections in a module). kmemleak_not_leak() is meant for objects which
are reported as leaks but are known not to be (i.e. the pointer is
stored in a place that kmemleak doesn't scan or the pointer value is
modified before storing or reading) and they should be scanned for
pointers to other objects.
--
Catalin
next prev parent reply other threads:[~2009-02-23 12:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-23 8:24 Tetsuo Handa
2009-02-23 9:40 ` Pekka Enberg
2009-02-23 10:45 ` Catalin Marinas
2009-02-23 11:29 ` Tetsuo Handa
2009-02-23 12:20 ` Catalin Marinas [this message]
2009-02-23 12:59 ` Tetsuo Handa
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=1235391634.14987.61.camel@pc1117.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
/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®