The Wayback Machine - https://web.archive.org/web/20240926162309/https://www.geeksforgeeks.org/tracing-memory-usage-linux/
Open In App

Tracing memory usage in Linux

Last Updated : 08 Jun, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Memory is a critical resource in computing because its usage affects the performance and stability of a system. It’s necessary to trace the memory usage of the system in order to determine the program that consumes all CPU resources or the program that is responsible for slowing down the activities of the CPU. 

Tracing memory usage also becomes necessary to determine the load on the server. Parsing the usage data enables the servers to be able to balance the load and serve the user’s request without slowing down the system. In Linux, there are several ways to trace memory usage, and we are going to discuss them.

Using the `free` command to check memory usage in Linux.

free Displays the amount of memory that is currently available and used by the system (both physical and swapped). free command gathers this data by parsing /proc/meminfo. By default, the amount of memory is displayed in kilobytes.

free
free

free

To display the memory usage in megabytes every 5 seconds, we use the following command. Watch command is used to execute a program periodically.

watch -n 5 free -m
watch -n 5 free -m

watch -n 5 free -m

Using the `vmstat` command to check memory usage in Linux.

vmstat vmstat command is used to display virtual memory statistics of the system. This command reports data about the memory, paging, disk, and CPU activities, etc. The first use of this command returns the data averages since the last reboot. Further users return the data based on sampling periods of long delays.

 vmstat
 vmstat

 vmstat

To view disk statics

vmstat -d
vmstat -d

vmstat -d

 Displays the amount of memory used and available.

vmstat -s
vmstat -s

vmstat -s

Using the `top` command to check memory usage in Linux.

top command displays all the currently running processes in the system. This command displays the list of processes and thread currently being handled by the kernel. The top command can also be used to monitor the total amount of memory usage. 

top

top

Thread-mode operation. Displays individual thread that are currently in the system. Without this command option, a summation of all thread in each process is displayed.

 top -H 
 top -H

 top -H 

Using the `/proc/meminfo ` location to check memory usage in Linux.

/proc/meminfo This file contains all the data about the memory usage. It provides the current memory usage details rather than old, stored values. 

cat /proc/meminfo
cat /proc/meminfo

cat /proc/meminfo

Using the `htop ` command to check memory usage in Linux.

htop is an interactive process viewer. This command is similar to top command except that it allows to scroll vertically and horizontally to allows users to view all processes running on the system, along with their full command line as well as viewing them as a process tree, selecting multiple processes and acting on them all at once.

To use htop we need to install it in our system.

sudo apt-get install htop

Now we can use the following command.

htop
htop

htop

Conclusion

In this article we are discussing different methods to trace memory usage in Linux as memory usage is an essential aspect of computing which is used to optimize the performance and stability of a system. We have discussed commands like free, vmstat, top, /proc/meminfo, and htop.  By using these commands, we can monitor memory usage and diagnose problems that may occur in a system. Overall, we can say monitoring memory usage in Linux system is important for efficient system management.



Similar Reads

