Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to visually display memory usage in Linux

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to visually display memory footprint in Linux". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to visually display memory usage in Linux".

Insufficient physical memory has a great impact on the performance of both Linux desktop and server systems. When your computer slows down, the first thing to do is to free up memory. Especially in a multi-user environment and a server environment that performs critical tasks, memory consumption becomes more critical because multiple users and application threads compete for more memory space at the same time.

If you want to monitor the use of various resources in the system (such as CPU or memory), graphical display is an efficient method, through the graphical interface can quickly analyze the resource consumption of each user and process. This tutorial will introduce the method of graphically analyzing memory usage under linux, using the command line tool smem.

Physical memory usage: RSS, PSS, and USS

Because Linux uses virtual memory (virtual memory), it is not easy to calculate exactly how much physical memory a process actually uses. It is not very useful to know only the virtual memory size of the process, because it is still impossible to get the actual physical memory allocated.

RSS (Resident set size), which can be queried using the top command, is the most commonly used memory metric, indicating the amount of physical memory consumed by the process. However, adding up the RSS values of each process usually exceeds the memory consumption of the entire system because the RSS contains shared memory among processes.

PSS (Proportional set size) is more accurate, averaging the size of shared memory and then allocating it to processes.

USS (Unique set size) is its own part of PSS, which only calculates the amount of memory occupied by the process alone and does not contain any shared parts.

Install Smem

Smem is a command-line tool that can generate a variety of memory consumption reports. It extracts the PSS/USS information of each process from the / proc file system and outputs it together. It also has built-in ability to generate charts, so it can easily analyze the memory usage of the whole system.

Install smem on Debian, Ubuntu, or Linux Mint

The code is as follows:

$sudo apt-get install smem

Install Smem on Fedora or CentOS/RHEL

On CentOS/RHEL, you first have to enable the EPEL repository.

The code is as follows:

$sudo yum install smem python-matplotlib

Use smem to check memory usage

You can use smem in unprivileged mode, which displays the memory usage of all processes currently running by the user and sorts them by the size of the PSS.

The code is as follows:

$smem

If you want to get the memory usage of all users in the entire system, you need to use root permissions to run smem.

The code is as follows:

$sudo smem

You can also output reports by user dimension:

The code is as follows:

$sudo smem-u

Smem provides the following options to filter the output, which supports filtering by mapping mode (mapping), process, and user:

-M

-P

-U

To learn more about how to use smem, consult the user's manual (man page).

Use smem to graphically display memory usage

Graphical reports will be easier and faster to use. Smem supports two formats of graphic display: histogram and pie chart.

Here are some examples of graphical display.

The following command line generates a histogram based on the PSS/ RSS value, taking the user alice as an example.

The code is as follows:

$sudo smem-- bar name-c "pss uss"-U alice

This example generates a pie chart that shows the PSS memory usage of each process in the system:

The code is as follows:

$sudo smem-pie name-c "pss"

In a nutshell, smem is a convenient memory analysis tool. With the formatted output of smem, you can automate the analysis of memory usage reports and perform some automated processing measures.

At this point, I believe you have a deeper understanding of "how to visually display memory footprint in Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report