<div>Sankar and All,</div>
<div> </div>
<div>I followed blow investigation on detecting kernel memory leak. I got different o/p which is different from yours shown.</div>
<div>ie, 4 and 5 lines are addresses in the backtrace and not function names.</div>
<div><a href="http://psankar.blogspot.com/2010/11/detecting-memory-leaks-in-kernel.html">http://psankar.blogspot.com/2010/11/detecting-memory-leaks-in-kernel.html</a></div>
<div> </div>
<div> comm "insmod", pid 1559, jiffies 4294961804 (age 229.610s)<br> hex dump (first 32 bytes):<br> fa 3e 00 00 00 00 00 00 92 5a 00 00 00 00 00 00 .>.......Z......<br> 0a 00 00 00 12 00 00 00 3c 38 00 00 00 00 00 00 ........<8......<br>
backtrace:<br> [<ffffffff8156eb1d>] kmemleak_alloc+0x2d/0x60<br> [<ffffffff81152469>] __vmalloc_node+0xc9/0xe0<br> [<ffffffff8115280c>] vmalloc+0x2c/0x30<br> [<ffffffffa0099047>] 0xffffffffa0099047<br>
[<ffffffffa009906c>] 0xffffffffa009906c<br> [<ffffffff8100204c>] do_one_initcall+0x3c/0x1a0<br> [<ffffffff810cea1b>] sys_init_module+0xbb/0x200<br> [<ffffffff81041072>] system_call_fastpath+0x16/0x1b<br>
[<ffffffffffffffff>] 0xffffffffffffffff<br><br><br></div>
<div class="gmail_quote">On Wed, Oct 27, 2010 at 12:24 PM, Sankar P <span dir="ltr"><<a href="mailto:sankar.curiosity@gmail.com">sankar.curiosity@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi Dave, Rajat, Mulyadi and everyone,<br><br><br>Thanks for your pointers.<br><br>Now I removed the "static __init" from the hello_init function and I<br>
got an output of:<br><br>unreferenced object 0xf9042000 (size 512):<br> comm "insmod", pid 12068, jiffies 13995923 (age 51.096s)<br>
<div class="im"> hex dump (first 32 bytes):<br></div> 6f 64 75 6c 65 00 00 00 00 00 00 2e 73 79 6d 74 odule.......symt<br> 61 62 00 2e 73 74 72 74 61 62 00 2e 73 68 73 74 ab..strtab..shst<br>
<div class="im"> backtrace:<br> [<c10b0001>] create_object+0x114/0x1db<br> [<c148b4d0>] kmemleak_alloc+0x21/0x3f<br> [<c10a43e9>] __vmalloc_node+0x83/0x90<br> [<c10a44b9>] vmalloc+0x1c/0x1e<br>
</div> [<f9036021>] init_module+0x21/0x2f [hello_kernel]<br>
<div class="im"> [<c1001226>] do_one_initcall+0x71/0x113<br> [<c1056c48>] sys_init_module+0x1241/0x1430<br> [<c100284c>] sysenter_do_call+0x12/0x22<br> [<ffffffff>] 0xffffffff<br><br><br></div>
And, if I create a new function named myfunc and do my allocations<br>inside that function (instead of the init function), even though I<br>have a "static __init" text in the init_function I get an output:<br><br>
unreferenced object 0xf9061000 (size 512):<br> comm "insmod", pid 12750, jiffies 14401507 (age 110.217s)<br>
<div class="im"> hex dump (first 32 bytes):<br></div> 1c 0f 00 00 01 12 00 00 2a 0f 00 00 01 12 00 00 ........*.......<br> 38 0f 00 00 01 12 00 00 bc 0f 00 00 01 12 00 00 8...............<br>
<div class="im"> backtrace:<br> [<c10b0001>] create_object+0x114/0x1db<br> [<c148b4d0>] kmemleak_alloc+0x21/0x3f<br> [<c10a43e9>] __vmalloc_node+0x83/0x90<br> [<c10a44b9>] vmalloc+0x1c/0x1e<br>
</div> [<f9055021>] myfunc+0x21/0x23 [hello_kernel]<br> [<f9058012>] 0xf9058012<br>
<div class="im"> [<c1001226>] do_one_initcall+0x71/0x113<br> [<c1056c48>] sys_init_module+0x1241/0x1430<br> [<c100284c>] sysenter_do_call+0x12/0x22<br> [<ffffffff>] 0xffffffff<br><br></div>
As we can see from the above output, it shows both the function name<br>as well as the module name where the leak is happening. Also the<br>address of the statement. So, my problem seems to be solved. Thank you<br>all for your pointers.<br>
<br>Sorry for the top post and long contents.<br><br>On Thu, Oct 28, 2010 at 12:00 AM, Rajat Sharma <<a href="mailto:fs.rajat@gmail.com">fs.rajat@gmail.com</a>> wrote:<br>> try removing static __init from function definition<br>
<div>
<div></div>
<div class="h5">> On Wed, Oct 27, 2010 at 10:40 PM, Sankar P <<a href="mailto:sankar.curiosity@gmail.com">sankar.curiosity@gmail.com</a>><br>> wrote:<br>>><br>>> Hi,<br>>><br>>> I have an out of tree kernel module with the source:<br>
>><br>>> static __init int hello_init(void)<br>>> {<br>>> char *ptr;<br>>> ptr = vmalloc(512);<br>>> ptr = vmalloc(512);<br>>> ptr = vmalloc(512);<br>>><br>
>> printk(KERN_ALERT "Hello World");<br>>><br>>> return 0;<br>>> }<br>>><br>>> Now I compile this file (hello.c) using my Makefile as follows:<br>>><br>>> EXTRA_CFLAGS=-g<br>
>> obj-m := hello-kernel.o<br>>> hello-kernel-objs := hello.o<br>>><br>>><br>>> Now if I insmod my hello-kernel.ko file and then do a `cat<br>>> /sys/kernel/debug/kmemleak` I get an output:<br>
>><br>>> unreferenced object 0xf8211000 (size 512):<br>>> comm "insmod", pid 9602, jiffies 3666022 (age 1553.469s)<br>>> hex dump (first 32 bytes):<br>>> 01 12 00 00 f2 10 00 00 01 12 00 00 fe 10 00 00 ................<br>
>> 01 12 00 00 0c 11 00 00 01 12 00 00 1a 11 00 00 ................<br>>> backtrace:<br>>> [<c10b0001>] create_object+0x114/0x1db<br>>> [<c148b4d0>] kmemleak_alloc+0x21/0x3f<br>
>> [<c10a43e9>] __vmalloc_node+0x83/0x90<br>>> [<c10a44b9>] vmalloc+0x1c/0x1e<br>>> [<f8208021>] 0xf8208021<br>>> [<c1001226>] do_one_initcall+0x71/0x113<br>>> [<c1056c48>] sys_init_module+0x1241/0x1430<br>
>> [<c100284c>] sysenter_do_call+0x12/0x22<br>>> [<ffffffff>] 0xffffffff<br>>><br>>><br>>> I understand that the kmemleak has correctly detected the memory leak.<br>>> But why is the leak showing in insmod , instead of the actual function<br>
>> name "hello_init". Is there a way we can get the exact location inside<br>>> the hello.c file printed instead of the generic "insmod" location ?<br>>><br>>> If I do a `gdb hello-kernel.ko`, the symbols are properly resolved, so<br>
>> I am sure the .ko file has symbols.<br>>><br>>> Any help will be appreciated. Thank you.<br>>><br>>> --<br>>> Sankar P<br>>> <a href="http://psankar.blogspot.com/" target="_blank">http://psankar.blogspot.com</a><br>
>><br>>> --<br>>> To unsubscribe from this list: send an email with<br>>> "unsubscribe kernelnewbies" to <a href="mailto:ecartis@nl.linux.org">ecartis@nl.linux.org</a><br>>> Please read the FAQ at <a href="http://kernelnewbies.org/FAQ" target="_blank">http://kernelnewbies.org/FAQ</a><br>
>><br>><br>><br><br><br><br>--<br>Sankar P<br><a href="http://psankar.blogspot.com/" target="_blank">http://psankar.blogspot.com</a><br><br>--<br>To unsubscribe from this list: send an email with<br>"unsubscribe kernelnewbies" to <a href="mailto:ecartis@nl.linux.org">ecartis@nl.linux.org</a><br>
Please read the FAQ at <a href="http://kernelnewbies.org/FAQ" target="_blank">http://kernelnewbies.org/FAQ</a><br><br></div></div></blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>S. Sengottuvelan.<br>