How to Calculate Memory Usage in Linux:
If you are managing Linux servers, knowing about memory use is very important. Good memory use helps your servers work better and more reliably.
In this guide, we'll explain the ways you can use to calculate and keep track of how much memory is being used in Linux.
Understanding Key Memory Metrics:
Total Memory: The sum of physical memory installed in your system.
Used Memory: The portion of memory currently utilized by processes.
Free Memory: The amount of memory that is not in use.
Buffers/Cache: Memory used by the Linux kernel for buffering and caching, which enhances performance.
As a system administrator, it's important to understand that buffer and cache memory should not be counted as used memory. This is because buffer and cache are used to improve system performance. So, we should not think of this as memory being used up.
Using the free Command:
A very easy and useful tool you can use is the free command. Here's how to do it: Type free -mw in your terminal. This command shows memory details in megabytes, which is simpler to understand. The result will show different things like total memory, how much is used, how much is free, shared, buffer/cache, and how much memory is available.
To calculate memory usage in percentage:
To find out how much memory is being used in percentage on a Linux system, you can use a simple formula: Subtract the free memory from the total memory, divide this by the total memory, and then multiply by 100.
This tells you how much memory is being used in percentage.
I have created a shell script that assists in determining the amount of memory being used in Linux systems. This script conveniently displays the memory usage as a percentage.
Script output: Below is the referenced script output for calculating memory usage in percentage.
This guide and the shell script simplify help to check the real time memory usage on Linux systems. Now, you can easily determine the memory utilization in percentage, which aids in efficiently managing your Linux systems. You can view my YouTube video below, which demonstrates real-time memory usage calculation in Linux.