17b94a
From 55d47524c0c8a88204129c3a94d71779aae00beb Mon Sep 17 00:00:00 2001
17b94a
From: Mohit Agrawal <moagrawa@redhat.com>
17b94a
Date: Tue, 28 May 2019 08:18:12 +0530
17b94a
Subject: [PATCH 145/169] core: Capture process memory usage at the time of
17b94a
 call gf_msg_nomem
17b94a
17b94a
Problem: All gluster processes call gf_mgm_nomem while calloc/malloc/realloc
17b94a
         throw an error but the message does not capture current memory usage of
17b94a
         gluster process
17b94a
17b94a
Solution: Call getrusage to capture current memory usage of gluster
17b94a
          process
17b94a
17b94a
> Change-Id: I2e0319da1f33b177fa042fdc9e7268068576c9c3
17b94a
> fixes: bz#1708051
17b94a
> Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22688/
17b94a
> Cherry pick from commit 8e1d53f14730ac1b1ca0ce9d9a0ccb32578fd4fb
17b94a
17b94a
BUG: 1709087
17b94a
Change-Id: I2e0319da1f33b177fa042fdc9e7268068576c9c3
17b94a
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/171587
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
17b94a
---
17b94a
 libglusterfs/src/logging.c | 7 +++++--
17b94a
 1 file changed, 5 insertions(+), 2 deletions(-)
17b94a
17b94a
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
17b94a
index 5d46916..7f0eff6 100644
17b94a
--- a/libglusterfs/src/logging.c
17b94a
+++ b/libglusterfs/src/logging.c
17b94a
@@ -17,6 +17,7 @@
17b94a
 #include <string.h>
17b94a
 #include <stdlib.h>
17b94a
 #include <syslog.h>
17b94a
+#include <sys/resource.h>
17b94a
 
17b94a
 #ifdef HAVE_BACKTRACE
17b94a
 #include <execinfo.h>
17b94a
@@ -1196,6 +1197,7 @@ _gf_msg_nomem(const char *domain, const char *file, const char *function,
17b94a
     glusterfs_ctx_t *ctx = NULL;
17b94a
     int wlen = 0;
17b94a
     int priority;
17b94a
+    struct rusage r_usage;
17b94a
 
17b94a
     this = THIS;
17b94a
     ctx = this->ctx;
17b94a
@@ -1231,10 +1233,11 @@ _gf_msg_nomem(const char *domain, const char *file, const char *function,
17b94a
                    "]"
17b94a
                    " [%s:%d:%s] %s: no memory "
17b94a
                    "available for size (%" GF_PRI_SIZET
17b94a
-                   ")"
17b94a
+                   ") current memory usage in kilobytes %ld"
17b94a
                    " [call stack follows]\n",
17b94a
                    timestr, gf_level_strings[level], (uint64_t)0, basename,
17b94a
-                   line, function, domain, size);
17b94a
+                   line, function, domain, size,
17b94a
+                   (!getrusage(RUSAGE_SELF, &r_usage) ? r_usage.ru_maxrss : 0));
17b94a
     if (-1 == ret) {
17b94a
         goto out;
17b94a
     }
17b94a
-- 
17b94a
1.8.3.1
17b94a