LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-20-2010, 11:49 PM   #1
chamara82
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Rep: Reputation: 0
Application Virtual address space memory allocation - memory does not get free


I am using malloc and frees a lot in my program. It shows its allocated but when i remove it doesnt show as the memory is removed(I am using the top command to view VIRT memory usage). If this continously grows what would happen to my program (Will it go out of memory?)
 
Old 04-21-2010, 12:36 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
You only need to be alarmed if you keep seeing memory usage GROW even after you know you've freed it.

It would be extremely inefficient to shrink and grow program size every time you malloc and free new data. As an optimization, "free()" only marks de-allocated memory as "available", and "malloc()" tries to re-use previously allocated memory whenever possible.

So no, there's probably nothing to worry about - the system is doing exactly what it's supposed to
 
1 members found this post helpful.
Old 04-21-2010, 02:49 AM   #3
chamara82
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Original Poster
Rep: Reputation: 0
I have checked my program for memory leaks and found None(Valgrind,purify). I have growing memory problem each time i execute some tasks of the program memory grows but the growth degrades after number of times
E.g.
times i execute the same tasks
1st time VIRT memory - 1023MB
2nd time - 1123MB
3rd Time - 1190MB
4th Time - 1210MB
5th Time - 1220MB
So the memeory growth degrades as we go along. If there is no problem with memory leaks, can we make sure that the freed memory will be available for the process regardless of this growth shown. THere is a virtual addess space cutover at 3GB in 32bit RH4 i guess.

Does anyone knw what will happen if we malloc and free small chunks of memory(3KB) many times. Does the virtual address space do a memory fragementaion? Please help

Last edited by chamara82; 04-21-2010 at 04:24 AM.
 
Old 04-22-2010, 06:53 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Did you start two threads for this same question? Or did you change your user ID and start three threads for the one question:
http://www.linuxquestions.org/questi...-leaks-803024/

http://www.linuxquestions.org/questi...-space-803426/

Having part of the details we need to give a specific answer in each of three threads makes it much more difficult to provide an answer.

Quote:
Originally Posted by chamara82 View Post
I have checked my program for memory leaks and found None(Valgrind,purify).
That isn't a strong reason to believe there are no memory leaks. Valgrind and purify are not very accurate. There are many kinds of leaks they can't report.

Quote:
times i execute the same tasks
That phrase needs a lot more clarification. In context of the thread, it would seem you mean the program is running continuously and the program does some operation which malloc's a bunch of memory and the frees all of it before the next time. If that were true, you would not see the growth in VIRT that you claim. So probably you do have a memory leak.

But that estimate is extrapolating a lot from your unclear statements.

Quote:
Originally Posted by chamara82 View Post
But the growth is degrading over the number of times of the execution of the tasks. Can i think that fragmentation plays a role in this?
Consider a program that has a lot of small allocations and never frees a large fraction of them at once. Instead it might replace them one at a time with similar, but not exactly the same size, allocations.

When malloc allocates a chunk, it might not have a free one of exactly the right size nor have a big contiguous free area, so it might split a slightly larger chunk into the chunk needed and a small fragment that won't get used. If you later need the size that it split, it might no longer be available, causing malloc to split a larger chunk again. Soon malloc would need to get more from the OS even though the total of all allocations might not be changing much.

So in that rolling replace mode (unlike the deleting it all at the end of each task and reallocating for the next task) the average amount wasted for allocations might gradually go up as the rolling replace varies the chunk sizes.

But the fragments aren't lost forever. They come back when you free the adjacent chunks. So as you continue such a rolling replace, the amount that the average freed size exceeds the actual use should soon catch up with the amount the average allocation cost exceeds the actual use.

All of that assumes a rolling replace design with random small size variations. That is an even wilder extrapolation from the little info you have provided.

Last edited by johnsfine; 04-22-2010 at 07:16 AM.
 
1 members found this post helpful.
Old 01-01-2011, 08:19 PM   #5
chamara82
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Sorry for the delay in replying this thread. Do you know a tool to check actual memory usage for a process. Why i am asking this is I have a process it actually allocates small chuncks of data and release everything at the end. However the top command does not seem to show that. I used purify and valigrind to check for memory leaks too but didnt find any leaks on my program. I am currently looking at VIRT from the top, it actually shows an increase all the time. How am i suppose to know that the freed memory is aavailable to process and they can be reused since the there is not +/- shown in the VIRT column in top,
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
memory allocation for vista in virtual box. mick463 Linux - Newbie 1 09-18-2008 01:26 PM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04:05 AM
The used memory of application is increasing. Free space decreasing. Help needed. maheshnimje Linux - General 1 05-09-2006 12:16 AM
dynamic allocation of memory in kernel space appas Programming 1 08-04-2004 06:32 AM
memory allocation, application<-->driver charlies Programming 2 03-03-2001 11:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:42 AM.

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