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.
  • cgmemtime seem use wait4 under hood, isn't viable query process while it's running.
  • tstime reports 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().

patch rfc


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -