MeasuringMemoryUsage

This project is no longer maintained. You might be interested in Ubuntu Touch though.

Please help to improve this page if you have more tools or ideas to add.

Nexus7 Memory Measurement

Measuring application memory consumption in Linux has been a black art for a long time. This is because there are many different ways to think about memory usage and many different memory types. For instance the binary code of shared libraries is loaded in memory once and shared between all processes using it: how do you count the memory used by multiple programs using the same shared library?

Identifying Issues

htop is an advanced version of top which is good way to start browsing your processes by memory usage, filtering them down etc.

smem is a small python script which walks over /proc/*/smaps files to figure out how much memory each process uses, and how much memory is used by shared libraries overall. It provides an useful "PSS" metric which will count memory used by shared libraries in proportion to the number of times a shared library is loaded. For instance if 3 processes use a 30K shared library, each will get 10K accounted for in its PSS.

To use smem:

  • sudo apt-get --no-install-recommends install smem
  • sudo smem -c "name command uss pss rss vss" -s pss -k -r
  • look at the PSS memory column

The above smem command will sort processes by PSS (-s pss) as it's a good system-wide memory metric, with friendly units (-k), and reversed (-r) as to show the top consumers first.

http://people.canonical.com/~lool/smem-tabs is a patched smem script which will:

  • avoid shortening command lines and program names
  • separate columns with tabs as to make it easier to import into a spreadsheet

Once you have identified a program that is consuming a lot of memory, you may research where it's using memory.

To inspect an individual process' memory, use the pmap tool as root. Read-only pages might be shared by the kernel while writable pages are definetly *not* shared.

If you suspect a memory leak, you may want to use Valgrind to debug it.

Resources

Nexus7/MeasuringMemoryUsage (last edited 2013-01-31 20:15:32 by brian-murray)