I'm having hard time understanding memory usage reported by top
. The memory summary section lists the following. All numbers in MiB
.
MiB Mem : 31884.1 total, 13562.7 free, 7881.9 used, 10439.4 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 22665.9 avail Mem
However, when I sum up RES
column values, they don't add up to used
reported in the summary. Summation of RES
is 15225.7
. This is double used
value of 7881.9
. If I add used
and buff/cache
, I get 18321.3
. So, now the summation of used
and buff/cache
is more than summation of RES
.
More findings:
- Noticed that
top
memory summary almost matches that offree
. The following isfree -m
output.
total used free shared buff/cache available
Mem: 31884 7881 13555 886 10446 22658
Swap: 2047 0 2047
As you can see, used
, free
, buff/cache
, as well as, available
all have almost the same values.
When I add from
free
output the fieldsused
,shared
, andbuff/cache
, I get19213
. This is again more thanRES
summation! This is expected, however, as we agreed that the output offree
andtop
match from summary standpoint.I'm expecting that
RES
summation (fromtop
) would be equal/close to summation ofused
,shared
, andbuff/cache
(fromfree
) astop
documentation lists that memory per process factors in private and shared portions.
RES - anything occupying physical memory which, beginning with Linux-4.5, is the sum of the following three fields: RSan - quadrant 1 pages, which include any former quadrant 3 pages if modified RSfd - quadrant 3 and quadrant 4 pages RSsh - quadrant 2 pages
- Whenever I clear system cache,
RES
summation always is more than the expected summation. This is how I clear system cache:sudo sync && sudo sysctl -w vm.drop_caches=1
. Interestingly enough,RES
summation upped to18175.2
! The following is the memory summary oftop
after clearing the cache. You can notice significant decrease inbuff/cache
, as expected. However, I wasn't expecting significant increase inused
field! Summation ofused
,shared
, andbuff/cache
fromfree
output is13533
. This is around 5 GiB less thanRES
summation!
MiB Mem : 31884.1 total, 19358.2 free, 8795.6 used, 3730.2 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 21626.5 avail Mem
- Tried
smem
and the values doesn't match eithertop
,free
, or summation ofRES
!
I can't make sense of the numbers! And I don't know, as a software application, how much memory an application I write actually takes and won't be able to investigate a memory issue if I run into one! I'm totally lost here. If someone can shed some light one what's going on, this will be much appreciated!
I looked at other questions but non actually addresses the inquiry. Like: Why does the memory usage in "top" not add up?. This one was lucky their numbers checked out fine. .. and more, but still didn't find clear cut answer!
Looked at this one too: Why total RES doesn't match used memory in top command? [duplicate] Neither does this one (Correctly determining memory usage in Linux) answer the question.