Linux memory reporting is pretty simple. Unfortunately many people mis-read the data.
Linux uses spare memory for buffer cache. Both report very low values of free memory on a machine that's been up for a while. But this isn't a problem.
Let's take a machine. This is a pretty idle machine; 1Gb of RAM and it's not doing much at all.
Code:
% free
total used free shared buffers cached
Mem: 1003316 906428 96888 0 213900 528004
-/+ buffers/cache: 164524 838792
Swap: 2024148 12968 2011180
The "free" column on the "Mem" line isn't useful. free+buffers+cached is more interesting. Fortunately the command works this out for us; the "buffers/cache" has already done the sums. The number "838792" is the real amount of free memory on this box.
Now there are two things which might be of interest; are we running short of physical memory? Are we running short of virtual memory?
The first could simply be the number from the "free" output, above, but it might make more sense to also take into account how much has been swapped (which might have indicated a temporary short-fall), so "real free - swap usage" might be a more useful indicator of free RAM. A %age value could be taken by dividing that by "total" from the Mem: field.
In my case (838792-12968)/ 1003316 * 100 = 82% free memory.
However, this isn't necessarily useful. Many machines might be short of physical memory (especially for programs that allocated and use multi-Gbyte data tables) and the users are more concerned with free virtual memory. Here we need to consider free memory and free swap, so "real free + swap free" is the number. A %age value could be taken by dividing that by the totals of "Mem+Swap".
In my case (838792+2011180)/ (1003316+2024148) * 100 = 94% free virtual memory. This is clearly a box with no memory issues.
My workstation, however, isn't so lucky:
Code:
total used free shared buffers cached
Mem: 506200 472792 33408 0 4076 57184
-/+ buffers/cache: 411532 94668
Swap: 1012084 117660 894424
Free memory = (94668-117660)/506200*100 = -5% - negative! My requirements exceed physical memory, but not by much.
Free virtual memory = (94668+894424)/(506200+1012084)*100 = 65% - Not too bad.
Hmmph. My desktop would achieve better performance with more memory, but since I don't do a lot of heavy I/O (except backups) it's not really an issue.
On a normal machine, "running short of VM" is normally more interesting, but on a linode swapping has a heavy performance penalty so I'd look more at the "real free - swap usage" figure.
My linode is... pretty idle!
Code:
% free
total used free shared buffers cached
Mem: 296020 287344 8676 0 17916 162152
-/+ buffers/cache: 107276 188744
Swap: 263160 576 262584
I built the config back when it was a linode64 and gradually increased stuff on it (eg lighttpd instead of thttpd) as we got more and more bang for buck. But still...
These measures are "snapshot" measures and only an indication. They can be used to determine if a process is likely to die with "out of memory" issues, for example. For more detailed analysis, a continuous track of swap in/swap out activity (from vmstat) is a more dynamic measure of memory shortfall issues and a more likely indicator of application performance issues (a short burst of paging is normal; long term continuous paging indicates the machine could be spending more time paging data in/out than actually processing and is indicative of a real memory shortfall (as opposed to virtual memory). That's a lot more difficult question
