LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-10-2009, 03:43 PM   #1
ineya
Member
 
Registered: Jul 2007
Posts: 39

Rep: Reputation: 16
debugging with memory map


I noticed that my application is leaking memory in stack area. There are many threads going on, stopping/starting quite often. I noticed (by using pmap) that [anon] areas number is growing, even when thread count stays the same. I can't think of anything else, that would occupy that area of memory, other than stack of threads.

I'm now struggling, how to identify who (which thread) is occupying that area? And also to understand why those areas are not unmapped as they are on x86.

I'm working on mips target, I can't reproduce it on x86.
I have no valgrind for mips.
I thought about LD_PRELOAD for mmap, but failed to make it work.
I assume that these are all mmaped regions, so I think none "leak-find" tools would help here, as they are all malloc based.

I'm looking for a way to identify those [ anon ] areas. Having a stack trace to see, which thread allocated it would be nice.

Is there a way to see, which memory regions were mapped by specific thread? Or this way: Is there a way to get thread's stack pointer from outside? Perhaps I could make a kernel module to list all threads and their stack pointer, but I don't know where kernel keeps this information.

Following trace is just for illustration, if you didn't see pmap before:
Code:
0000000000400000    744K r-x--  /bin/bash
00000000006b9000     40K rw---  /bin/bash
00000000006c3000     20K rw---    [ anon ]
0000000001766000   3488K rw---    [ anon ]
00007f6f59753000     40K r-x--  /lib/libnss_files-2.7.so
00007f6f5975d000   2048K -----  /lib/libnss_files-2.7.so
00007f6f5995d000      8K rw---  /lib/libnss_files-2.7.so
00007f6f5995f000     40K r-x--  /lib/libnss_nis-2.7.so
00007f6f59969000   2044K -----  /lib/libnss_nis-2.7.so
00007f6f59b68000      8K rw---  /lib/libnss_nis-2.7.so
00007f6f59b6a000     84K r-x--  /lib/libnsl-2.7.so
00007f6f59b7f000   2044K -----  /lib/libnsl-2.7.so
00007f6f59d7e000      8K rw---  /lib/libnsl-2.7.so
00007f6f59d80000      8K rw---    [ anon ]
00007f6f59d82000     28K r-x--  /lib/libnss_compat-2.7.so
00007f6f59d89000   2044K -----  /lib/libnss_compat-2.7.so
00007f6f59f88000      8K rw---  /lib/libnss_compat-2.7.so
00007f6f59f8a000   1320K r-x--  /lib/libc-2.7.so
00007f6f5a0d4000   2044K -----  /lib/libc-2.7.so
00007f6f5a2d3000     12K r----  /lib/libc-2.7.so
00007f6f5a2d6000      8K rw---  /lib/libc-2.7.so
00007f6f5a2d8000     20K rw---    [ anon ]
00007f6f5a2dd000      8K r-x--  /lib/libdl-2.7.so
00007f6f5a2df000   2048K -----  /lib/libdl-2.7.so
00007f6f5a4df000      8K rw---  /lib/libdl-2.7.so
00007f6f5a4e1000    236K r-x--  /lib/libncurses.so.5.7
00007f6f5a51c000   2044K -----  /lib/libncurses.so.5.7
00007f6f5a71b000     20K rw---  /lib/libncurses.so.5.7
00007f6f5a720000    112K r-x--  /lib/ld-2.7.so
00007f6f5a7bf000   1368K r----  /usr/lib/locale/locale-archive
00007f6f5a915000      8K rw---    [ anon ]
00007f6f5a931000     28K r--s-  /usr/lib/gconv/gconv-modules.cache
00007f6f5a938000     12K rw---    [ anon ]
00007f6f5a93b000      8K rw---  /lib/ld-2.7.so
00007fff62927000     84K rw---    [ stack ]
00007fff629fe000      4K r-x--    [ anon ]
ffffffffff600000      4K r-x--    [ anon ]

Last edited by ineya; 12-10-2009 at 03:45 PM.
 
Old 12-11-2009, 03:39 PM   #2
jiobo
Member
 
Registered: Nov 2008
Posts: 180

Rep: Reputation: 36
What debugger are you using? Are you running both a mips and x86 machine?
 
Old 12-11-2009, 04:32 PM   #3
ineya
Member
 
Registered: Jul 2007
Posts: 39

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by jiobo View Post
What debugger are you using? Are you running both a mips and x86 machine?
GDB. Yes both,.. but x86 has limited functionality (hw present on mips target is missing).
I traced the issue to __pthread_manager thread, which in case of my uclibc won't unmap the stack unless I detach and exit the thread explicitly (I let the test run over weekend)
I ended up putting traces in kernel sys_mmap2, sys_munmap, sys_brk,.. to find what thread mapped the memory as last one.
During my search I also found possible workaround by switching to user managed stack for pthreads, but I didn't try that.
 
Old 12-11-2009, 04:48 PM   #4
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
Have you looked into valgrind? It's useful for finding memory leaks because it points out where the discrepancy in malloc's versus free's is.

Regards,

Alunduil
 
0 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Virtual memory mapping to Board memory map !rajkums! Linux - Kernel 4 10-19-2008 12:27 PM
Kernel virtual memory map TO Board memory map -----> Mapping !rajkums! Linux - Embedded & Single-board computer 0 10-18-2008 09:21 AM
LXer: Techniques for memory debugging LXer Syndicated Linux News 0 02-20-2007 06:16 AM
Memory Leak when using memory debugging C program on SuSE SLES8 babalina Linux - Distributions 0 10-06-2003 09:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration