Which command line command displays overall memory usage on your Linux system

In this blog post, we will discuss four easy ways to check memory usage in Linux. This is an important task for any system administrator or anyone who wants to keep track of their system’s performance. By following the instructions in this post, you will be able to get an accurate reading of your system’s memory usage and take the necessary steps to improve performance if needed. Let’s get started!

The following commands can get your memory usage in Linux.

  • top
  • free
  • df
  • vmstat
  • ps

 

understanding memory usage in Linux

In order to understand memory usage in Linux, you first need to understand the different types of memory that your system has. There are two types of memory that are typically used in Linux systems:

  • Physical Memory or RAM – This is the type of memory that is installed in your system and is used to store programs and data that are currently being used by your system. The amount of physical memory you have will determine how much you can load into your system’s memory at one time.
  • Swap – This is a type of virtual memory that is used by Linux systems to help manage physical memory. When your system runs out of physical memory, it will use some of your swap space to store data that is not currently being used.

 

When we talk about memory usage in Linux, we are referring to the amount of RAM that is being used by the system and applications.

procedure to check memory usage in Linux

The procedure to check memory usage in Linux is as follows:

  • Open the terminal application.
  • Type top command
  • Press Enter to run the command.
  • Once the top command has loaded, take a look at the “mem” column. This command displays a real-time view of your system’s CPU and memory usage.

 

Check memory usage with top command in Linux

The best way to check memory usage in Linux is by using the top command. To use this command, open up a terminal window and type: top. One of the columns that it displays is called “mem”. This column tells you the percentage of how much memory each process is using.

This is a very handy command that displays information about the processes that are currently running on your system. If you see any process that is taking up a lot of memory, you can take steps to correct the issue.

Check memory usage with free command in Linux

The second way to check memory usage is by using the free command in Linux. This command displays information about the amount of free and used memory on your system. To use this command, open up a terminal window and type: free -m

The free command is used to display information about the amount of free and used memory on your system. The -m flag tells the command to display the output in megabytes.

This is a very useful command for troubleshooting issues with your system’s memory. By running this command, you can get a good idea of how much memory your system has available and whether or not it is being used efficiently.

$ free -m
total used free shared buff/cache available
Mem: 31496 17125 2735 0 11634 14061
Swap: 3071 97 2974

Check memory usage with vmstat command in Linux

Another way to check memory usage is by using the vmstat command in Linux. This command displays information about virtual memory statistics. To use this command, open up a terminal window and type: vmSTAT [options]

The vmstat command is used to display virtual memory statistics. This can be helpful for troubleshooting or for getting a general overview of how your system is performing. The vmstat command has many options, but we will only be discussing a few of them in this article.

vmstat reports information about processes, memory, paging, block IO, traps, disks and cpu activity. The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case.

The vmstat interval in Linux can be specified. This flag tells vmstat to report information on a sampling period of length delay. The default interval is 1 second, but you can change it to any value you want. For example, if you want to report information on a sampling period of 10 seconds, you would type: vmstat 10

$ vmstat 10
procs ———–memory———- —swap– —–io—- -system– ——cpu—–
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 99328 2799320 8 11913184 0 0 53 25 5 8 0 0 99 0 0
0 0 99328 2799088 8 11913184 0 0 0 4 2237 2605 1 0 99 0 0
0 0 99328 2799088 8 11913184 0 0 0 4 2190 2561 0 0 100 0 0

check memory usage from /proc/meminfo in linux

/proc/meminfo is a file that contains information about memory usage on your system in Linux. This file is a part of the proc filesystem, which gives you access to information about the running processes on your system. The meminfo file contains information such as the total amount of memory on your system, the amount of free memory, and the amount of memory that is being used by process.

This file can be helpful if you want to get an overview of how much memory your system is using. It can also help you troubleshoot issues with Memory Management Unit (MMU) errors and Out-of-Memory (OOM) errors.

  • grep ‘MemTotal:’ /proc/meminfo
  • grep ‘SwapTotal:’ /proc/meminfo
  • MemTotal: total usable ram in megabytes
  • SwapTotal: total swap space in megabytes

