This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Very confused about malloc in Linux, Help!!!


I think I had better describe this scenario clearly.
 
1. My module includes some .so files, when I test them using simple program. No memory leak found checked by valgrind. And all memory addresses returned by malloc were in heap area.(below 0x40000000). My module will request many 64bytes, 128 bytes, 256 bytes memory.
 
2. When I integrated my module to a big program. The program will consume 700M virtual memory in initialization phase. My module in that program will malloc and free memory very frequently. And then, I found many blocks (1020K, 1024K, ...) were created in higher address ( higher than 0x40000000). And when I request 64 bytes, 128 bytes, 256 bytes..., system will return some address in the blocks. At this time, heap area only have 40M. 
 
So my question is:
 
1. What malloc did do to cause scenario 2? Both 1 and 2 are multi-thread program.
2. Can malloc free memory well in scenario 2?
 
Thanks so much!!!

----------------------------------------
> Date: Sat, 9 Oct 2010 16:30:21 +0200
> From: pasky@suse.cz
> To: zanshigang@hotmail.com
> CC: libc-help@sourceware.org
> Subject: Re: Very confused about malloc in Linux, Help!!!
>
> Hi!
>
> On Sat, Oct 09, 2010 at 01:10:20PM +0000, Shigang Zan wrote:
>> Now I have met a problem about my software in Linux. The memory usage kept increasing until no memory to use.
>>
>> I found that malloc will return many addresses higher than 0x40000000 when I requested memory using malloc, the addresses were not in heap area (below 0x40000000). I don't know why this scenario happened.
>
> Larger allocations are not allocated in heap but using mmap().
>
>> And it seemed many blocks (1020K 1024K ...) were created and until memory was exhausted by them.
>> What can I do to found the root cause of this problem. I found many blocks had no content, but why system crote more and more blocks.
>
> Are you freeing up your memory properly? Are you sure about that?
> Check with valgrind that you have no leaks.
>
> If you want to receive programming advice, it would be wise to:
>
> * ask about it on some more general programming forum (comp.lang.c?
> stackoverflow.com?); this does not appear to be a glibc-specific
> question
>
> * create a short standalone testcase demonstrating your problem
>
> Kind regards,
>
> --
> Petr "Pasky" Baudis
> The true meaning of life is to plant a tree under whose shade
> you will never sit. 		 	   		  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]