/mem

Primary LanguageMakefileGNU General Public License v3.0GPL-3.0

View Linux process memory usage and flags.

1. Install

./configure
make
sudo make install

2. Usage

2.1. To view process memory usage like `pmap`:
sudo mem pid

$ sudo mem 748

748: /usr/bin/containerd
4000000000-4000400000 rw-p 00000000 00:00 0  VSZ:4096KB RSS:3792KB PSS:3772KB USS:3772KB
4000400000-4000800000 rw-p 00000000 00:00 0  VSZ:4096KB RSS:4072KB PSS:4072KB USS:4072KB
4000800000-4000a00000 rw-p 00000000 00:00 0  VSZ:2048KB RSS:2028KB PSS:2028KB USS:2028KB
4000a00000-4000e00000 rw-p 00000000 00:00 0  VSZ:4096KB RSS:2384KB PSS:2384KB USS:2384KB
4000e00000-4001000000 rw-p 00000000 00:00 0  VSZ:2048KB RSS:0KB PSS:0KB USS:0KB
4001000000-4004000000 ---p 00000000 00:00 0  VSZ:49152KB RSS:0KB PSS:0KB USS:0KB
aaaab3cf0000-aaaab531b000 r-xp 00000000 08:02 1839213                    /usr/bin/containerd VSZ:22700KB RSS:18152KB PSS:18152KB USS:18152KB
aaaab532a000-aaaab61ba000 r--p 0162a000 08:02 1839213                    /usr/bin/containerd VSZ:14912KB RSS:10476KB PSS:10476KB USS:10476KB
aaaab61ba000-aaaab6246000 rw-p 024ba000 08:02 1839213                    /usr/bin/containerd VSZ:560KB RSS:512KB PSS:512KB USS:512KB
aaaab6246000-aaaab62a1000 rw-p 00000000 00:00 0  VSZ:364KB RSS:240KB PSS:156KB USS:156KB
aaaadcf52000-aaaadcf73000 rw-p 00000000 00:00 0                          [heap] VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff58000000-ffff58021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff58021000-ffff5c000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff5c000000-ffff5c021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff5c021000-ffff60000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff60000000-ffff60021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff60021000-ffff64000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff64000000-ffff64021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff64021000-ffff68000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff68000000-ffff68021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff68021000-ffff6c000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff6d3b0000-ffff6d3c0000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff6d3c0000-ffff6dbc0000 rw-p 00000000 00:00 0  VSZ:8192KB RSS:12KB PSS:12KB USS:12KB
ffff6dbc0000-ffff6dbd0000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff6dbd0000-ffff6e3d0000 rw-p 00000000 00:00 0  VSZ:8192KB RSS:12KB PSS:12KB USS:12KB
ffff6e3d0000-ffff6e7d0000 r--s 00000000 08:02 534781                     /var/lib/containerd/io.containerd.metadata.v1.bolt/meta.db VSZ:4096KB RSS:1828KB PSS:1828KB USS:1828KB
ffff6e7d0000-ffff6e7e0000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff6e7e0000-ffff6efe0000 rw-p 00000000 00:00 0  VSZ:8192KB RSS:12KB PSS:12KB USS:12KB
ffff6efe0000-ffff6eff0000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff6eff0000-ffff6f7f0000 rw-p 00000000 00:00 0  VSZ:8192KB RSS:12KB PSS:12KB USS:12KB
ffff6f7f0000-ffff6f800000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff6f800000-ffff70000000 rw-p 00000000 00:00 0  VSZ:8192KB RSS:8KB PSS:8KB USS:8KB
ffff70000000-ffff70021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff70021000-ffff74000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff74000000-ffff74021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff74021000-ffff78000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff78000000-ffff78021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff78021000-ffff7c000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff7c000000-ffff7c021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff7c021000-ffff80000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff80000000-ffff80021000 rw-p 00000000 00:00 0  VSZ:132KB RSS:4KB PSS:4KB USS:4KB
ffff80021000-ffff84000000 ---p 00000000 00:00 0  VSZ:65404KB RSS:0KB PSS:0KB USS:0KB
ffff8417f000-ffff841ff000 rw-p 00000000 00:00 0  VSZ:512KB RSS:288KB PSS:288KB USS:288KB
ffff841ff000-ffff8427f000 r--s 00000000 08:02 524454                     /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/metadata.db VSZ:512KB RSS:320KB PSS:320KB USS:320KB
ffff8427f000-ffff8449f000 rw-p 00000000 00:00 0  VSZ:2176KB RSS:1852KB PSS:1852KB USS:1852KB
ffff8449f000-ffff844af000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff844af000-ffff84caf000 rw-p 00000000 00:00 0  VSZ:8192KB RSS:8KB PSS:8KB USS:8KB
ffff84caf000-ffff84cbf000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff84cbf000-ffff854ff000 rw-p 00000000 00:00 0  VSZ:8448KB RSS:268KB PSS:268KB USS:268KB
ffff854ff000-ffff8550f000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff8550f000-ffff85d0f000 rw-p 00000000 00:00 0  VSZ:8192KB RSS:12KB PSS:12KB USS:12KB
ffff85d0f000-ffff85d1f000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff85d1f000-ffff866bf000 rw-p 00000000 00:00 0  VSZ:9856KB RSS:1116KB PSS:1116KB USS:1116KB
ffff866bf000-ffff866cf000 ---p 00000000 00:00 0  VSZ:64KB RSS:0KB PSS:0KB USS:0KB
ffff866cf000-ffff891f3000 rw-p 00000000 00:00 0  VSZ:44176KB RSS:572KB PSS:556KB USS:556KB
ffff891f3000-ffff89a70000 ---p 00000000 00:00 0  VSZ:8692KB RSS:0KB PSS:0KB USS:0KB
ffff89a70000-ffff89a71000 rw-p 00000000 00:00 0  VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffff89a71000-ffffa9a00000 ---p 00000000 00:00 0  VSZ:523836KB RSS:0KB PSS:0KB USS:0KB
ffffa9a00000-ffffa9a01000 rw-p 00000000 00:00 0  VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffffa9a01000-ffffad9f2000 ---p 00000000 00:00 0  VSZ:65476KB RSS:0KB PSS:0KB USS:0KB
ffffad9f2000-ffffad9f3000 rw-p 00000000 00:00 0  VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffffad9f3000-ffffae1f0000 ---p 00000000 00:00 0  VSZ:8180KB RSS:0KB PSS:0KB USS:0KB
ffffae1f0000-ffffae1f1000 rw-p 00000000 00:00 0  VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffffae1f1000-ffffae2f0000 ---p 00000000 00:00 0  VSZ:1020KB RSS:0KB PSS:0KB USS:0KB
ffffae2f0000-ffffae350000 rw-p 00000000 00:00 0  VSZ:384KB RSS:180KB PSS:56KB USS:56KB
ffffae350000-ffffae4d9000 r-xp 00000000 08:02 1857444                    /usr/lib/aarch64-linux-gnu/libc.so.6 VSZ:1572KB RSS:824KB PSS:13KB USS:0KB
ffffae4d9000-ffffae4e8000 ---p 00189000 08:02 1857444                    /usr/lib/aarch64-linux-gnu/libc.so.6 VSZ:60KB RSS:0KB PSS:0KB USS:0KB
ffffae4e8000-ffffae4ec000 r--p 00188000 08:02 1857444                    /usr/lib/aarch64-linux-gnu/libc.so.6 VSZ:16KB RSS:16KB PSS:16KB USS:16KB
ffffae4ec000-ffffae4ee000 rw-p 0018c000 08:02 1857444                    /usr/lib/aarch64-linux-gnu/libc.so.6 VSZ:8KB RSS:8KB PSS:8KB USS:8KB
ffffae4ee000-ffffae4fa000 rw-p 00000000 00:00 0  VSZ:48KB RSS:16KB PSS:16KB USS:16KB
ffffae500000-ffffae501000 r-xp 00000000 08:02 1857447                    /usr/lib/aarch64-linux-gnu/libdl.so.2 VSZ:4KB RSS:4KB PSS:1KB USS:0KB
ffffae501000-ffffae510000 ---p 00001000 08:02 1857447                    /usr/lib/aarch64-linux-gnu/libdl.so.2 VSZ:60KB RSS:0KB PSS:0KB USS:0KB
ffffae510000-ffffae511000 r--p 00000000 08:02 1857447                    /usr/lib/aarch64-linux-gnu/libdl.so.2 VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffffae511000-ffffae512000 rw-p 00001000 08:02 1857447                    /usr/lib/aarch64-linux-gnu/libdl.so.2 VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffffae520000-ffffae521000 r-xp 00000000 08:02 1857463                    /usr/lib/aarch64-linux-gnu/libpthread.so.0 VSZ:4KB RSS:4KB PSS:0KB USS:0KB
ffffae521000-ffffae530000 ---p 00001000 08:02 1857463                    /usr/lib/aarch64-linux-gnu/libpthread.so.0 VSZ:60KB RSS:0KB PSS:0KB USS:0KB
ffffae530000-ffffae531000 r--p 00000000 08:02 1857463                    /usr/lib/aarch64-linux-gnu/libpthread.so.0 VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffffae531000-ffffae532000 rw-p 00001000 08:02 1857463                    /usr/lib/aarch64-linux-gnu/libpthread.so.0 VSZ:4KB RSS:4KB PSS:4KB USS:4KB
ffffae537000-ffffae547000 rw-p 00000000 00:00 0  VSZ:64KB RSS:12KB PSS:12KB USS:12KB
ffffae547000-ffffae572000 r-xp 00000000 08:02 1841404                    /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1 VSZ:172KB RSS:160KB PSS:2KB USS:0KB
ffffae57a000-ffffae57e000 rw-p 00000000 00:00 0  VSZ:16KB RSS:16KB PSS:16KB USS:16KB
ffffae57e000-ffffae580000 r--p 00000000 00:00 0                          [vvar] VSZ:8KB RSS:0KB PSS:0KB USS:0KB
ffffae580000-ffffae581000 r-xp 00000000 00:00 0                          [vdso] VSZ:4KB RSS:4KB PSS:0KB USS:0KB
ffffae581000-ffffae583000 r--p 0002a000 08:02 1841404                    /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1 VSZ:8KB RSS:8KB PSS:8KB USS:8KB
ffffae583000-ffffae585000 rw-p 0002c000 08:02 1841404                    /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1 VSZ:8KB RSS:8KB PSS:8KB USS:8KB
ffffc04b6000-ffffc04d7000 rw-p 00000000 00:00 0                          [stack] VSZ:132KB RSS:12KB PSS:12KB USS:12KB
===============================================================
VSZ:1497188KB	 RSS:49324KB	 PSS:48100KB	 USS:48084KB

You can view VSZ, RSS, PSS, USS of every entry in `/proc/pid/maps`, and the total value in the last line.

2.2. To view memory flags:
sudo mem -a start_addr-end_addr pid

$ sudo mem -a ffffae4ec000-ffffae4ee000 748

748: /usr/bin/containerd
virtual addr: 0xffffae4ec000, physical addr: 0x115cf7000, flags: UPTODATE LRU MMAP ANON SWAPBACKED
virtual addr: 0xffffae4ed000, physical addr: 0x115cf1000, flags: UPTODATE LRU MMAP ANON SWAPBACKED