Well Situated, Friendly Neighborhood

Ben has some good news for anyone interested in reducing the memory usage of Linux programs. Smaps is great. But does it tell the whole truth?

For PCs with (basically) limitless swap space, it’s possible that it doesn’t even come close. The reason: Under memory pressure, only memory pages that are actually being accessed will be kept in main memory. These pages are usually 4kB each. So how much of a hog your process will be is determined by its access pattern. Which brings us to our dear old friend, Locality. It’s easy enough to deduce that a process with many tiny, frequently accessed memory blocks sprinkled in between “low urgency” blocks over a lot of pages will be a disaster compared to a process with frequently-accessed data allocated close together.

So, it’s possible that an even better measure of a process’ memory badness would be a running count of “number of different pages accessed in the last 10 seconds”, possibly with a falloff function (think load average). Maybe this could be done with a Valgrind tool, a la Cachegrind but for VM pages instead of CPU cache lines? Maybe it could even tell you where the N most frequently accessed memory blocks were allocated, and for each block, provide a list of locations where it was accessed (sorted by time last accessed or by frequency).

That sounds like a fun project!

Leave a Reply

Your email address will not be published. Required fields are marked *