K.Mandla's blog of Linux experiences

Looking close at memory usage

Working with 16Mb of physical memory has underscored the importance of two things: first, lightweight applications, and second, keeping a close eye on what is taking up space.

System monitors such as htop are useful for the second point, although using a monitor to watch memory use defeats the purpose to a small degree; it does, after all, take up space. For a shorter, quicker peek, this little script does a great job. Here’s what the output looks like:

I find that interesting mostly because it helps answer a long-standing question, of how it all fits. But it also puts a few things into perspective, like the fact that Musca takes up less space than tty-clock, or that htop and alpine are standing on the same amount of ground, more or less.

On a bigger system the results might be a little more intersting. And now I can take a more critical approach to lightweight versus heavyweight software, with some numbers to back myself up. :twisted:

Post navigation

25 thoughts on “Looking close at memory usage”

This was exactly what I was looking for, too. It makes analyzing memory usage much simpler and lighter. I mean, who doesn’t like a program that gives results by just printing plain text? :)

The other day, I was experimenting to see what was my minimal memory usage on my thinkpad x200s laptop. And, as you can see in the picture linked below, memory usage of htop itself was limiting the accuracy:

[BTW I’m thinking the main reasons for it being still too large (at least in K.Mandla standards) are the large framebuffer resolution and a great variety of loaded kernel modules.]

Instead of a single snapshot, shouldn’t you be taking a series of samples over a prolonged period of time — similar to the way a profiler gathers statistics on what parts of a program use the most CPU time?

A program’s memory usage is usually not constant, and your single snapshot is very likely to have missed its peaks. But you need to know about those peaks if you’re trying to evaluate the load a given mix of applications puts on the system.

If I were you, btw, I’d ditch that tty clock, and replace bash with something lighter-weight.

Not sure. Seems like the numbers should more or less correspond, but free -m and this script might calculate things differently. If you check back against the description of the script and maybe the man pages for free, it might give you an idea.

On my machine, the numbers correspond roughly to what htop reports. I don’t often rely on free -m, mostly because I always found the output to be somewhat scattered.

Nice script indeed!
I do encounter a problem however.. When comparing the python script to the values given by gnome-system-monitor, the results I get are off by about 60 Mb, with gnome-system-monitor giving me a higher memory usage in the order of 20%. This is huge! Would anybody know where this is coming from?
Kind regards.