diff options
author | antirez <antirez@gmail.com> | 2012-11-19 11:24:56 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2012-11-19 15:25:57 +0100 |
commit | 1d8af6074caa0c397dce01d4309afefdfa30606e (patch) | |
tree | c301f2d80ab4e8084269efafad3c20b5b34ff39d /src/zmalloc.c | |
parent | 1a706c729a5c27ae7a554ee4995f6c161d24a05b (diff) | |
download | redis-1d8af6074caa0c397dce01d4309afefdfa30606e.tar.gz |
zmalloc_get_private_dirty() function added (Linux only).
For non Linux systmes it just returns 0.
This function is useful to estimate copy-on-write because of childs
saving stuff on disk.
Diffstat (limited to 'src/zmalloc.c')
-rw-r--r-- | src/zmalloc.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/zmalloc.c b/src/zmalloc.c index 1ebf68d17..1f8c7f08e 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -324,3 +324,28 @@ size_t zmalloc_get_rss(void) { 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 |