smem - Process Memory Usage Report

This section provides a tutorial on how to install 'smem' and use it to report memory usage of each running process.

What Is smem? - "smem" is a tool that can give numerous reports on memory usage on Ubuntu systems. Here is what I did to install and use "smem" on my Ubuntu 18 computer.

1. Install "smem".

herong$ sudo apt install smem 

2. Run "smem" with default options. It displays memory usage of each process.

herong$ smem

  PID User    Command                       Swap   USS   PSS    RSS
 1849 root    /usr/libexec/sssd/sssd_nss      88  4204  4885  11288
59583 apache  php-fpm: pool www               48  3712  4890  19232
53605 apache  /usr/sbin/httpd -DFOREGROUN    100  4112  5040  15172
 1221 root    /usr/lib/systemd/systemd-ud     16  5456  5556   9724
 2484 root    /usr/sbin/rpc.mountd          7936  6384  6433   7916
 2479 rpcuser /usr/sbin/rpc.statd          16156  9124  9137  10728
...

The memory usage fields in the output are:

3. Run "smem -t" to report the total counts at the end.

herong$ smem -t

  PID User    Command                 Swap     USS     PSS     RSS
...
 1169 root    /usr/lib/systemd/sy        0   23964   50023   82168
 2479 rpcuser /usr/sbin/rpc.statd    16156    9124    9137   10728
 1998 mysql   /usr/libexec/mysqld   388728  653368  653741  656520
------------------------------------------------------------------
  148 19                           6479428 6413180 6508005 6812112

4. Run "smem -s uss" to sort the output by USS size.

herong$ sudo smem -s uss

  PID User  Command                      Swap  USS  PSS  RSS
 2921 root  /usr/sbin/dnsmasq --conf-fi   444    0    2    4
 1484 root  /usr/sbin/rpc.idmapd          608    4    4    8
 1532 root  /usr/sbin/mcelog --ignoreno   152    4    4    8
...

5. Run "smem -r -s uss" to sort the output by USS size in descending order.

herong$ sudo smem -r -s uss

  PID User   Command                 Swap     USS     PSS     RSS
 2330 herong /usr/bin/gnome-shel   199444  174376  185182  207636 
 2666 herong /usr/bin/gnome-soft    87120  153740  154675  162228 
 2202 herong /usr/lib/xorg/Xorg     35220   31972   33908   38216 
...

6. Run "smem -w" to report systemwide memory usage summary.

herong$ smem -w

Area                           Used      Cache   Noncache
firmware/hardware                 0          0          0
kernel image                      0          0          0
kernel dynamic memory       7024568    5911676    1112892
userspace memory            6503044     202880    6300164
free memory                 2203836    2203836          0

7. Run "smem -m" to report memory usage of each program file that is loaded in the memory.

herong$ sudo smem -m

Map                                       PIDs   AVGPSS      PSS
/dev/dri/card0                               1        0        0
/dev/shm/squid-cf__metadata.shm              1        0        0
/dev/shm/squid-cf__queues.shm                1        0        0
/dev/shm/squid-cf__readers.shm               1        0        0
/etc/udev/hwdb.bin                           1        0        0
...

Compare "ps" and "smem" Reports - To help our understanding memory usage fields reported by "ps" and "smem" commands, let's compare their output for a single process:

herong$ smem -P firewalld
  PID User  Command                       Swap  USS  PSS  RSS
 1661 root  /usr/libexec/platform-pytho  25436   12   12   16

herong$ ps -o pid,euser,%mem,rss,drs,trs,sz,vsz,comm -p 1661
  PID EUSER  %MEM  RSS     DRS  TRS     SZ     VSZ  COMMAND
 1661 root    0.0    0  321436    0  80359  321436  firewalld

Apparently, the 2 reports do not match at all. I am not sure why.

Table of Contents

 About This Book

 Introduction to Ubuntu Systems

 GNOME - Desktop Interface and Environment

 Shell - The Command-Line Interpreter

 Process Management

Memory Management

 Layers of Memory and Access Speed

 List CPU Caches and Their Sizes

 Virtual Memory vs. Physical Memory

 Buffer Memory and Cache Memory

 Verify Cache Memory with "cp" Command

 What Is Swap Space

 Virtual Memory Mapping and Page Table

 "ps -o rss,drs,trs,vsz,sz" - Process Status Options

smem - Process Memory Usage Report

 pmap - Process Memory Map

 /proc/{id}/maps - Process Memory Map

 /proc/{id}/smaps - Process Memory Map Details

 earlyoom - A Simple OOM Killer

 Files and Directories

 APT (Advanced Package Tool)

 Network Connection on Ubuntu

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Administrative Tasks

 References

 Full Version in PDF/EPUB