Smem – Reports Memory Consumption Per-Process and Per-User Basis in Linux

[‘

n

Memory management in terms of monitoring memory usage is one important thing to do on your Linux system, there are many tools available for monitoring your memory usage that you can find on different Linux distributions. But they work in different ways, in this how to guide, we shall take a look at how to install and use one such tool called smem.

n

Don’t Miss: 20 Command Line Tools to Monitor Linux Performance

n

Smem is a command-line memory reporting tool thats gives a user diverse reports on memory usage on a Linux system. There is one unique thing about smem, unlike other traditional memory reporting tools, it reports PSS (Proportional Set Size), a more meaningful representation of memory usage by applications and libraries in a virtual memory setup.

n

Smem - Linux Memory Reporting Tool
Smem – Linux Memory Reporting Tool

n

Existing traditional tools focus mainly on reading RSS (Resident Set Size) which is a standard measure to monitor memory usage in a physical memory scheme, but tends to overestimate memory usage by applications.

n

PSS on the other hand, gives a reasonable measure by determining the “fair-share” of memory used by applications and libraries in a virtual memory scheme.

n

You can read this guide (about memory RSS and PSS) to understand memory consumption in a Linux system, but let us proceed to looking at some of the features of smem.

n

Features of Smem Tool

n

    n

  1. System overview listing
  2. n

  3. Listings and also filtering by process, mappings or user
  4. n

  5. Using data from /proc filesystem
  6. n

  7. Configurable listing columns from several data sources
  8. n

  9. Configurable output units and percentages
  10. n

  11. Easy to configure headers and totals in listings
  12. n

  13. Using data snapshots from directory mirrors or compressed tar files
  14. n

  15. Built-in chart generation mechanism
  16. n

  17. Lightweight capture tool used in embedded systems
  18. n

n

How to Install Smem – Memory Reporting Tool in Linux

n

Before you proceed with installation of smem, your system must meet the following requirements:

n

    n

  1. modern kernel (> 2.6.27 or so)
  2. n

  3. a recent version of Python (2.4 or so)
  4. n

  5. optional matplotlib library for generation of charts
  6. n

n

Most of the today’s Linux distributions comes with latest Kernel version with Python 2 or 3 support, so the only requirement is to install matplotlib library which is used to generate nice charts.

n

On RHEL, CentOS and Fedora

n

First enable EPEL (Extra Packages for Enterprise Linux) repository and then install as follows:

n

# yum install smem python-matplotlib python-tkrn

n

On Debian and Ubuntu

n

$ sudo apt-get install smemrn

n

On Linux Mint

n

$ sudo apt-get install smem python-matplotlib python-tkrn

n

on Arch Linux

n

Use this AUR repository.

n

How to Use Smem – Memory Reporting Tool in Linux

n

To view a report of memory usage across the whole system, by all system users, run the following command:

n

$ sudo smem rn

n

Monitor Memory Usage of Linux System

n

 PID User     Command                         Swap      USS      PSS      RSS rn 6367 tecmint  cat                                0      100      145     1784 rn 6368 tecmint  cat                                0      100      147     1676 rn 2864 tecmint  /usr/bin/ck-launch-session         0      144      165     1780 rn 7656 tecmint  gnome-pty-helper                   0      156      178     1832 rn 5758 tecmint  gnome-pty-helper                   0      156      179     1916 rn 1441 root     /sbin/getty -8 38400 tty2          0      152      184     2052 rn 1434 root     /sbin/getty -8 38400 tty5          0      156      187     2060 rn 1444 root     /sbin/getty -8 38400 tty3          0      156      187     2060 rn 1432 root     /sbin/getty -8 38400 tty4          0      156      188     2124 rn 1452 root     /sbin/getty -8 38400 tty6          0      164      196     2064 rn 2619 root     /sbin/getty -8 38400 tty1          0      164      196     2136 rn 3544 tecmint  sh -c /usr/lib/linuxmint/mi        0      212      224     1540 rn 1504 root     acpid -c /etc/acpi/events -        0      220      236     1604 rn 3311 tecmint  syndaemon -i 0.5 -K -R             0      252      292     2556 rn 3143 rtkit    /usr/lib/rtkit/rtkit-daemon        0      300      326     2548 rn 1588 root     cron                               0      292      333     2344 rn 1589 avahi    avahi-daemon: chroot helpe         0      124      334     1632 rn 1523 root     /usr/sbin/irqbalance               0      316      343     2096 rn  585 root     upstart-socket-bridge --dae        0      328      351     1820 rn 3033 tecmint  /usr/bin/dbus-launch --exit        0      328      360     2160 rn 1346 root     upstart-file-bridge --daemo        0      348      371     1776 rn 2607 root     /usr/bin/xdm                       0      188      378     2368 rn 1635 kernoops /usr/sbin/kerneloops               0      352      386     2684 rn  344 root     upstart-udev-bridge --daemo        0      400      427     2132 rn 2960 tecmint  /usr/bin/ssh-agent /usr/bin        0      480      485      992 rn 3468 tecmint  /bin/dbus-daemon --config-f        0      344      515     3284 rn 1559 avahi    avahi-daemon: running [tecm        0      284      517     3108 rn 7289 postfix  pickup -l -t unix -u -c            0      288      534     2808 rn 2135 root     /usr/lib/postfix/master            0      352      576     2872 rn 2436 postfix  qmgr -l -t unix -u                 0      360      606     2884 rn 1521 root     /lib/systemd/systemd-logind        0      600      650     3276 rn 2222 nobody   /usr/sbin/dnsmasq --no-reso        0      604      669     3288 rn....rn

n

When a normal user runs smem, it displays memory usage by process that the user has started, the processes are arranged in order of increasing PSS.

n

Take a look at the output below on my system for memory usage by processes started by user aaronkilik:

n

$ smemrn

n

Monitor User Memory Usage in Linux

n

 PID User     Command                         Swap      USS      PSS      RSS rn 6367 tecmint  cat                                0      100      145     1784 rn 6368 tecmint  cat                                0      100      147     1676 rn 2864 tecmint  /usr/bin/ck-launch-session         0      144      166     1780 rn 3544 tecmint  sh -c /usr/lib/linuxmint/mi        0      212      224     1540 rn 3311 tecmint  syndaemon -i 0.5 -K -R             0      252      292     2556 rn 3033 tecmint  /usr/bin/dbus-launch --exit        0      328      360     2160 rn 3468 tecmint  /bin/dbus-daemon --config-f        0      344      515     3284 rn 3122 tecmint  /usr/lib/gvfs/gvfsd                0      656      801     5552 rn 3471 tecmint  /usr/lib/at-spi2-core/at-sp        0      708      864     5992 rn 3396 tecmint  /usr/lib/gvfs/gvfs-mtp-volu        0      804      914     6204 rn 3208 tecmint  /usr/lib/x86_64-linux-gnu/i        0      892     1012     6188 rn 3380 tecmint  /usr/lib/gvfs/gvfs-afc-volu        0      820     1024     6396 rn 3034 tecmint  //bin/dbus-daemon --fork --        0      920     1081     3040 rn 3365 tecmint  /usr/lib/gvfs/gvfs-gphoto2-        0      972     1099     6052 rn 3228 tecmint  /usr/lib/gvfs/gvfsd-trash -        0      980     1153     6648 rn 3107 tecmint  /usr/lib/dconf/dconf-servic        0     1212     1283     5376 rn 6399 tecmint  /opt/google/chrome/chrome -        0      144     1409    10732 rn 3478 tecmint  /usr/lib/x86_64-linux-gnu/g        0     1724     1820     6320 rn 7365 tecmint  /usr/lib/gvfs/gvfsd-http --        0     1352     1884     8704 rn 6937 tecmint  /opt/libreoffice5.0/program        0     1140     2328     5040 rn 3194 tecmint  /usr/lib/x86_64-linux-gnu/p        0     1956     2405    14228 rn 6373 tecmint  /opt/google/chrome/nacl_hel        0     2324     2541     8908 rn 3313 tecmint  /usr/lib/gvfs/gvfs-udisks2-        0     2460     2754     8736 rn 3464 tecmint  /usr/lib/at-spi2-core/at-sp        0     2684     2823     7920 rn 5771 tecmint  ssh -p 4521 [emailxa0protected]        0     2544     2864     6540 rn 5759 tecmint  /bin/bash                          0     2416     2923     5640 rn 3541 tecmint  /usr/bin/python /usr/bin/mi        0     2584     3008     7248 rn 7657 tecmint  bash                               0     2516     3055     6028 rn 3127 tecmint  /usr/lib/gvfs/gvfsd-fuse /r        0     3024     3126     8032 rn 3205 tecmint  mate-screensaver                   0     2520     3331    18072 rn 3171 tecmint  /usr/lib/mate-panel/notific        0     2860     3495    17140 rn 3030 tecmint  x-session-manager                  0     4400     4879    17500 rn 3197 tecmint  mate-volume-control-applet         0     3860     5226    23736 rn...rn

n

There are many options to invoke while using smem, for example, to view system wide memory consumption, run the following command:

n

$ sudo smem -wrn

n

Monitor System Wide Memory User Consumption

n

Area                           Used      Cache   Noncache rnfirmware/hardware                 0          0          0 rnkernel image                      0          0          0 rnkernel dynamic memory       1425320    1291412     133908 rnuserspace memory            2215368     451608    1763760 rnfree memory                 4424936    4424936          0 rn

n

To view memory usage on a per-user basis, run the command below:

n

$ sudo smem -urn

n

Monitor Memory Consumption Per-User Basis in Linux

n

User     Count     Swap      USS      PSS      RSS rnrtkit        1        0      300      326     2548 rnkernoops     1        0      352      385     2684 rnavahi        2        0      408      851     4740 rnpostfix      2        0      648     1140     5692 rnmessagebus     1        0     1012     1173     3320 rnsyslog       1        0     1396     1419     3232 rnwww-data     2        0     5100     6572    13580 rnmpd          1        0     7416     8302    12896 rnnobody       2        0     4024    11305    24728 rnroot        39        0   323876   353418   496520 rntecmint     64        0  1652888  1815699  2763112 rn

n

You can also report memory usage by mappings as follows:

n

$ sudo smem -mrn

n

Monitor Memory Usage by Mappings in Linux

n

Map                                       PIDs   AVGPSS      PSS rn/dev/fb0                                     1        0        0 rn/home/tecmint/.cache/fontconfig/7ef2298f    18        0        0 rn/home/tecmint/.cache/fontconfig/c57959a1    18        0        0 rn/home/tecmint/.local/share/mime/mime.cac    15        0        0 rn/opt/google/chrome/chrome_material_100_p     9        0        0 rn/opt/google/chrome/chrome_material_200_p     9        0        0 rn/usr/lib/x86_64-linux-gnu/gconv/gconv-mo    41        0        0 rn/usr/share/icons/Mint-X-Teal/icon-theme.    15        0        0 rn/var/cache/fontconfig/0c9eb80ebd1c36541e    20        0        0 rn/var/cache/fontconfig/0d8c3b2ac0904cb8a5    20        0        0 rn/var/cache/fontconfig/1ac9eb803944fde146    20        0        0 rn/var/cache/fontconfig/3830d5c3ddfd5cd38a    20        0        0 rn/var/cache/fontconfig/385c0604a188198f04    20        0        0 rn/var/cache/fontconfig/4794a0821666d79190    20        0        0 rn/var/cache/fontconfig/56cf4f4769d0f4abc8    20        0        0 rn/var/cache/fontconfig/767a8244fc0220cfb5    20        0        0 rn/var/cache/fontconfig/8801497958630a81b7    20        0        0 rn/var/cache/fontconfig/99e8ed0e538f840c56    20        0        0 rn/var/cache/fontconfig/b9d506c9ac06c20b43    20        0        0 rn/var/cache/fontconfig/c05880de57d1f5e948    20        0        0 rn/var/cache/fontconfig/dc05db6664285cc2f1    20        0        0 rn/var/cache/fontconfig/e13b20fdb08344e0e6    20        0        0 rn/var/cache/fontconfig/e7071f4a29fa870f43    20        0        0 rn....rn

n

There are also options for filtering smem output and we shall look at two examples here.

n

To filter output by username, invoke the -u or --userfilter="regex" option as below:

n

$ sudo smem -urn

n

Report Memory Usage by User

n

User     Count     Swap      USS      PSS      RSS rnrtkit        1        0      300      326     2548 rnkernoops     1        0      352      385     2684 rnavahi        2        0      408      851     4740 rnpostfix      2        0      648     1140     5692 rnmessagebus     1        0     1012     1173     3320 rnsyslog       1        0     1400     1423     3236 rnwww-data     2        0     5100     6572    13580 rnmpd          1        0     7416     8302    12896 rnnobody       2        0     4024    11305    24728 rnroot        39        0   323804   353374   496552 rntecmint     64        0  1708900  1871766  2819212 rn

n

To filter output by process name, invoke the -P or --processfilter="regex" option as follows:

n

$ sudo smem --processfilter="firefox"rn

n

Report Memory Usage by Process Name

n

PID User     Command                         Swap      USS      PSS      RSS rn 9212 root     sudo smem --processfilter=f        0     1172     1434     4856 rn 9213 root     /usr/bin/python /usr/bin/sm        0     7368     7793    11984 rn 4424 tecmint  /usr/lib/firefox/firefox           0   931732   937590   961504 rn

n

Output formatting can be very important, and there are options to help you format memory reports and we shall take a look at few examples below.

n

To show desired columns in the report, use -c or --columns option as follows:

n

$ sudo smem -c "name user pss rss"rn

n

Report Memory Usage by Columns

n

Name                     User          PSS      RSS rncat                      tecmint       145     1784 rncat                      tecmint       147     1676 rnck-launch-sessi          tecmint       165     1780 rngnome-pty-helpe          tecmint       178     1832 rngnome-pty-helpe          tecmint       179     1916 rngetty                    root          184     2052 rngetty                    root          187     2060 rngetty                    root          187     2060 rngetty                    root          188     2124 rngetty                    root          196     2064 rngetty                    root          196     2136 rnsh                       tecmint       224     1540 rnacpid                    root          236     1604 rnsyndaemon                tecmint       296     2560 rnrtkit-daemon             rtkit         326     2548 rncron                     root          333     2344 rnavahi-daemon             avahi         334     1632 rnirqbalance               root          343     2096 rnupstart-socket-          root          351     1820 rndbus-launch              tecmint       360     2160 rnupstart-file-br          root          371     1776 rnxdm                      root          378     2368 rnkerneloops               kernoops      386     2684 rnupstart-udev-br          root          427     2132 rnssh-agent                tecmint       485      992 rn...rn

n

You can invoke the -p option to report memory usage in percentages, as in the command below:

n

$ sudo smem -prn

n

Report Memory Usage by Percentages

n

 PID User     Command                         Swap      USS      PSS      RSS rn 6367 tecmint  cat                            0.00%    0.00%    0.00%    0.02% rn 6368 tecmint  cat                            0.00%    0.00%    0.00%    0.02% rn 9307 tecmint  sh -c { sudo /usr/lib/linux    0.00%    0.00%    0.00%    0.02% rn 2864 tecmint  /usr/bin/ck-launch-session     0.00%    0.00%    0.00%    0.02% rn 3544 tecmint  sh -c /usr/lib/linuxmint/mi    0.00%    0.00%    0.00%    0.02% rn 5758 tecmint  gnome-pty-helper               0.00%    0.00%    0.00%    0.02% rn 7656 tecmint  gnome-pty-helper               0.00%    0.00%    0.00%    0.02% rn 1441 root     /sbin/getty -8 38400 tty2      0.00%    0.00%    0.00%    0.03% rn 1434 root     /sbin/getty -8 38400 tty5      0.00%    0.00%    0.00%    0.03% rn 1444 root     /sbin/getty -8 38400 tty3      0.00%    0.00%    0.00%    0.03% rn 1432 root     /sbin/getty -8 38400 tty4      0.00%    0.00%    0.00%    0.03% rn 1452 root     /sbin/getty -8 38400 tty6      0.00%    0.00%    0.00%    0.03% rn 2619 root     /sbin/getty -8 38400 tty1      0.00%    0.00%    0.00%    0.03% rn 1504 root     acpid -c /etc/acpi/events -    0.00%    0.00%    0.00%    0.02% rn 3311 tecmint  syndaemon -i 0.5 -K -R         0.00%    0.00%    0.00%    0.03% rn 3143 rtkit    /usr/lib/rtkit/rtkit-daemon    0.00%    0.00%    0.00%    0.03% rn 1588 root     cron                           0.00%    0.00%    0.00%    0.03% rn 1589 avahi    avahi-daemon: chroot helpe     0.00%    0.00%    0.00%    0.02% rn 1523 root     /usr/sbin/irqbalance           0.00%    0.00%    0.00%    0.03% rn  585 root     upstart-socket-bridge --dae    0.00%    0.00%    0.00%    0.02% rn 3033 tecmint  /usr/bin/dbus-launch --exit    0.00%    0.00%    0.00%    0.03% rn....rn

n

The command below will show totals at the end of each column of the output:

n

$ sudo smem -trn

n

Report Total Memory Usage Count

n

PID User     Command                         Swap      USS      PSS      RSS rn 6367 tecmint  cat                                0      100      139     1784 rn 6368 tecmint  cat                                0      100      141     1676 rn 9307 tecmint  sh -c { sudo /usr/lib/linux        0       96      158     1508 rn 2864 tecmint  /usr/bin/ck-launch-session         0      144      163     1780 rn 3544 tecmint  sh -c /usr/lib/linuxmint/mi        0      108      170     1540 rn 5758 tecmint  gnome-pty-helper                   0      156      176     1916 rn 7656 tecmint  gnome-pty-helper                   0      156      176     1832 rn 1441 root     /sbin/getty -8 38400 tty2          0      152      181     2052 rn 1434 root     /sbin/getty -8 38400 tty5          0      156      184     2060 rn 1444 root     /sbin/getty -8 38400 tty3          0      156      184     2060 rn 1432 root     /sbin/getty -8 38400 tty4          0      156      185     2124 rn 1452 root     /sbin/getty -8 38400 tty6          0      164      193     2064 rn 2619 root     /sbin/getty -8 38400 tty1          0      164      193     2136 rn 1504 root     acpid -c /etc/acpi/events -        0      220      232     1604 rn 3311 tecmint  syndaemon -i 0.5 -K -R             0      260      298     2564 rn 3143 rtkit    /usr/lib/rtkit/rtkit-daemon        0      300      324     2548 rn 1588 root     cron                               0      292      326     2344 rn 1589 avahi    avahi-daemon: chroot helpe         0      124      332     1632 rn 1523 root     /usr/sbin/irqbalance               0      316      340     2096 rn  585 root     upstart-socket-bridge --dae        0      328      349     1820 rn 3033 tecmint  /usr/bin/dbus-launch --exit        0      328      359     2160 rn 1346 root     upstart-file-bridge --daemo        0      348      370     1776 rn 2607 root     /usr/bin/xdm                       0      188      375     2368 rn 1635 kernoops /usr/sbin/kerneloops               0      352      384     2684 rn  344 root     upstart-udev-bridge --daemo        0      400      426     2132 rn.....rn-------------------------------------------------------------------------------rn  134 11                                          0  2171428  2376266  3587972 rn

n

Further more, there are options for graphical reports that you can also use and we shall dive into them in this sub section.

n

You can produce a bar graph of processes and their PSS and RSS values, in the example below, we produce a bar graph of processes owned by the root user.

n

The vertical plane shows the PSS and RSS measure of processes and the horizontal plane represents each root user process:

n

$ sudo smem --userfilter="root" --bar pid -c"pss rss"rn

n

Linux Memory Usage in PSS and RSS Values
Linux Memory Usage in PSS and RSS Values

n

You can also produce a pie chart showing processes and their memory consumption based on PSS or RSS values. The command below outputs a pie chart for processes owned by root user measuring values.

n

The --pie name means label by name and -s option helps to sort by PSS value.

n

$ sudo smem --userfilter="root" --pie name -s pssrn

n

Linux Memory Consumption by Processes
Linux Memory Consumption by Processes

n

There are many other known fields apart from PSS and RSS used for labeling charts:

n

To get help, simply type, smem -h or visit the manual entry page.

n

We shall stop here with smem, but to understand it better, use it with many other options that you can find in the man page. As usual you can use the comment section below to express any thoughts or concerns.

n

Reference Links: https://www.selenic.com/smem/

n

‘]