Running the htop
command gives you a picture of the memory usage in a format like this:
1.92G/5.83G
Question: how should I interpret the values taken from /proc/meminfo
in order to calculate programmatically the memory used?
I am looking for something similar to this: Accurate calculation of CPU usage given in percentage in Linux? 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...
$ 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
.
.
.
...
1.92G/5.83G
stats you quote, simply take the numbers in the first two lines and convert from kB to GB (i.e. divide by 1024*1024)... Most of the rest of the lines are simply a breakdown of what's currently in use base on how it's being used, whether it's been modified or not, and a few other characteristics...