Skip to content

Instantly share code, notes, and snippets.

@dspezia
Created September 25, 2011 09:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dspezia/1240427 to your computer and use it in GitHub Desktop.
Save dspezia/1240427 to your computer and use it in GitHub Desktop.
Instrumenting Redis to evaluate the efficiency of COW
/*
This function makes use of /proc to evaluate the ratio between shared and private memory blocks.
It is expressed as a percentage: 90 means 90% of the blocks are shared, and 10% have been duplicated.
Call this function at the very end of the child process.
For Redis, it is supposed to be called at the end of rdbSave (file rdb.c)
Ugly but effective.
Please note it does not work if huge pages are used
*/
void rdbDisplayCOW() {
char smaps[256];
char tmp[256];
sprintf( smaps, "awk '/^Shared_Dirty:/ { x += $2 } /^Rss:/ { y += $2 } END { printf \"%%.3f\\n\", x/y*100 }' < /proc/%d/smaps", getpid() );
FILE *f = popen( smaps, "r" );
if ( !f )
return;
if ( fscanf( f, "%s", tmp ) != 1 ) {
pclose( f );
return;
}
pclose( f );
redisLog(REDIS_NOTICE,"Background saving COW ratio: %s",tmp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment