How to Check Memory Usage in Linux – 5 Quick Ways

Try this guide with our instant dedicated server for as low as 40 Euros

Check Memory Usage Linux

Memory management is a vital aspect of keeping a Linux system running smoothly.

Whether you’re a system administrator, a developer, or just a curious user, knowing how to check memory use in Linux is critical for guaranteeing the stability and performance of your system. RAM is a valuable resource, and monitoring its utilization can assist you in identifying and resolving issues such as memory leaks or low memory because of resource-hungry processes.

This post will look at various ways of monitoring and checking memory use in a Linux environment. Whether you prefer command-line tools or graphical interfaces, by the end of this article, you’ll have a firm grasp on assessing your system’s memory utilization while keeping your Linux system running smoothly.

  1. The Prerequisites to Checking Available Memory in Linux
  2. Five Methods to Check Memory Usage in Linux
  3. Use the GUI to Check Linux Memory Use
  4. Tips For Tracking Memory Usage in Linux
  5. Conclusion
  6. FAQs

Let’s start with the prerequisites and then move on to the five ways to check memory usage in Linux.

The Prerequisites to Checking Available Memory in Linux

Here’s what you need to try out the five methods we’ll discuss in this tutorial:

  • A system running a Linux distribution
  • Access to a command line or a terminal
  • A user account with sudo permissions
  • The system should have a package manager (we’ll use APT)

System memory (RAM) is just one of the critical specifications you need for smooth server operation. Here’s our guide to choosing the best dedicated server resources for your projects.

Five Methods to Check Memory Usage in Linux

Methods to Check Memory Usage in Linux

Like most tasks, Linux offers several ways of checking the available system memory. We’ll discuss five simple ways to check memory usage in Linux environment,

Method #1: Use the cat Command to Show Linux Memory Information

The easiest method is to use the cat command to view the contents of the /proc/meminfo file. For this, enter the following commond in the terminal:

$ cat /proc/meminfo

This file tracks how much memory is available and consumed by various processes. It has real-time data on the system’s memory utilization and the kernel’s use of shared memory and buffers. Since this data is closely tied to the system, the outcome could vary slightly depending on the architecture and operating system.

For instance, here’s how the /proc/meminfo file looks like on an Ubuntu machine:

cat Command to Show Linux Memory Information

You can see that the system uses kilobytes as the unit for system memory. You have to do some quick math to translate the numbers in GBs.

Method #2: Use the free Command to See the Physical and Swap Space Memory Capacity

Free is a simple command that prints the available and consumed memory statistics. Here’s a sample output:

free Command to See the Physical and Swap Space Memory Capacity

Like the first method, the output shows the swap and used/available memory in kilobytes.
Let’s explore this output in detail to find out what each caption indicates.

total The total physical memory installed on the system
used The memory used by the processes (used = total – free – buff/cache)
free The memory that isn’t currently in use (free = total – used – buff/cache)
shared The memory shared by system processes
buffers The memory the OS has set aside to allot as buffers when processes raise a demand
cached RAM-stored files
buff/cache Buffers + Cache
available The available memory new apps can use without swapping.

As you can see, the free command gives less information than the /proc/meminfo file. However, it is easier to comprehend. The crucial metric is the available value, which shows how much RAM is still available for new applications.

You can customize the output of the command by adding flags at the end. Here are some useful flags for the command.

Options Result
-b Changes memory usage/availability figures to bytes
-k Changes memory usage/availability figures to kilobytes
-m Changes memory usage/availability figures to megabytes
-g Changes memory usage/availability figures to gigabytes
-l Shows detailed low and high memory statistics
-o Revert output to an old format (no -/+buffers/cache line)
-t Shows the total sum of RAM + swap
-s Updates the output every [delay] seconds
-c Updates the output by [count] times

Also Read: Master the Linux Free Command: 6 Examples For Sysadmins and DevOps Engineers

Method #3: Use the vmstat Command to See Virtual Memory Usage

vmstat (Virtual Memory Statistic Reporter) offers comprehensive insights into system performance aspects, including processes, memory usage, paging, block IO, traps, and CPU activity.

Here’s a sample output of the command:

vmstat Command to See Virtual Memory Usage

This output can confuse first-time users because of the details. Let’s go into these details to see what these headings represent.

  • Procs (Processes)
  • r: the number of processes pending execution.
  • B: The number of uninterrupted sleep processes
  • Memory
  • swpd: The utilized virtual memory size.
  • free: The unused memory space.
  • Buff: The portion of RAM used as buffers.
  • cache: The RAM space used for caching.
  • Swap
  • si: swapped-in memory from disc (/s).
    so: swapped memory for disc (/s)
  • IO
  • bi: Blocks received per second (blocks/s) from a block device.
  • bo: Blocks per second (blocks written to a block device)
  • CPU (These are percentages of total CPU time)
  • us: running time devoted to non-kernel code. (User time, pleasant time included)
  • sy: Duration of kernel execution. (Time on system)
  • id: Length of downtime.
  • wa: The amount of time spent waiting out for IO.
  • st: Virtual machine time that has been stolen.

Method #4: Use the top Command to Display Memory and CPU Usage

