summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-11-19 12:02:08 +0100
committerantirez <antirez@gmail.com>2012-11-20 12:32:19 +0100
commit5ab4151d7f771ae6e97edc4c27e55c368228315e (patch)
treeb2c4d52ebaf0a5cd715380aad7af260a1c4af312
parente95ca66320a97d4a7415ce5dda942130d6338f85 (diff)
downloadredis-5ab4151d7f771ae6e97edc4c27e55c368228315e.tar.gz
Children creating AOF or RDB files now report memory used by COW.
Finally Redis is able to report the amount of memory used by copy-on-write while saving an RDB or writing an AOF file in background. Note that this information is currently only logged (at NOTICE level) and not shown in INFO because this is less trivial (but surely doable with some minor form of interprocess communication). The reason we can't capture this information on the parent before we call wait3() is that the Linux kernel will release the child memory ASAP, and only retain the minimal state for the process that is useful to report the child termination to the parent. The COW size is obtained by summing all the Private_Dirty fields found in the "smap" file inside the proc filesystem for the process. All this is Linux specific and is not available on other systems.
-rw-r--r--src/aof.c7
-rw-r--r--src/rdb.c9
2 files changed, 16 insertions, 0 deletions
diff --git a/src/aof.c b/src/aof.c
index bc92cdb98..6289e4dd5 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -962,6 +962,13 @@ int rewriteAppendOnlyFileBackground(void) {
if (server.sofd > 0) close(server.sofd);
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
if (rewriteAppendOnlyFile(tmpfile) == REDIS_OK) {
+ size_t private_dirty = zmalloc_get_private_dirty();
+
+ if (private_dirty) {
+ redisLog(REDIS_NOTICE,
+ "AOF rewrite: %lu MB of memory used by copy-on-write",
+ private_dirty/(1024*1024));
+ }
exitFromChild(0);
} else {
exitFromChild(1);
diff --git a/src/rdb.c b/src/rdb.c
index a57b72e43..3d5ac2043 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -731,6 +731,15 @@ int rdbSaveBackground(char *filename) {
if (server.ipfd > 0) close(server.ipfd);
if (server.sofd > 0) close(server.sofd);
retval = rdbSave(filename);
+ if (retval == REDIS_OK) {
+ size_t private_dirty = zmalloc_get_private_dirty();
+
+ if (private_dirty) {
+ redisLog(REDIS_NOTICE,
+ "RDB: %lu MB of memory used by copy-on-write",
+ private_dirty/(1024*1024));
+ }
+ }
exitFromChild((retval == REDIS_OK) ? 0 : 1);
} else {
/* Parent */