How to check Memory Usage in Linux

Introduction

Sometimes Memory Usage monitoring in Linux might be tricky. In this Blog, we will learn about the basic linux commands that you as an Linux user will find these commands very useful and so that you can run the same during day to day operations.

By executing a few basic commands on the terminal, you can obtain all the necessary information and track memory statistics to enhance the performance of your Linux system. Below are the list of command that we will go through in detail in this blog:

  1. cat
  2. free
  3. vmstat
  4. top

These commands are compatible with almost all Linux distributions, and we will provide an explanation of their functions and how to interpret the output.

cat Command to Show Linux Memory Information

Entering cat /proc/meminfo in your terminal opens the /proc/meminfo file.

This virtual file provides real-time information on the available and used memory, as well as kernel buffers. It is important to note that the output may vary slightly depending on the architecture and operating system being used.

Example of /proc/meminfo

free Command to Display the Amount of Physical and Swap Memory

Typing free in your command terminal provides the following result:

totalTotal installed memory
usedMemory currently in use by running processes (used= total – free – buff/cache)
freeUnused memory (free= total – used – buff/cache)
sharedMemory shared by multiple processes
buffersMemory reserved by the OS to allocate as buffers when process need them
cachedRecently used files stored in RAM
buff/cacheBuffers + Cache
availableEstimation of how much memory is available for starting new applications, without swapping.

The free command has multiple options to format the output so that it better matches your requirements. The table below lists the most useful variations of the free command.

OptionsResult
-boutput in bytes
-koutput in kibibytes
-moutput in mebibytes
-goutput in gibibytes
-ldetailed low and high memory statistics
-oold format (no -/+buffers/cache line)
-ttotal for RAM + swap
-supdate every [delay] seconds
-cupdate [count] times

vmstat Command to Report Virtual Memory Statistics

vmstat provides general information about processes, memory, paging, block IO, traps, and CPU activity.

top Command to Check Memory Use

The top command is useful to check memory and cpu usage per process. It displays information about:

  • uptime
  • average load
  • tasks running
  • number of users logged in
  • number of CPUs/CPU utilization
  • memory/swap system processes

Note: If you want to change the delay for top command output then use cmd +d and specify the number in seconds. Below is the sample output of top command.

Conclusion

The guide presented various approaches for monitoring memory usage on Linux. One of the commands discussed provides a significant amount of valuable information that can be reviewed later. It’s crucial to learn how to interpret this information accurately.

You can now manage your server more efficiently.

Hope it helps. Cheers!!!

About the author

Mohit Chaudhary

Hey there, I am IT enthusiast who is passionate about Middleware, DevOps, Cloud and much more.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *