whitenoise

technology notes… mobile and embedded.

Archive for the ‘hands on’ Category

Memory consumption of your program.A quick and dirty way.

leave a comment »

Happy New Year too all ! Hope the New Year turns out a good one for all of us.

This year,  I would like to write more ‘code’ and blog more about hands on programing tips and topics. With this in mind,  here is the first hands on tip I thought of putting as my first post for the year.

One of the metrics that is measured  in Desktop and Embedded Linux programs  would be its ‘startup time’  and memory (RAM) usage . Owing to its virtual memory , there is no ‘static ‘ way to estimate  RAM usage of a program.

Here is a quick & dirty way to identify the memory consumption your Linux program. This relies on the page-faults that occur as soon as the program is started .

———————
A  gross estimate on the total page faults that happen over an interval by cat’ing /proc/vmstat and look at the page-in count (pgpgin).

As long as your program is the main thing running, and the only work that’s starting up between two checks of that value, the vast majority of those page faults will have been for you.
It’s also useful to look at that value when the device seems to be running sluggishly — when I’ve done that, the page fault count is rising very rapidly, indicating thrashing due to too much memory in use, and too little left for a usable page/file cache.

eg: Before starting your app:
# cat /proc/vmstat
nr_dirty 0
nr_writeback 0
nr_unstable 0
nr_page_table_pages 677
nr_mapped 8151
nr_slab 1231
pgpgin 166187
pgpgout 33
pswpin 0
pswpout 0


After starting app and allowing the initial UI to come up, run the command again:
# cat /proc/vmstat
nr_dirty 0
nr_writeback 0
nr_unstable 0
nr_page_table_pages 711
nr_mapped 8012
nr_slab 1139
pgpgin 172090
pgpgout 33
pswpin 0
pswpout 0

The difference in pdpgin gives an estimate on the memory usage by your application on startup.

So what does these esoteric names mean .Here is a reference on what these terms mean.

pgpgin      –  Number of kilobytes the system has paged in from disk per second.
pgpgout     –  Number of kilobytes the system has paged out to disk per second.
pswpin      –  Number of kilobytes the system has swapped in from disk per second.
pswpout     –  Number of kilobytes the system has swapped out to disk per second.

The following statistics are only available by kernels from 2.6.
pgfault     –  Number of page faults the system has made per second (minor + major).
pgmajfault  –  Number of major faults per second the system required loading a memory page from disk.

Written by sujai

January 6, 2009 at 10:41 am

%d bloggers like this: