How to calculate used memory on Linux?

Hi, wanted to get more information on how to get the real used memory value on a droplet with CentOS 7 x64.

I was reviewing how DigitalOcean calculates used memory in the monitoring graphs and they do it “used memory is calculated by subtracting free memory and memory used for caching from the total memory amount” from the information exposed in /proc/meminfo.

This is the correct way to calculate used memory on a Linux server?

I see other people calculating used memory as “dividing active memory by total memory amount” from the same information exposed in /proc/meminfo.

Any ideas on this? What do you think? As you can see I have little knowledge on this issue.

Thank you.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


It seems you want to figure out the used memory rate.About /proc/meminfo you should know: this is not a real file. Instead, /proc/meminfo is a dummy file containing real-time dynamic information about the system. In particular, you need to check the following values: Total memory (MemTotal) Free memory (MemFree) Available memory (MemAvailable) Buffers File cache (Cached) SwapCached All swap areas (SwapTotal) SwapFree If you want to use /proc/meminfo, you can connect to the egrep command and use it: egrep --color'Mem | Cache | Swap'/proc/meminfo.This will produce an easy-to-read list with entries containing things like Mem, Cache and Swap will be colored.

Other commands to find that,top,free,vmstat -s and dmidecode may help you.But to use dmidecode command,you need to have sudo permission,then type in sudo dmidecode -t 17.The output of this command can be long because it displays information for all memory-type devices. Therefore, if you cannot scroll up and down, you may need to send the output of this command to a file,like sudo dmidecode -t 17> dmi_infoI or pass it to a less command, such as sudo dmidecode | less.

By the way,how do you export the red font?

Best wishes.


This is the /proc/meminfo output:

MemTotal:        3880364 kB
MemFree:          222412 kB
MemAvailable:    2666848 kB
Buffers:              28 kB
Cached:          1536256 kB
SwapCached:            0 kB
Active:          1341356 kB
Inactive:         758104 kB
Active(anon):     654492 kB
Inactive(anon):    38632 kB
Active(file):     686864 kB
Inactive(file):   719472 kB