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