Created
September 25, 2011 09:42
-
-
Save dspezia/1240427 to your computer and use it in GitHub Desktop.
Instrumenting Redis to evaluate the efficiency of COW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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