memstat: Identify what is using up virtual memory
October 19th, 2008 edited by VichoArticle submitted by Todd Troxell. Guess what? We still need you to submit good articles about software you like!
This tool lets you discover what libraries and programs are using up memory. It is very simple to use. Here is an example of its output (the -w makes memstat not truncate lines at 80 columns):
gaius% memstat -w 256k: PID 5465 (/lib/ld-2.3.6.so) 368k: PID 13019 (/var/db/nscd/passwd) 3352k: PID 13914 (/usr/lib/gconv/gconv-modules.cache) 8k: /usr/bin/memstat 5465 12k: /lib/libcap.so.1.10 13019 256k: /lib/libncurses.so.5.5 13914 88k: /lib/ld-2.3.6.so 5465 13019 256k: /lib/libncurses.so.5.5 13019 1212k: /lib/tls/libc-2.3.6.so 13914 32k: /lib/tls/libnss_compat-2.3.6.so 13914 24k: /lib/tls/libcrypt-2.3.6.so 13914 12k: /lib/tls/libdl-2.3.6.so 13914 144k: /lib/tls/libm-2.3.6.so 13914 76k: /lib/tls/libnsl-2.3.6.so 13914 40k: /lib/tls/libnss_files-2.3.6.so 13914 36k: /lib/tls/libnss_nis-2.3.6.so 13914 60k: /lib/tls/libpthread-2.3.6.so 13914 28k: /lib/tls/librt-2.3.6.so 13914 88k: /lib/ld-2.3.6.so 13914 1212k: /lib/tls/libc-2.3.6.so 5465 13019 12k: /lib/tls/libdl-2.3.6.so 13019 144k: /lib/tls/libm-2.3.6.so 13019 76k: /lib/tls/libnsl-2.3.6.so 13019 480k: /bin/zsh-beta 13019 212k: /var/db/nscd/passwd 13019 788k: /usr/bin/irssi 13914 148k: /usr/lib/libpcre.so.3.12.0 13019 176k: /usr/lib/perl5/auto/Irssi/Irssi.so 13914 80k: /usr/lib/perl5/auto/Irssi/Irc/Irc.so 13914 80k: /usr/lib/perl5/auto/Irssi/UI/UI.so 13914 12k: /usr/lib/gconv/CP1252.so 13914 24k: /usr/lib/gconv/gconv-modules.cache 13914 76k: /usr/lib/libz.so.1.2.3 13914 584k: /usr/lib/libglib-2.0.so.0.1200.4 13914 1128k: /usr/lib/libperl.so.5.8.8 13914 12k: /usr/lib/libgmodule-2.0.so.0.1200.4 13914 1240k: /usr/lib/i686/cmov/libcrypto.so.0.9.8 13914 248k: /usr/lib/i686/cmov/libssl.so.0.9.8 13914 8k: /usr/lib/zsh-beta/4.3.2-dev-1/zsh/terminfo.so 13019 24k: /usr/lib/zsh-beta/4.3.2-dev-1/zsh/zutil.so 13019 56k: /usr/lib/zsh-beta/4.3.2-dev-1/zsh/compctl.so 13019 116k: /usr/lib/zsh-beta/4.3.2-dev-1/zsh/complete.so 13019 196k: /usr/lib/zsh-beta/4.3.2-dev-1/zsh/zle.so 13019 -------- 13480k
This output lists many libraries and processes loaded into memory and their sizes. First of all, processes and the size of their private memory are listed. This does not include their shared memory. Afterwards, shared objects are listed, and finally the total is listed.
In case you are wondering, shared object are libraries like /lib/tls/libc-2.3.6.so
that are shared across all processes that need them to save memory and make things run faster. Instead of loading this library into memory for every process, Linux loads one copy and uses this for any process that wants to use the library. Therefore, you may notice that these values sometimes do not add up to the amount of memory you see used on your system. If you look at ps(1) you will see two columns related to memory: RSS and VSZ. For each process, RSS is the amount of memory used by the process, and VSZ is the amount used counting shared objects. To add up memory correctly, you must count each shared object only once for the system.
It is possible to output per user statistics by running memstat as an unprivileged user. When run as root, memstat will list everything on the system.
Memstat works by scanning files in /proc
and then searching for binaries in the paths listed at /etc/memstat.conf
. The default file should be sufficient for most cases. If you have libraries or binaries in a non-standard place, you may need to modify this file to get accurate results.
Memstat was authored by Joshua Yelon. It is available in all current Debian and Ubuntu releases.
Posted in Debian, Ubuntu | 9 Comments »