how we can reach at RAM size by summing up the memory occupied by processes and free memory in linux? [duplicate]

流过昼夜 提交于 2020-01-05 07:29:48

问题


I want to know to how to calculate total RAM, how we can reach at RAM size by summing up the output of "cat proc/meminfo" command

Memtotal = MemFree+?...........

any one can help


回答1:


You need a tool that takes shared memory into account to do this.

For example, smem:

# smem -t
  PID User     Command                         Swap      USS      PSS      RSS
...
10593 root     /usr/lib/chromium-browser/c        0    22868    26439    49364 
11500 root     /usr/lib/chromium-browser/c        0    22612    26486    49732 
10474 browser  /usr/lib/chromium-browser/c        0    39232    43806    61560 
 7777 user     /usr/lib/thunderbird/thunde        0    89652    91118   102756 
-------------------------------------------------------------------------------
  118 4                                       40364   594228   653873  1153092 

PSS is the interesting column here because it takes shared memory into account (adding RSS together will result in shared mem segments being counted multiple times so numbers won't add up).

So userland processes take up 654Mb total here.

# smem -tw
Area                           Used      Cache   Noncache 
firmware/hardware                 0          0          0 
kernel image                      0          0          0 
kernel dynamic memory        345784     297092      48692 
userspace memory             654056     181076     472980 
free memory                   15828      15828          0 
----------------------------------------------------------
                            1015668     493996     521672 

346Mb is used by the kernel and there's 16Mb free.
Overall about half of memory is used for cache (494Mb).

So 1Gb RAM total = 654Mb userland processes, broken up as above + 346Mb kernel mem + 16Mb free
(give or take a few Mb)



来源:https://stackoverflow.com/questions/27017579/how-we-can-reach-at-ram-size-by-summing-up-the-memory-occupied-by-processes-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!