Re: [PATCH 2/4] kmemleak: Handle percpu memory allocation

From: Catalin Marinas
Date: Tue Oct 04 2011 - 05:26:38 EST


On Tue, Oct 04, 2011 at 10:13:14AM +0100, Tejun Heo wrote:
> On Tue, Oct 04, 2011 at 10:04:46AM +0100, Catalin Marinas wrote:
> > > The percpu part looks fine to me but I don't know how kmemleak works
> > > to judge whether the kmemleak part is okay or not. This just avoids
> > > false positives from slab and would still require bumping up the early
> > > log memory as # of cpus increases, right?
> >
> > No, there is only one kmemleak call for each __percpu pointer (to the
> > specific kmemleak_*_percpu function). The kmemleak expands the percpu
> > pointer into corresponding blocks for each cpu but the early log only
> > stores a single call.
>
> Hmmm... but the following definitely seems O(#PCPU_ALLOCS * #CPUS)?
> What am I missing?
>
> +/*
> + * Log an early allocated block and populate the stack trace.
> + */
> +static void early_alloc_percpu(struct early_log *log)
> +{
> + unsigned int cpu;
> + const void __percpu *ptr = log->ptr;
> +
> + for_each_possible_cpu(cpu) {
> + log->ptr = per_cpu_ptr(ptr, cpu);
> + early_alloc(log);
> + }
> +}

Before kmemleak is initialised we still get memory allocations that
kmemleak stores in an early_log buffer (via the log_early() function
called from kmemleak_alloc_percpu). Later when kmemleak has all the data
structures in place, the kmemleak_init() function goes through the
early_log array and replays the previously recorded requests. The
early_alloc_percpu() function is used during early_log replaying and it
indeed registers every percpu memory block but the early_log is always
O(#PCPU_ALLOCS).

The reason we don't call kmemleak_alloc_percpu() directly during
replaying is that early_alloc() also copies the previously recorded
stack trace into the newly created object (otherwise all early
allocations would be shown as done by kmemleak_init).

Thanks.

--
Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/