linux - Get memory high water mark for a time interval -
i'm trying max amount of memory used during brief intervals, long-running linux process. example, like:
resetmaxrss(); // hypothetical new command void* foo = malloc(4096); free(foo); getrusage(...); // 'ru_maxrss' reports 4096 plus whatever else alive resetmaxrss(); void* bar = malloc(2048); free(bar); getrusage(...); // 'ru_maxrss' reports 2048 + whatever, *not* 4096 options i've found , ruled out:
getrusage's max rss can't reset.cgmemtimeseem usewait4under hood, isn't viable query process while it's running.tstimereports exiting processes, not viable query process while it's running.
other options, none of good:
- polling. prone miss our brief allocations.
- instrumenting our code. don't have access of memory allocators being used, wouldn't elegant or straightforward. i'd rather use values reported os accuracy.
is there way this, short of proposing patch linux kernel?
it turns out since linux 4.0, peak rss can reset:
/proc/[pid]/clear_refs (since linux 2.6.22) write-only file, writable owner of process. following values may written file: [snip] 5 (since linux 4.0) reset peak resident set size ("high water mark") process's current resident set size value. that hwm/peak rss can read out /proc/[pid]/status -> vmhwm or getrusage().
Comments
Post a Comment