A way to visualize memory usage in Linux

Source: Internet
Author: User
Tags memory usage regular expression centos linux mint

A lack of physical memory affects both the performance of Linux desktop systems and server systems. The first thing to do when your computer slows down is to free up memory. In particular, in a multiuser environment and in a mission-critical server environment, 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 within the system (such as CPU or memory), graphical display is an efficient way to quickly analyze the resource consumption of each user and process through a graphical interface. This tutorial will show you how to graphically analyze memory usage under Linux, and using the command-line tool is Smem.

Physical memory Usage: RSS, PSS, and USS

Because Linux uses virtual memory, it is not as easy to accurately compute the physical memory that a process actually uses. It is not very useful to know only the virtual memory size of a process, because it is still not possible to get the actual allocated physical memory size.

RSS (resident set size), which can be queried using the top command, is the most commonly used memory metric that represents the amount of physical memory the process occupies. However, adding the RSS values of each process typically exceeds the memory consumption of the entire system, because RSS contains memory shared between processes.

PSS (proportional set size) is more accurate, averaging the size of shared memory and then spreading it across processes.

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

Install Smem

Smem is a command-line tool that generates a variety of memory consumption reports that extracts the Pss/uss information of each process from the/proc file system and summarizes the output. It also built the ability to generate graphs, so it is easy to analyze the memory usage of the entire 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 the Centos/rhel, you first have to enable the Epel warehouse.

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 shows the memory usage of all processes running by the current user and sorts them according to the size of the PSS.

The code is as follows:

$ smem

If you want to get the memory usage of all the users in the whole system, you need to use ROOT 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 for filtering out the output, supporting filtering by mapping (mapping), process, and user three dimensions:

-M < regular expression >

-P < Regular expression >

-U < Regular expression >

To find out more about SMEM use, you can query the user's Manual (man page).

Graphical display of memory usage using SMEM

Graphical reports can be more convenient and quick to use. Smem supports graphical display in two formats: histograms and pie charts.

Here are some examples of graphical displays.

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 showing the PSS memory usage for each process in the system:

The code is as follows:

$ sudo smem--pie name-c "PSS"

Generally speaking, Smem is an easy-to-use memory analysis tool. With Smem formatted output, you can automate the analysis of memory usage reports and perform some automated processing. If you know other good memory detection tools, please tell me in the message area.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.