All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Tejun Heo <tj@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Huajun Li <huajun.li.lee@gmail.com>,
	Christoph Lameter <cl@linux-foundation.org>
Subject: Re: [PATCH 2/4] kmemleak: Handle percpu memory allocation
Date: Fri, 30 Sep 2011 09:37:06 +0100	[thread overview]
Message-ID: <20110930083706.GB22300@e102109-lin.cambridge.arm.com> (raw)
In-Reply-To: <20110929192818.GB10425@mtj.dyndns.org>

Hi Tejun,

On Thu, Sep 29, 2011 at 08:28:18PM +0100, Tejun Heo wrote:
> On Thu, Sep 29, 2011 at 12:02:28PM +0100, Catalin Marinas wrote:
> > This patch adds kmemleak callbacks from the percpu allocator, reducing a
> > number of false positives caused by kmemleak not scanning such memory
> > blocks. The percpu chunks are never reported as leaks because of current
> > kmemleak limitations with the __percpu pointer not pointing directly to
> > the actual chunks.
> ...
> > @@ -801,7 +804,16 @@ area_found:
> >  	mutex_unlock(&pcpu_alloc_mutex);
> >  
> >  	/* return address relative to base address */
> > -	return __addr_to_pcpu_ptr(chunk->base_addr + off);
> > +	ptr = __addr_to_pcpu_ptr(chunk->base_addr + off);
> > +
> > +	/*
> > +	 * Percpu allocations are currently reported as leaks (kmemleak false
> > +	 * positives). To avoid this, just set min_count to 0.
> > +	 */
> > +	for_each_possible_cpu(cpu)
> > +		kmemleak_alloc(per_cpu_ptr(ptr, cpu), size, 0, GFP_KERNEL);
> > +
> > +	return ptr;
> 
> I'm pretty ignorant about kmemleak but it scans memories looking for
> references to allocated objects, right?  There currently is no way for
> such scanner to tell a percpu pointer in memory from a regular pointer
> making it impossible to track percpu objects properly from kmemleak.
> If my understanding is correct, I don't see much point in tracking
> each percpu alloc/free.  Why not just mark all pages taken by percpu
> allocator as untrackable?

That's pretty much the current behaviour (apart from embedded chunk).
The problem is that percpu blocks may contain references to other memory
blocks and if they are not found it leads to false positives. So rather
than marking each individual false positive as such, we could add
tracking support to percpu allocations.

> If we want to track percpu memory leak properly, I think we'll need
> more invasive changes.  If kmemleak is enabled, we can offset percpu
> pointer so that the scanner can tell percpu pointers and then kmemleak
> should properly account for all percpu areas pointed to by the percpu
> pointer.

Or we could just extend the kmemleak API to tell it's a percpu pointer
(e.g. kmemleak_alloc_percpu).

> Hmmm... or, alternatively, we can make kmemleak only track
> allocations for the first possible cpu and ignore all the rest and
> modify percpu such that percpu pointer points to the actual address of
> the first cpu if kmemleak is enabled.

This would solve the kmemleak issues with overlapping memory blocks.
I'll try to come up with a patch and see how feasible it is.

Thanks.

-- 
Catalin

  reply	other threads:[~2011-09-30  8:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-29 11:02 [PATCH 0/4] Kmemleak patches for -next Catalin Marinas
2011-09-29 11:02 ` [PATCH 1/4] kmemleak: Show where early_log issues come from Catalin Marinas
2011-09-29 11:02 ` [PATCH 2/4] kmemleak: Handle percpu memory allocation Catalin Marinas
2011-09-29 11:56   ` Eric Dumazet
2011-09-29 17:17     ` Catalin Marinas
2011-09-29 17:57       ` Christoph Lameter
2011-09-29 19:28   ` Tejun Heo
2011-09-30  8:37     ` Catalin Marinas [this message]
2011-10-03 15:21     ` Catalin Marinas
2011-10-03 16:14       ` Christoph Lameter
2011-10-04  7:59       ` Tejun Heo
2011-10-04  9:04         ` Catalin Marinas
2011-10-04  9:13           ` Tejun Heo
2011-10-04  9:26             ` Catalin Marinas
2011-10-04 16:59               ` Tejun Heo
2011-10-04 17:06                 ` Catalin Marinas
2011-09-29 11:02 ` [PATCH 3/4] kmemleak: When the early log buffer is exceeded, report the actual number Catalin Marinas
2011-09-29 11:02 ` [PATCH 4/4] kmemleak: Report previously found leaks even after an error Catalin Marinas
2011-10-04 17:45   ` Nick Bowler
2011-10-04 20:50     ` Catalin Marinas
2011-10-04 21:14       ` Nick Bowler
2011-10-24 18:57         ` Nick Bowler

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=20110930083706.GB22300@e102109-lin.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=cl@linux-foundation.org \
    --cc=huajun.li.lee@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.