How to free up memory on Linux system?

There are a few ways to free up memory on your Linux system. You can kill processes that are using up too much RAM, you can unload modules that are no longer being used, or you can use a tool like “Swap” to create a temporary file on your hard drive that can be used as additional RAM.

What is a memory leak?

A memory leak is a situation where a process is using up more and more RAM over time, even though it doesn’t need to. This can eventually lead to the system running out of memory and crashing.

How to prevent Linux system from running out of memory?

There are a few things you can do to prevent your Linux system from running out of memory. You can increase the amount of RAM in your system, you can reduce the number of processes that are running, or you can use a tool like “Swap” to create a temporary file on your hard drive that can be used as additional RAM.

How to find out which processes are using up the most memory?

To find out which processes are using up the most memory, you can use the “ps” command. For example, to see a list of all the processes that are using more than 100 MB of RAM, you would use the following command: “ps -eo pmem,pid,user,args | sort -k +0nr | head -n 20”.

To kill a process in Linux, you can use the “kill” command. For example, to kill the process with the ID 1234, you would use the following command: “kill 1234”.

What is the difference between physical memory and virtual memory?

Physical memory is the amount of RAM in your system. Virtual memory is a temporary file on your hard drive that can be used as additional RAM.

By using the top command, you can see how much memory each process is using.
The free command will give you a breakdown of the amount of free and used memory, in megabytes.
The vmstat command will give you a breakdown of the amount of physical and virtual memory, in megabytes.

These are 4 easy ways to check memory usage in Linux. By following the instructions in this post, you will be able to get an accurate reading of your system’s memory usage and take the necessary steps to improve performance if needed. Thanks for reading!

Which command line command displays overall memory usage on your Linux system

David Cao

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He uses AWS, Git & GitHub, Linux, Python, Ansible, and Bash. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

5 useful Linux network troubleshooting commands

Read More »

what does 0.0.0.0 ip mean in netstat command

Read More »

6 ways to use netstat command in Linux

Read More »

2 Easy ways to fix cd: string not in pwd

Read More »

Search

5 effective ways to learn Linux commands

Check More

5 useful Linux network troubleshooting commands

Here are five commands that you can use to check the network status in Linux. ifconfig ifconfig: This command displays information about the network interfaces

Read More »

December 17, 2022

what does 0.0.0.0 ip mean in netstat command

Have you ever seen the 0.0.0.0 address in your netstat output and wondered what it means? This is a special IP address that represents all

Read More »

December 11, 2022

6 ways to use netstat command in Linux

The netstat command is one of the most powerful and useful commands in Linux. It can be used to troubleshoot network problems, find out what

Read More »

December 10, 2022

2 Easy ways to fix cd: string not in pwd

The cd command is used to change the current working directory in Bash. By default, it will move you to your home directory with cd

Read More »

December 9, 2022

2 Easy ways to fix cd: Permission denied

If you’re getting an error like “cd: Permission denied” when trying to change directories in Bash, don’t worry, you’re not alone. This is a common

Read More »

December 7, 2022

Understanding SSH’s StrictHostKeyChecking Option

The SSH option StrictHostKeyChecking is a security feature that affects how SSH verifies the identity of a remote computer when connecting to it. When this

How to show memory usage in Linux?

Open the command line..
Type the following command: grep MemTotal /proc/meminfo..
You should see something similar to the following as output: MemTotal: 4194304 kB..
This is your total available memory..

How to check memory usage percentage in Linux?

Method-1: How to check Memory Utilization Percentage in Linux?.
free Command, smem Command..
ps_mem Command, vmstat Command..
Multiple ways to check size of physical memory..

How to check memory utilization history in Linux?

You can use the command “free” to find the current memory usage in the server. The command will show you the current RAM and swap usages in MB. The history of memory usage for the day can be found by using the “sar” command.