Linux Tutorials - Herong's Tutorial Examples - v5.45, by Herong Yang
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 Linux systems. Here is what I did to install and use "smem" on my CentOS 8 computer.
1. Intall "smem".
herong$ sudo dnf install smem Installed: smem-1.5-6.el8.noarch
2. Run "smem" with default options. It displays memory usage of each process.
herong$ sudo 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$ sudo 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 1998 mysql /usr/libexec/mysqld 388728 653392 653749 656520 3399 gdm /usr/bin/gnome-shell 142116 53212 54859 59672 3705 root /usr/libexec/package 97520 17880 18517 22436 ...
6. Run "smem -w" to report systemwide memory usage summary.
herong$ sudo 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$ sudo 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
Cockpit - Web Portal for Administrator
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
Virtual Memory Mapping and Page Table
"ps -o rss,drs,trs,vsz,sz" - Process Status Options
►smem - Process Memory Usage Report
/proc/{id}/maps - Process Memory Map
/proc/{id}/smaps - Process Memory Map Details
SELinux - Security-Enhanced Linux
SSH Protocol and ssh/scp Commands
Software Package Manager on CentOS - DNF and YUM
vsftpd - Very Secure FTP Daemon