Jul 13 2011
Firing up top or free on a Linux system and attempting to discern memory usage statistics can be a daunting task for the uninitiated. While the task of explaining “free” vs “used” memory has been done in many places, I wanted to take some time to talk about a little-known tool called Exmap which gives you a much deeper insight into the memory usage of your processes.
I have a netbook with a limited amount of ram and an SSD for a backing store. Since this particular SSD has poor write performance and I don’t want to wear it out with excessive writes, I’ve set the VM swappiness to zero. This means I truly am constrained by the physical memory of the system as I can’t rely on swap to mitigate app bloat. A similar situation arises with some VPS providers which simply disable swap altogether — the 256 megs you get is it. In these kinds of situations, knowing precisely which applications are hogging ram is crucial.
Of course, the copy-on-write nature of the VM subsystem complicates this calculation. While one-off applications are easy to spot in top or ps listings, complex GUI applications load so many common libraries that it’s tough to tell how much memory would truly be saved by killing off an application. This is where Exmap shines.
Exmap scans pages assigned to each running binary and identifies how much ram each process individually consumes, taking into account shared libraries. For example, it turns out Pidgin is an offender by loading many shared objects unique to itself (part of this is its plugin system). Exmap is, as far as I can tell, the only tool which gives you this level of granularity in tracing down application memory usage.
To operate, Exmap needs intimate access to your application’s memory — this means a compiled kernel extension. Unfortunately, the source located on the project’s homepage does not compile directly on modern systems (Debian Squeeze at the time of this writing) and some modifications were needed. The author has a fork on GitHub but this too suffers from some minor compilation warts. The version I have in my repository seems to compile, load, and run OK. The easiest way to get it is by running this:
git clone git://github.com/wickedchicken/exmap.git
and following instructions in the README.
show/hide comment box