1

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

  • Why would the want a process to compute the total memory available when this information is already exported by the OS ? You have to use the output provided by `dmidecode` or `cat /proc/meminfo | grep -i Total`. – askb Nov 19 '14 at 13:22

1 Answers1

0

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)

lemonsqueeze
  • 1,041
  • 8
  • 19
  • how can we do by proc/meminfo commands output details. which field is related to process –  Nov 20 '14 at 06:36
  • Actually a really good exercise if you want to learn this stuff is to rewrite smem. You'll learn everything about parsing /proc data, getting info about shared mem segments, computing PSS etc. It's all [here](http://selenic.com/repo/smem/file/c2cab19139d0/smem) and [there](http://linux.die.net/man/5/proc) – lemonsqueeze Nov 20 '14 at 22:03