How to Check RAM in Linux
The RAM (Random Access Memory) is an essential component of a Linux system which has to be monitored closely. In some conditions, we may run out of memory with very slow response times to our server or completely unresponsive.
As a result, it is essential to know to check your RAM on Linux because we may take protective action rather than the right ones.
We may also need to increase our swap memory, also called virtual memory, so that the server's performance can be increased.
Now, we discuss the ways by which we can check our RAM in Linux:
Check RAM on Linux Using Free
With the help of the free command, we can check our RAM on Linux, and the free command is the most popular command.
Syntax of the Free Command:
We can see in the above image that the output is divided into two categories: memory (the actual RAM) and swap (also known as virtual memory).
With the help of the free command, we can offer the following information:
One thing which we have to note down is, however, a lot of memory can be used by buffers or caches; if our system needs additional memory for the processes, then the kernel can free up this space. Just like the lsblk command, the free command can also be displayed in a human-readable format.
We can use the free command along with the option -h, in order to check the current RAM available using a human-readable format.
We can see that the above output is easy to read, but it is rounded.
Likewise, using the free command, we can show the total column to check the RAM and swap available on the system.
In order to show the total column, we can use the "free" command along with the option "-t."
We can also combine the command to get a human-friendly output as well as the total columns shown.
Inspecting /proc/meminfo to Check RAM
As we all know, the kernel is the one that is virtualizing the file system and providing entry points to a few of our devices on our system.
For example, the /proc directory can store references to our system's processes (that is, file descriptors); correspondingly, the /dev can store references to the virtual devices, which eventually point to the real disks.
Although, one /proc file can be more essential than others when we are talking about checking our RAM: meminfo.
We can see in the above output; the kernel displays statistics that are similar to those shown by the "free" or "vmstat" commands.
With the help of the /proc/meminfo file, we have access to the total amount of memory of our system. the memory which is free, the available buffer memory, and the page cache which might be used.
Lastly, we have access to the swap cache and also used active and inactive swap.
Check RAM Usage With top Command
With the help of the top command, we can see all the information related to the memory utilization for each process on our system. The top command is already installed in every Linux system. If in case it is not preinstalled, then we can install it with the help of the apt command. By using the following syntax, we can run the top command:
Look at the % mem column carefully. If we wish to see a process that is using too much memory, enter Shift + m. It will short the programs on the basis of the memory utilization on top. This is the advantage of top command that we are able to monitor the memory utilization of our system quickly. We can enter q in order to exit from the top menu.
Check RAM Usage with htop Command
When we run the htop command, then this will display you the overall information related to the RAM installation in which it is constantly updating the statistics and displays you how much memory is used by every process.
It is not like a free command; the htop utilities are not always installed by default on our Linux systems. Although, with the help of the below command, we can install it:
When the installation of the htop command complete, then we can run it through the terminal by using the following syntax:
Htop command is a free ncurses-based process GPL viewer for every Linus distro. It is just like the top command except that in the htop command, we can scroll vertically as well as horizontally; thus, it provides the full information with their complete command lines related to each process which are running on the system.