LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Memory not being freed after program is finished running. (https://www.linuxquestions.org/questions/linux-newbie-8/memory-not-being-freed-after-program-is-finished-running-730414/)

keiths121 06-03-2009 10:10 AM

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

sineri 06-03-2009 10:17 AM

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.

johnsfine 06-03-2009 10:24 AM

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).

keiths121 06-03-2009 10:27 AM

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?

sineri 06-03-2009 10:37 AM

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)

johnsfine 06-03-2009 11:41 AM

Quote:

Originally Posted by keiths121 (Post 3561762)
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.


All times are GMT -5. The time now is 03:22 AM.