Memory usage on Linux servers is one of the common challenges for those new to server management. We think that with this article, you can have clearer information about memory usage
on your Linux servers.
The command you need to use to view memory usage is the free command. When you type this command, the terminal output will be as follows.
total used free shared buffers
cached
Mem: 3924572 2788396 1136176 0 410880 1679744
-/+ buffers/cache: 697772 3226800
Swap: 8388600 655712 7732888You can use some special parameters to display the values in the command’s output more
readably. The most commonly preferred parameter is the free -m parameter. For more parameters, you can type man free to access all parameters of the free command. The output of the free -m parameter is as follows;
values are given in megabytes with this command.
total used free shared buffers cached
Mem: 3832 2842 989 0 419 1736
-/+ buffers/cache: 686 3145
Swap:
8191 639 7552The common mistake when viewing and evaluating memory usage is interpreting the Used column of the Mem: field in the output as active memory usage. However, in reality, the active memory
usage is not the value in the used column. The Linux kernel tries to use the memory in the system at the most optimal level and stores information kept in memory, ready to be used when needed. For this reason, the Mem: section shows both the amount of actively used
memory and the amount of cache stored in RAM that can be cleared when needed.
For these reasons, the section in the 2nd line of the free command shows the actual usage excluding the disk cache.
-/+ buffers/cache: 686
3145The actual amount of memory you are using on the system is the used column shown in the -/+ buffers/cache: row.
Finally, we will inform you about the Swap: function in the free
-m output. Swap is the virtual memory amount that the operating system resorts to in order to prevent itself from becoming unstable when the amount of physical memory is completely exhausted. This virtual memory runs on the hard disks of your server. Do not
confuse this with cache — if a server starts using swap memory, it will start running very slowly. If there is any usage in the used column of the Swap: row on your server, we can say that at a certain point, your physical memory was
insufficient and Linux resorted to swap memory. (Some applications work differently in this regard and may prioritize using swap memory.)
When you start using swap, your server’s load values increase, and since access to data in swap memory is at a much lower
speed than actual physical memory, it can create serious performance issues. To free up swap memory, you can apply the following commands.
swapoff -a
swapon -aYou can send your questions about memory usage to us in the comments
section.
Leave a Comment
* Your comment will be published after approval.
Comments
0No comments yet. Be the first to comment!