X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/af0b220756571bc8faf57a0c7b7389dd86a60376..95f68f7b0fc4ffc700361484b6c792a8e03f3a13:/src/zmalloc.c diff --git a/src/zmalloc.c b/src/zmalloc.c index 1ebf68d1..a9ba0943 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -252,7 +252,7 @@ void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) { * function RedisEstimateRSS() that is a much faster (and less precise) * version of the funciton. */ -#if defined(HAVE_PROCFS) +#if defined(HAVE_PROC_STAT) #include #include #include @@ -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_PROC_SMAPS) +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