Linux – Understanding difference between system and process memory in htop

htoplinuxmemory

I'm a bit confused by the memory stats that htop is reporting on one of our servers. On the top bars, it's showing system memory as:

Mem: 456 / 7950MB

So, looks very low usage.

However, my main process is showing it's memory usage as:

VIRT    RES     SHR     MEM% 
13.3G   2388M   2239M   30%

Hmm, a lot higher.

Why are the system stats only showing 456MB used, when the process reports that it's using 2388MB?

Update Here's the output from free:

             total       used       free     shared    buffers     cached
Mem:       8141292    5425364    2715928          0     103560    4839368
-/+ buffers/cache:     482436    7658856
Swap:      2097148          0    2097148

Best Answer

Htop show memory: MEN TOTAL, USED, BUFFERS AND CACHE. If you sum used, buffers and cache you will have result equals result of command free. Htop you need to consider all results because process can use any memory. Man htop describe memory is:

   M_SIZE (VIRT)
        Size in memory of the total program size.

   M_SHARE (SHR)
        The size of the process’s shared pages

   PERCENT_MEM(MEN%)
        The percentage of memory the process is currently using (based on the process’s resident memory size, see M_RESIDENT below).

   M_RESIDENT (RES)
        The resident set size, i.e the size of the text and data sections, plus stack usage.

I hope I´ve helped.