LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-03-2009, 10:10 AM   #1
keiths121
LQ Newbie
 
Registered: Jun 2009
Posts: 2

Rep: Reputation: 0
Memory not being freed after program is finished running.


I just setup a linux box and am having issues of memory not being freed after apps are run. My distro is Debian 4 "etch". After the OS was installed I ran apt-get update, apt-get upgrade, and apt-get install build essential. After running these commands the amount of free memory has dramatically decreased from around 470MB or 512MB free when I first logged into the system after running those commands 191MB of 512MB free. I am viewing this info via free -m command. I have let 30 mins or so pass and still only 191MB of 512MB are free. It does not make sense. When i run the command to see how much mem each process is using, it does not add up. that is what i get when i do ps -e -o rss=,args= | sort -b -k1,1n | pr -TW$COLUMNS

Does anyone know where this memory is going or how to resolve this issue? Any help is greatly appreciated. Thank you.


396 /sbin/klogd -x
548 sort -b -k1,1n
592 pr -TW93
596 /sbin/syslogd
628 init [3]
644 udevd --daemon
728 ps -e -o rss=,args=
808 /usr/sbin/cron
1236 /usr/sbin/sshd
1728 /bin/sh
1828 -bash
2936 sshd: root@pts/0
 
Old 06-03-2009, 10:17 AM   #2
sineri
LQ Newbie
 
Registered: Jun 2009
Posts: 9

Rep: Reputation: 0
I encountered this before ... but don't remember what I found out
anyway ... try doing "more /proc/meminfo"
I think it's chewed by chached or something (don't quite remember)
so ... memory minus a few of the figures displayed, would be the added up number of free

If I was wrong, please correct me.
 
Old 06-03-2009, 10:24 AM   #3
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,109

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
I think you are misinterpreting the significance of "free memory" and misunderstanding the output of the free command (or whatever other command you used to measure "free memory").

Almost certainly nothing is wrong other than your understanding of the situation.

Here is sample output from free
Code:
             total       used       free     shared    buffers     cached
Mem:       4025704    1773880    2251824          0     188760     781836
-/+ buffers/cache:     803284    3222420
Swap:     12691328      92180   12599148
If you know what all those numbers mean, you probably wouldn't have asked the question you asked.

If you don't know what they all mean, the simple answer is:
Ignore the number directly below the word free. The amount of free memory is the next number below in that column (the 3222420 in my example).
 
Old 06-03-2009, 10:27 AM   #4
keiths121
LQ Newbie
 
Registered: Jun 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Yes, it looks like it is being chewed up by cache. What does that mean if it is cached? Does that mean it will be freed if there is a need for the additional memory?
 
Old 06-03-2009, 10:37 AM   #5
sineri
LQ Newbie
 
Registered: Jun 2009
Posts: 9

Rep: Reputation: 0
when it's chewed by cache .. it's used by system.
like the file system, it stores files in mem until system does a "sync" or when you do a "sync"
it could be something else as well.

it's managed by kernel I think, not much for you to do .
since I do not know linux soooo much
I only know that "sync" may help a bit, but you shouldn't even worry about it.

Because when additional memory is needed, I think (at least I was told) that the kernel will free more memory for other use. (by doing "sync" or like moving cached stuff into swap)

Last edited by sineri; 06-03-2009 at 10:39 AM.
 
Old 06-03-2009, 11:41 AM   #6
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,109

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
Quote:
Originally Posted by keiths121 View Post
What does that mean if it is cached? Does that mean it will be freed if there is a need for the additional memory?
In simple cases yes. In complicated cases, it depends what you mean by "need".

The system might swap other memory to the swap file in preference to releasing memory from cache. The algorithms are pretty good, so when it swaps in preference to releasing cache, that is usually the best choice. But may people misunderstand and think it is always wrong to swap in preference to releasing cache, and they take misguided steps to prevent the system from doing so.

So if "need" means the system really needs that memory (can't manage without it) then it absolutely will take it from cache. But if "need" means the system needs to take memory from somewhere and has a choice to swap or to take it from cache, the system will make a good choice. Most of the time that good choice is to take the memory from cache, rather than swapping. In the less common case that good choice is swapping, it is likely to still be a good choice, even though that may be hard to understand.

Notice in the example I quoted 90MB of swap space is in use even though 3146MB of memory is "free" including cache. When it wrote that 90MB to the swap area, I'm sure less than 3146MB was "free", but I'm sure quite a LOT was "free" (used by cache) and the system correctly swapped rather than taking from cache. I think that swapping happened long before I used that free command, yet the swap space was still in use. That implies the sleeping tasks that own the swapped memory haven't touched it since it was swapped.

Last edited by johnsfine; 06-03-2009 at 11:49 AM.
 
  


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
pthreads virtual memory usage -- memory is not freed after thread exit minimol Linux - General 2 05-26-2009 01:19 AM
How does the cdev_alloc memory get freed up? nabramovitz Linux - Kernel 2 03-28-2008 07:04 PM
'Freeing Unused Kernel Memory: 224k Freed - Laptop Hangs nutnut Linux - Laptop and Netbook 1 10-21-2005 07:09 PM
Freeing unused kernel memory: 136k freed apenguinlinux Debian 8 08-08-2005 03:30 PM
Freeing unused kernel memory: 228k freed bodedeb Linux - General 8 10-28-2003 03:59 AM


All times are GMT -5. The time now is 07:23 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration