1. mirror
  2. redis

Commits

bitbucket  committed fa7b11e Merge

Merge branch 'unstable' of https://github.com/antirez/redis into unstable

  • Participants
  • Parent commits 751fcd3, 49b6452
  • Branches unstable

Comments (0)

Files changed (4)

File src/aof.c

View file
         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);

File src/rdb.c

View file
         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 */

File src/zmalloc.c

View file
 float zmalloc_get_fragmentation_ratio(void) {
     return (float)zmalloc_get_rss()/zmalloc_used_memory();
 }
+
+#if defined(HAVE_PROCFS)
+size_t zmalloc_get_private_dirty(void) {
+    char line[1024];
+    size_t pd = 0;
+    FILE *fp = fopen("/proc/self/smaps","r");
+
+    if (!fp) return 0;
+    while(fgets(line,sizeof(line),fp) != NULL) {
+        if (strncmp(line,"Private_Dirty:",14) == 0) {
+            char *p = strchr(line,'k');
+            if (p) {
+                *p = '\0';
+                pd += strtol(line+14,NULL,10) * 1024;
+            }
+        }
+    }
+    fclose(fp);
+    return pd;
+}
+#else
+size_t zmalloc_get_private_dirty(void) {
+    return 0;
+}
+#endif

File src/zmalloc.h

View file
 void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
 float zmalloc_get_fragmentation_ratio(void);
 size_t zmalloc_get_rss(void);
+size_t zmalloc_get_private_dirty(void);
 void zlibc_free(void *ptr);
 
 #ifndef HAVE_MALLOC_SIZE