What is the difference between the memory usage report in System Monitor and the one by free?

I am using System Monitor 2.28.0. When I look in the Resources tab, I see a nice graph with for memory and swap. Memory is about 60% 2.3 GiB of 3.8. When I type the command free, I got :

             total       used       free     shared    buffers     cached
Mem:       3994908    3962396      32512          0     100852    1477032
-/+ buffers/cache:    2384512    1610396
Swap:      8000328      28468    7971860

cat /proc/meminfo | grep MemFree give

MemFree:           34536 kB

The situation has remained the save for several minute. I started a lot of process with a script and the script is waiting for the free memory to get lower. According to what I am seeing in the Process tab (or with top), the number in System Monitor seem a lot closed to the total of the memory of the process that the one reported by free.

Thanks


Solution 1:

The difference is whether or not the "buffers" and "cached" memory is included in the "used" count.

Generally, Linux system memory is used by the kernel for two purposes: processes and file/network cache/buffers. If you look closely at the output of free, it is already shown:


             total       used       free     shared    buffers     cached
Mem:       3994908    3962396      32512          0     100852    1477032
-/+ buffers/cache:    2384512    1610396
Swap:      8000328      28468    7971860

If you add "buffers" and "cache", and then subtract that from the "used" column, you'll get the second line under "used" (the line that starts with -/+ buffers/cache), which shows about 2.3G (2384512) in use, which matches the reported memory in use that System Monitor is reporting (it is ignoring the buffers/cached because those will go away to make room for more processes).

Your grep against /proc/meminfo actually matches the first line's "free" column (32512 is close enough to 34536 -- it likely changed between the two command outputs).