Getting an accurate view of process memory usage on Linux hosts


Having debugged a number of memory-related issues on Linux, one thing I’ve always wanted was a tool to display proportional memory usage. Specifically, I wanted to be able to see how much memory was unique to a process, and have an equal portion of shared memory (libraries, SMS, etc.) added to this value. My wish came true a while back when I discovered the smem utility. When run without any arguments, smem will give you the resident set size (RSS), the unique set size (USS) and the proportional set size (PSS) which is the unique set size plus a portion of the shared memory that is being used by this process. This results in output similar to the following:

$ smem -r

PID User Command Swap USS PSS RSS
3636 root /usr/lib/virtualbox/Virtual 0 1151596 1153670 1165568
3678 matty /usr/lib64/firefox-3.5.9/fi 0 189628 191483 203028
5779 root /usr/bin/python /usr/bin/sm 0 38584 39114 40368
1847 root /usr/bin/Xorg :0 -nr -verbo 0 34024 35874 92504
4103 matty pidgin 0 19364 21072 32412
3825 matty gnome-terminal 0 12388 13242 21992
3404 matty python /usr/share/system-co 0 11596 12622 19216
3710 matty gnome-screensaver 0 9872 10287 14640
3283 matty nautilus 0 7104 8373 18484
3263 matty gnome-panel 0 5828 6731 15780

To calculate the portion of shared memory that is being used by each process, you can add up the shared memory per process (you would probably index this by the type of shared resource), the number of processes using these pages, and then divide the two values to get a proportional value of shared memory per process. This is a very cool utility, and one that gets installed on all of my systems now!

This article was posted by Matty on 2010-07-02 08:06:00 -0400 -0400