Subject: | Free memory != Available memory (how to calculate it) |
Date: | Mon, 13 May 2013 12:03:50 +0100 (BST) |
To: | "bug-Sys-MemInfo [...] rt.cpan.org" <bug-Sys-MemInfo [...] rt.cpan.org> |
From: | freesoft <kqfhjjgrn [...] yahoo.es> |
I'm posting this message to help those who need to know the available memory for a program. The free memory (as calculated by this module, Sys::MemInfo, or as shown by some commands like "top") is NOT the memory available to a program. The reason: Linux kernel takes all free memory and uses it for buffers and for cache. As programs ask for memory, the kernel gives them memory from the buffer and cache memory. More info at:
http://www.linuxatemyram.com/
http://rimuhosting.com/howto/memory.jsp
So, if you want to know the memory available to a program, you can't use Sys::MemInfo, you will need to do something like the following:
* Open "/proc/meminfo" file.
* Look for 3 lines: MemFree Buffers Cached
* Add the values for those 3 lines: MemFree + Buffers + Cached
* The result is the REAL available memory for programs (in KB).