Possible kmemleak issue, but I'm confused
Hi Catalin,
I wasn't sure what list to post this to. Is there a list where kmemleak is predominately discussed, outside of LKML?
I have a "fix" for kmemleak that we are using in Sony's Linux kernel (circa 2.6.29), that I wanted to discuss with you and possibly push upstream. However, I'm confused about the status of kmemleak in current mainline.
In our patch set against 2.6.29, there are some kmemleak instrumentation hooks in kernel/module.c, in the routines percpu_modalloc and percpu_modfree. I thought that all of kmemleak got mainlined in 2.6.34, but I don't see these hooks in Linus' latest tree.
I found the commit that we are modifying, in your tree at:
http://git.kernel.org/?p=linux/kernel/git/cmarinas/linux-2.6-cm.git;a=commitdiff;h=4f2294b6dc88d99295230d97fef2c9863cec44c3
What is the status of this patch relative to linux-next or Linus' tree?
Here's the issue we found (I'm parroting this from some developers in Japan who are actually found the issue, so please forgive me if I mangle the explanation):
The kmemleak_alloc and kmemleak_free in percpu_modalloc and percpu_modfree routines are capturing allocations/frees of percpu data areas when a module is loaded or unloaded, respectively. However, on some platforms, the percpu memory area is instantiated by the bootmem allocator, and the memory in question is already tracked by kmemleak.
When a module is loaded and unloaded multiple times, it causes problems for kmemleak. The bug report I'm looking at says "kmemleak stops", but I don't know what that means. I can ask for clarification if needed.
Have you heard of this issue?
Our solution was just to make these specific calls to kmemleak_alloc and kmemleak_free (in module.c) compile-time configurable. I suspect that there is a better way to do this -- possibly by detecting or noting that this situation exists for certain platforms, and avoiding it without specific user interaction.
Anyway, any help you can provide would be appreciated.
I thought I'd contact you and clarify the situation before trying to push our existing patch, or reimplement it based on my current understanding.
Thanks,
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Network Entertainment
=============================
Hi Tim,
Quoted 2 lines · Tim Bird
I wasn't sure what list to post this to. Is there a list where kmemleak is predominately discussed, outside of LKML?
There isn't much traffic on kmemleak apart from people reporting its output. So LKML is the right list for this (it was always discussed on LKML).
Quoted 4 lines
I have a "fix" for kmemleak that we are using in Sony's Linux kernel (circa 2.6.29), that I wanted to discuss with you and possibly push upstream. However, I'm confused about the status of kmemleak in current mainline.
Kmemleak is fully functional in the current mainline. From time to time we need to plug some false positive but otherwise it is fine.
Quoted 11 lines
In our patch set against 2.6.29, there are some kmemleak instrumentation hooks in
kernel/module.c, in the routinespercpu_modallocandpercpu_modfree. I thought that all of kmemleak got mainlined in 2.6.34, but I don't see these hooks in Linus' latest tree.I found the commit that we are modifying, in your tree at:
http://git.kernel.org/?p=linux/kernel/git/cmarinas/linux-2.6-cm.git;a=commitdiff;h=4f2294b6dc88d99295230d97fef2c9863cec44c3What is the status of this patch relative to linux-next or Linus' tree?
This patch was merged in 2.6.31-rc1 but parts of it were later dropped in 2.6.34-rc1 (commit 23fb064b) when Tejun removed the legacy percpu allocator. The new percpu allocator in mm/percpu.c uses standard allocation methods like alloc_bootmem or kzalloc and kmemleak handles these already, so no need for extra code in kernel/module.c.
Quoted 6 lines
The
kmemleak_allocandkmemleak_freeinpercpu_modallocandpercpu_modfreeroutines are capturing allocations/frees of percpu data areas when a module is loaded or unloaded, respectively. However, on some platforms, the percpu memory area is instantiated by the bootmem allocator, and the memory in question is already tracked by kmemleak.
I only tested kmemleak on ARM and x86 and it was fine at the time. Anyway, it currently doesn't matter since we dropped this kmemleak callback entirely from percpu_modalloc/modfree.
Quoted 4 lines
When a module is loaded and unloaded multiple times, it causes problems for kmemleak. The bug report I'm looking at says "kmemleak stops", but I don't know what that means. I can ask for clarification if needed.
If the kmemleak gets called with a block already registered, it prints a warning and disables itself.
Quoted 1 line
Have you heard of this issue?
No but it is possible with older kernels.
Quoted 5 lines
Our solution was just to make these specific calls to
kmemleak_allocandkmemleak_free(inmodule.c) compile-time configurable. I suspect that there is a better way to do this -- possibly by detecting or noting that this situation exists for certain platforms, and avoiding it without specific user interaction.
For the 2.6.29 kernel (not mainline), you could have it compile-tome configurable. Another option would be to hack create_object() in mm/kmemleak.c to not call kmemleak_stop("Cannot insert ..."), though this method could potentially hide other problems with kmemleak callbacks.
Signature · 1 line
Catalin
Quoted 8 lines · Catalin Marinas
Quoted 2 lines
What is the status of this patch relative to linux-next or Linus' tree?
This patch was merged in 2.6.31-rc1 but parts of it were later dropped in 2.6.34-rc1 (commit
23fb064b) when Tejun removed the legacy percpu allocator. The new percpu allocator inmm/percpu.cuses standard allocation methods likealloc_bootmemor kzalloc and kmemleak handles these already, so no need for extra code inkernel/module.c.
OK. This is just the information I needed. Thanks.
Quoted 11 lines
Quoted 5 lines
Our solution was just to make these specific calls to
kmemleak_allocandkmemleak_free(inmodule.c) compile-time configurable. I suspect that there is a better way to do this -- possibly by detecting or noting that this situation exists for certain platforms, and avoiding it without specific user interaction.For the 2.6.29 kernel (not mainline), you could have it compile-time configurable. Another option would be to hack
create_object()inmm/kmemleak.cto not callkmemleak_stop("Cannot insert ..."), though this method could potentially hide other problems with kmemleak callbacks.
We'll stick with our compile-time option, then, and it sounds like when we upgrade our kernel version we won't need to worry about this issue.
Thanks very much! kmemleak is cool. :-)
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Network Entertainment
=============================