Use smem to visually display Linux memory usage
Insufficient physical memory has a great impact on the performance of Linux desktop and server systems. When your computer slows down, the first thing to do is to release the memory. Especially in a multi-user environment and a server environment that executes key tasks, memory consumption becomes more critical because multiple users and application threads will compete for more memory space at the same time.
To monitor the usage of various resources in the system (such as CPU or memory), graphical display is an efficient method. You can quickly analyze the resource consumption of each user and process through the graphical interface. This tutorial will introduce how to analyze memory usage in linux. The command line tool is smem.
Physical memory usage: RSS, PSS, and USS
Since Linux uses virtual memory, it is not that easy to accurately calculate the physical memory actually used by a process. Only knowing the virtual memory size of the process is not very useful, because the actual physical memory size still cannot be obtained.
- RSS (Resident set size), which can be queried using the top Command, is the most common memory indicator, indicating the physical memory size occupied by the process. However, adding the RSS values of each process usually exceeds the memory consumption of the entire system, because RSS contains the memory shared by each process.
- PSS (Proportional set size) will be more accurate. It average the size of the shared memory and then shares it with various processes.
- USS (Unique set size) is a part of PSS. It only calculates the memory size occupied by the process independently and does not contain any shared part.
Install Smem
Smem is a command line tool that can generate multiple memory consumption reports. It extracts the PSS/USS information of each process from the/proc file system and outputs the summary. It also has built-in chart generation capabilities, so it can easily analyze the memory usage of the entire system.
Install smem On Debian, Ubuntu, or Linux Mint
- $ Sudo apt-get install smem
Install Smem on Fedora or CentOS/RHEL
On CentOS/RHEL, you must first enable the EPEL repository.
- $ Sudo yum install smem python-matplotlib
Use smem to check memory usage
You can use smem in non-privileged mode, which can display the memory usage of all processes running by the current user and sort the memory by the size of the PSS.
$ smem
If you want the memory usage of all users in the system, you need to use the root permission to run smem.
$ sudo smem
You can also output reports by user:
$ sudo smem -u
Smem provides the following options to filter output results and supports filtering by ing, process, and user:
- -M <Regular Expression>
- -P <Regular Expression>
- -U <Regular Expression>
For more information about smem usage, see the user manual (man page ).
Display memory usage in a graphical manner using smem
Graphical reports can be used more conveniently and quickly. Smem supports two formats of Graph Display: histogram and pie chart.
Below are some examples of graphical display.
The following command line generates a histogram Based on the PSS/RSS value. Take user alice as an example.
$ sudo smem --bar name -c "pss uss" -U alice
In this example, a pie chart is generated, showing the memory usage of each process in the system:
$ sudo smem --pie name -c "pss"
In summary, smem is an easy-to-use memory analysis tool. With the formatted output of smem, you can perform automated analysis on memory usage reports and perform some automated processing measures. If you know other excellent memory detection tools, please let me know in the message area.
This article permanently updates the link address: