s3-messages: add mallinfo() information to pool-usage report
authorRalph Wuerthner <ralph.wuerthner@de.ibm.com>
Fri, 29 Mar 2019 11:44:50 +0000 (12:44 +0100)
committerChristof Schmitt <cs@samba.org>
Thu, 4 Apr 2019 23:39:25 +0000 (23:39 +0000)
Signed-off-by: Ralph Wuerthner <ralph.wuerthner@de.ibm.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
Autobuild-User(master): Christof Schmitt <cs@samba.org>
Autobuild-Date(master): Thu Apr  4 23:39:25 UTC 2019 on sn-devel-144

source3/lib/tallocmsg.c
source3/wscript

index b5ab21c..9be1bf5 100644 (file)
 #include "includes.h"
 #include "messages.h"
 #include "lib/util/talloc_report.h"
+#ifdef HAVE_MALLINFO
+#include <malloc.h>
+#endif /* HAVE_MALLINFO */
 
+ /**
+ * Prepare memory allocation report based on mallinfo()
+ **/
+static char *get_mallinfo_report(void *mem_ctx)
+{
+       char *report = NULL;
+#ifdef HAVE_MALLINFO
+       struct mallinfo mi;
+
+       mi = mallinfo();
+       report = talloc_asprintf(mem_ctx,
+                                "mallinfo:\n"
+                                "    arena: %d\n"
+                                "    ordblks: %d\n"
+                                "    smblks: %d\n"
+                                "    hblks: %d\n"
+                                "    hblkhd: %d\n"
+                                "    usmblks: %d\n"
+                                "    fsmblks: %d\n"
+                                "    uordblks: %d\n"
+                                "    fordblks: %d\n"
+                                "    keepcost: %d\n",
+                                mi.arena,
+                                mi.ordblks,
+                                mi.smblks,
+                                mi.hblks,
+                                mi.hblkhd,
+                                mi.usmblks,
+                                mi.fsmblks,
+                                mi.uordblks,
+                                mi.fordblks,
+                                mi.keepcost);
+#endif /* HAVE_MALLINFO */
+
+       return report;
+}
 /**
  * Respond to a POOL_USAGE message by sending back string form of memory
  * usage stats.
@@ -31,8 +70,9 @@ static void msg_pool_usage(struct messaging_context *msg_ctx,
                           DATA_BLOB *data)
 {
        char *report = NULL;
+       char *mreport = NULL;
        int iov_size = 0;
-       struct iovec iov[1];
+       struct iovec iov[2];
 
        SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE);
 
@@ -45,6 +85,13 @@ static void msg_pool_usage(struct messaging_context *msg_ctx,
                iov_size++;
        }
 
+       mreport = get_mallinfo_report(msg_ctx);
+       if (mreport != NULL) {
+               iov[iov_size].iov_base = mreport;
+               iov[iov_size].iov_len = talloc_get_size(mreport) - 1;
+               iov_size++;
+       }
+
        if (iov_size) {
                messaging_send_iov(msg_ctx,
                                   src,
@@ -56,6 +103,7 @@ static void msg_pool_usage(struct messaging_context *msg_ctx,
        }
 
        TALLOC_FREE(report);
+       TALLOC_FREE(mreport);
 }
 
 /**
index c93b605..97b51bb 100644 (file)
@@ -1517,6 +1517,18 @@ main() {
                     define='HAVE_UNSHARE_CLONE_FS',
                     msg='for Linux unshare(CLONE_FS)')
 
+    # Check for mallinfo
+    conf.CHECK_CODE('''
+    struct mallinfo mi;
+    int tmp;
+
+    mi = mallinfo();
+    tmp = mi.arena + mi.ordblks + mi.smblks + mi.hblks +
+          mi.hblkhd + mi.usmblks + mi.fsmblks +  mi.uordblks +
+          mi.fordblks + mi.keepcost;
+    return tmp;
+    ''', 'HAVE_MALLINFO', msg="Checking for mallinfo()", headers='malloc.h')
+
     #
     # cluster support (CTDB)
     #