Smem Tool To Display Memory Usage More Accurate in Linux
Multiple tools are available to monitor the memory usage on a Linux system. Memory management by monitoring memory usage is one of the important things to do on our Linux system, Smem is one of the memory usage monitoring tools available in Linux. Smem displays the memory usage of the processes on the command line, smem also displays a Graphical Ou
3 min read
How to Find Top Running Processes by Memory and CPU Usage
Every current (running) instance of a program is referred to as a process in Linux. There are running processes on every instance of the Linux operating system. , SSHd, SSH processes, and cron jobs are a few examples. A process is started by any application that has to be used. These processes frequently produce new processes. In Unix, each command
6 min read
Quickly Analyzing Disk Usage Statistics Using Filelight in Linux
Filelight is an application to visualize disk usage on your computer. It is open-source and free software that works on Linux and Windows systems. Filelight visualizes the disk in the form of a pie diagram. Features of Filelight: Scan local, remote or removable disks on the system.Configurable color schemes of filelightFile system navigation by mou
2 min read
Gdu – Faster Disk Usage Analyzer for Linux
GDU is a disk usage analyzer written in Go language for the Linux Operating systems. Gdu was actually made for SSD disks where it can totally utilize parallel processing. Although it works for HDDs too, but the performance gain is not so good.GDU can run in two modes one is interactive and another is non-interactive. It is a good tool to analyze di
3 min read
Discus - Show Colourised Disk Space Usage in Linux
Discus is the prettier version of the df command to check the disk space utilization in Linux. Discus has several cool features such as color, bar graphs, and smart formatting of numbers. You can also configure it in your own way after copying its main configuration file /etc/discusrc to ~/.discusrc. Installation For installing Discus in your Debia
2 min read
How to Monitor System Usage, Outages and Troubleshoot Linux Servers
As we know that Linux is very reliable and a great system administrator should always know the system's behavior and its utilization at every moment of time. So if an administrator or a user wants to monitor its complete system then they have to do the following Storage Space Utilization Linux provides two commands which are used to inspect storage
5 min read
MSFvenom Payload Creator (MSFPC) – Installation And Usage in kali linux
Creating effective payloads is key for penetration testing and security research. MSFvenom provides a very flexible payload generation system that can be used to avoid detection. This guide will teach beginners how to install and use the MSFvenom Payload Creator (MSFPC) in Kali Linux. You'll learn how to easily generate customized payload executabl
6 min read
Difference between Virtual memory and Cache memory
Cache Memory: Cache memory increases the accessing speed of CPU. It is not a technique but a memory unit i.e a storage device. In cache memory, recently used data is copied. Whenever the program is ready to be executed, it is fetched from main memory and then copied to the cache memory. But, if its copy is already present in the cache memory then t
2 min read
Random Access Memory (RAM) and Read Only Memory (ROM)
Memory is a fundamental component of computing systems, essential for performing various tasks efficiently. It plays a crucial role in how computers operate, influencing speed, performance, and data management. In the realm of computer memory, two primary types stand out: Random Access Memory (RAM) and Read-Only Memory (ROM). Understanding the diff
8 min read
Difference between Volatile Memory and Non-Volatile Memory
Memory is one of the most fundamental components in computing systems. Broadly, computer memory can be divided into two types namely volatile memory and non volatile memory. Even though both are crucial in the total functioning of the electronics, they are not interchangeable, each playing specific roles. Volatile memory deploys power in order to s
6 min read
How to Monitor Processor, Memory, Network Performance using dstat in Linux?
Do you want to run a quick performance test on your Linux machine? You may want to check the dstat command. Dstat is a versatile and efficient command that combines the features of several older tools such as vmstat, netstat, iostat, and ifstat to provide useful insights into Linux system performance. You can analyze virtual memory, network connect
2 min read
How to Clear RAM Memory Cache, Buffer and Swap Space on Linux
RAM memory is a very important component of the computer system. it helps store data and code currently used by the operating system. This article will show how to Clear RAM Memory Cache, Buffer, and Swap Space on Linux. In every system, we come across caches that have unwanted files and can harm our system, the same thing happens in the Linux cach
5 min read
Netcat - Basic Usage and Overview
Netcat is a Unix utility which reads and writes data across network connections using TCP or UDP protocol. Following tasks can be done easily with Netcat: Connect to a port of a target host.Listen to a certain port for any inbound connections.Send data across client and server once the connection is established.Transfer files across the network onc
3 min read
Pydf - Check disk space usage with colored output
Pydf is a command-line-based tool that shows the amount of disk space available on the mounted file system. This tool is similar to the df command, but pydf command gives output in different colors for different file systems.pydf tool is highly customizable, and this tool is written in the python language. Installation of Pydf Now let's see how to
2 min read
Shell Script to Check Disk Space Usage
Disk usage is a report generated by the Linux system about different disks available or created on the secondary memory. These disks are also known as partitions, they have their isolated filesystem. This facility provides us the measurements of different labels or features like Used space, Free space, Filesystem of the disk, etc. To see all these
3 min read
Difference Between Arch Linux and Kali Linux
Arch Linux is an open-source Linux-based Operating System that is freely available for use. It belongs to the Pacman-based Linux family. It is a light weighted OS for daily use and could even be used by professionals. It was first released in March 2002. It is a beginner-friendly Linux Operating System. Features of Arch Linux: Minimalist approach:
4 min read
Neofetch In Linux – Snap cool screenshots of your Linux
Neofetch is a fancy, highly customizable, and aesthetic command-line system information screenshot utility tool. Written in the Bash scripting language, it works inside a terminal window, on triggering up the command it by default displays the operating system, software, and hardware of your system on the right side of the column alongside an ASCII
4 min read
Exodus - Copy Linux Binaries From One Linux System
Exodus is an easy-to-implement program, that is used for bundling dependencies, and also helps to effectively copy Linux ELF binaries from one to another machine securely, and this is very handy when you don't have root access, also if there are issues in the availability of the packages in the Linux distribution, Commonly Server oriented distribut
3 min read
Basic CentOS Linux Commands in linux
CentOS is a free and open-source operating system that aims to provide a stable reliable, and community-supported platform for servers and other enterprise applications. In this article, we will be covering CentOS Linux basics commands and functions of CentOS and also we will look into the advanced commands. These CentOS commands allow you to manag
3 min read
Linux on Azure – Linux Distributions
Azure, the cloud computing platform from Microsoft, offers a playground for deploying and managing your Linux-based operating systems. Think of it as a canvas of boundless resources, security, and scalability, painted onto which you can unleash the boundless creativity and flexibility of Linux. This powerful synergy unlocks a world of opportunity,
10 min read
Operating Systems | Memory Management | Question 1
Which of the following page replacement algorithms suffers from Belady’s anomaly? (A) FIFO (B) LRU (C) Optimal Page Replacement (D) Both LRU and FIFO Answer: (A) Explanation: Belady’s anomaly proves that it is possible to have more page faults when increasing the number of page frames while using the First in First Out (FIFO) page replacement algor
1 min read
Memory Allocation Techniques | Mapping Virtual Addresses to Physical Addresses
Prerequisite : Requirements of Memory Management System, Logical and Physical Address Memory Allocation Techniques:To store the data and to manage the processes, we need a large-sized memory and, at the same time, we need to access the data as fast as possible. But if we increase the size of memory, the access time will also increase and, as we kno
5 min read
Allocating kernel memory (buddy system and slab system)
Prerequisite - Buddy System Introduction: Allocating kernel memory is a critical task in operating system design, as the kernel needs to manage memory efficiently and effectively to ensure optimal system performance. Two common methods for allocating kernel memory are the buddy system and the slab system. The buddy system is a memory allocation alg
9 min read
Requirements of Memory Management System
Memory management keeps track of the status of each memory location, whether it is allocated or free. It allocates the memory dynamically to the programs at their request and frees it for reuse when it is no longer needed. Memory management meant to satisfy some requirements that we should keep in mind. These Requirements of memory management are:
5 min read
Algorithm for implementing Distributed Shared Memory
Distributed shared memory(DSM) system is a resource management component of distributed operating system that implements shared memory model in distributed system which have no physically shared memory. The shared memory model provides a virtual address space which is shared by all nodes in a distributed system. The central issues in implementing D
3 min read
Chat application between two processes using signals and shared memory
Prerequisite: C signal handling, IPC through shared memory A signal is used in the UNIX system to notify a process that a particular event has occurred. A signal may be received either synchronously or asynchronously depending on the source and the reason for the event being signalled. A signal must follow the following pattern - 1. A signal is gen
3 min read
Cache Memory Design
Prerequisite - Cache Memory A detailed discussion of the cache style is given in this article. The key elements are concisely summarized here. we are going to see that similar style problems should be self-addressed in addressing storage and cache style. They represent the subsequent categories: Cache size, Block size, Mapping function, Replacement
5 min read
Ferro-electric Random Access Memory
Ferro-electric Random Access Memory (FRAM) is a type of Random Access Memory, which uses a ferro-electric capacitor to achieve it's non-volatility (content is not lost when power is turned off).The di-electric constant of a ferroelectric material usually has a high value. The most widely used ferroelectric material is PZT (Lead Zirconate Titanate).
2 min read
Magnetic Random Access Memory (M-RAM)
MRAM stands for magnetoresistive random access memory and is a non-volatile type of RAM. Magnetic state refers to the electrical resistance of a metal when it is placed in a magnetic field. The MRAM uses magnetic states and magnetisation direction in a ferromagnetic material(a material which is highly susceptible to magnetization to store data bits
4 min read
Implementing Non-contiguous Memory Management Techniques
Memory Management Techniques are basic techniques that are used in managing the memory in operating system. Memory Management Techniques are basically classified into two categories: (i) Contiguous (ii) Non-contiguous We have already discussed the implementation of contiguous in the article Implementation of Contiguous Memory Management Techniques.
3 min read