[MOAB-dev] Measuring memory

Steve Jackson sjackson at cae.wisc.edu
Wed Jul 28 14:24:26 CDT 2010


This code snippet is duplicated several times in moab:

// estimate total program memory usage and store into tot_mem
struct rusage r_usage;
getrusage(RUSAGE_SELF, &r_usage);
...
if( 0 != r_usage.ru_maxrss ){
  tot_mem = r_usage.ru_idrss;
}
else{ 
  // parse data from file /proc/self/stat
}

This code is used to estimate memory usage in mbskin and mbperf, as well as in dagmc's ray_fire_test. 

This code is broken under Linux kernel 2.6.32, because under this kernel, getrusage() does report ru_maxrss, but does not report ru_idrss.  (Previous versions of the kernel reported neither value.)  See http://www.kernel.org/doc/man-pages/online/pages/man2/getrusage.2.html .  The result is that our tools always report a memory use of 0 with this kernel version.

Should this be fixed by changing the if statement to check for data in ru_idrss instead of ru_maxrss?  Or would a different approach be preferred?  Also, ought we to move the get_time_mem function to a shared location, to reduce code duplication?
~S


More information about the moab-dev mailing list