The top command shows detailed information about memory and CPU usage by process. It shows the following details about the system processes:

  • uptime
  • average weight
  • task execution,
  • Count of users who have logged in
  • CPU usage and utilization
  • swap system processes, and memory

Since the command constantly updates the data, you can use it to view memory consumption as it happens.

top Command to Display Memory and CPU Usage

The top command shows a near real-time view of the running processes. You can use various flags to see specific information about how processes consume system memory and CPU. We recommend using the man top command to see the list of these flags and options.

Method #5: Use the htop Command to See Each Process’s Memory Load

The htop command has a pretty similar output to the top command we discussed in the previous entry. The main benefits of using the htop commands are its user-friendly interface and improved control options.

Users prefer this command over the top command because of the multiple flags, the option to scroll vertically and horizontally, and the colorful output.

Let’s see the command in action.

#htop

htop Command to See Each Process's Memory Load

Let’s go into the details of this output:

The top part gives a summary of the system’s resource usage. This data gives you a quick overview and simplifies how to check memory usage in Linux systems.

The lower portion contains the details for every running process. This detailed breakdown helps you identify processes that are consuming too much memory and CPU time.

You can further change the details and format of the output by using the commands listed at the bottom.

You should note that htop is not installed by default on some Linux systems. If that’s the case with you, simply install it by running the following command :

$ sudo apt install htop

Do you know that not enough memory is often a common reason why servers lag and crash. That’s why we have included server specifications in our detailed overview of managed dedicated servers.

Use the GUI to Check Linux Memory Use

Command line tools are quick, but they often don’t have user-friendly output. If you prefer the GUI over the command line, you can use the System Monitor utility to visually check memory usage in Linux systems.

We’ll use Ubuntu to demonstrate, but the process of launching and using the utility remains the same on all distros.

Launching System Monitor is easy – simply go to Show Applications. Type System Monitor into the search box to open the utility.

Once the program is active, click the Resources tab. You can see a graphic representation of the memory usage in real time. You can also view historical data for better comparison and analysis.

Use the GUI to Check Linux Memory Use

Tips For Tracking Memory Usage in Linux

Monitoring memory usage in Linux is crucial for efficient system management. Here are five easy ways to keep track of your system’s memory resources.

  • Utilize basic commands like free or top to check current memory usage and identify memory-hungry processes. 
  • Keep an eye on swap memory usage, as excessive swapping can indicate memory issues. 
  • Explore graphical tools for a visual representation of memory usage statistics. These tools offer a more intuitive understanding of memory usage patterns.
  • Check the Processes tab of resource monitors to analyze process activity and memory utilization statistics in detail.
  • Engage with the current community for developers on platforms like Stack Exchange for the latest information on memory management techniques, including setting memory thresholds and ensuring effective memory management for optimal resource utilization.

Conclusion

Keeping track of your Linux system’s memory utilization is essential for maintaining its health and maximizing its performance. We described five simple commands you can try to check memory usage in Linux environments. By routinely utilizing these commands, Linux users and administrators can maintain their system’s effectiveness and responsiveness while avoiding potential performance concerns.

How to check memory usage in Linux is just one of the skills our support team uses every day to ensure our users have a high-performing bare metal infrastructure for their projects.

So, if you’re looking for a robust server for your Ubuntu projects, RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. Why is monitoring memory usage significant in Linux?

A1: Monitoring memory usage is crucial in Linux to ensure efficient resource allocation, prevent performance issues, and troubleshoot system bottlenecks. It helps maintain system stability and responsiveness.

Q. What is the free command, and how can I check memory usage?

A2: The free command displays information about total, used, and free memory in your system. Running free with options like ‘-m’ (megabytes) or ‘-g’ (gigabytes) provides memory statistics in a more human-readable format.

Q. What are the 5 commands to check memory usage in Linux?

 The 5 commands to check memory usage in Linux are free, top, vmstat, sar, and htop.

Q. How can I check memory usage on a Linux system using the command line?

You can check memory usage on a Linux system using commands such as free, top, vmstat, sar, or htop in the terminal.

Q. What is the command to check memory usage in Linux?

The command to check memory usage in Linux is the free command, which shows the total amount of free and used memory on your system.

Q. How to view memory statistics in Linux?

You can view memory statistics in Linux by using commands like free, top, vmstat, sar, or htop to check the memory usage and availability.

Q. How can I check the amount of memory used by Linux?

To check the amount of memory used by Linux, you can use commands like free, top, vmstat, sar, or htop to monitor the system’s memory usage.

Q. What are some ways to check memory usage on a Linux operating system?

 You can check memory usage on a Linux operating system by using commands like free, top, vmstat, sar, or htop to monitor the system’s memory usage and performance.

Q. How do I check the total amount of memory in use on a Linux system?

 You can check the total amount of memory in use on a Linux system by using commands like free, top, vmstat, sar, or htop to view the memory statistics.

Q. What are the commands to check both free and used memory on a Linux system?

The commands to check free and used memory on a Linux system are free, top, vmstat, sar, and htop, which provide insights into memory utilization.

Try this guide with our instant dedicated server for as low as 40 Euros