title: How to calculate system memory usage from /proc/meminfo (like htop)
body: <p>Running the <code>htop</code> command gives you a picture of the memory usage in a format like this: </p>
  
  <pre><code>1.92G/5.83G
  </code></pre>
  
  <p><strong>Question:</strong> how should I interpret the values taken from <code>/proc/meminfo</code> in order to calculate programmatically the memory used?</p>
  
  <p>I am looking for something similar to this: <a href="https://stackoverflow.com/questions/23367857/accurate-calculation-of-cpu-usage-given-in-percentage-in-linux">Accurate calculation of CPU usage given in percentage in Linux?</a> meaning that pseudocode is ok, I do not need something that can be compiled, just the logic. The source code of htop is a place to look for but I had no luck spotting the lines of code written for this...</p>
  
  <pre><code>$ cat /proc/meminfo 
  MemTotal:        6110716 kB
  MemFree:         2076448 kB
  MemAvailable:    3800944 kB
  Buffers:          382240 kB
  Cached:          1496216 kB
  SwapCached:            0 kB
  Active:          2830192 kB
  Inactive:         796648 kB
  Active(anon):    1749940 kB
  Inactive(anon):   109808 kB
  Active(file):    1080252 kB
  Inactive(file):   686840 kB
  Unevictable:          48 kB
  .
  .
  .
  ...
  </code></pre>