[PATCH] add mallinfo() information to pool-usage report
Jeremy Allison
jra at samba.org
Thu Apr 4 19:21:40 UTC 2019
On Thu, Apr 04, 2019 at 11:00:34AM +0200, Ralph Wuerthner via samba-technical wrote:
> Hi!
>
> Please see attached patch set to enhance the pool-usage report from
> smbcontrol with information available from mallinfo(). In addition to the
> talloc report we found the mallinfo() data quite handy to investigate a
> potential memory leak in Samba. To my knowledge mallinfo() is available on
> Linux, BSD, and AIX.
> The CI pipeline is running at
> https://gitlab.com/samba-team/devel/samba/pipelines/55161485
LGTM. RB+.
Can I get a second Team reviewer ?
Jeremy.
> From d221912134f4750bdee23d1dfbe2531e03c31d6d Mon Sep 17 00:00:00 2001
> From: Ralph Wuerthner <ralph.wuerthner at de.ibm.com>
> Date: Fri, 29 Mar 2019 12:30:45 +0100
> Subject: [PATCH 1/2] s3-messages: modify msg_pool_usage() to allow enhanced
> memory reports
>
> Signed-off-by: Ralph Wuerthner <ralph.wuerthner at de.ibm.com>
> ---
> source3/lib/tallocmsg.c | 23 +++++++++++++++++------
> 1 file changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/source3/lib/tallocmsg.c b/source3/lib/tallocmsg.c
> index 18b16ed..b5ab21c 100644
> --- a/source3/lib/tallocmsg.c
> +++ b/source3/lib/tallocmsg.c
> @@ -30,21 +30,32 @@ static void msg_pool_usage(struct messaging_context *msg_ctx,
> struct server_id src,
> DATA_BLOB *data)
> {
> - char *report;
> + char *report = NULL;
> + int iov_size = 0;
> + struct iovec iov[1];
>
> SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE);
>
> DEBUG(2,("Got POOL_USAGE\n"));
>
> report = talloc_report_str(msg_ctx, NULL);
> -
> if (report != NULL) {
> - messaging_send_buf(msg_ctx, src, MSG_POOL_USAGE,
> - (uint8_t *)report,
> - talloc_get_size(report)-1);
> + iov[iov_size].iov_base = report;
> + iov[iov_size].iov_len = talloc_get_size(report) - 1;
> + iov_size++;
> + }
> +
> + if (iov_size) {
> + messaging_send_iov(msg_ctx,
> + src,
> + MSG_POOL_USAGE,
> + iov,
> + iov_size,
> + NULL,
> + 0);
> }
>
> - talloc_free(report);
> + TALLOC_FREE(report);
> }
>
> /**
> --
> 2.7.4
>
>
> From 7a192974651567ec16b60a5c0fd22ac83da6c2d8 Mon Sep 17 00:00:00 2001
> From: Ralph Wuerthner <ralph.wuerthner at de.ibm.com>
> Date: Fri, 29 Mar 2019 12:44:50 +0100
> Subject: [PATCH 2/2] s3-messages: add mallinfo() information to pool-usage
> report
>
> Signed-off-by: Ralph Wuerthner <ralph.wuerthner at de.ibm.com>
> ---
> source3/lib/tallocmsg.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
> source3/wscript | 12 ++++++++++++
> 2 files changed, 61 insertions(+), 1 deletion(-)
>
> diff --git a/source3/lib/tallocmsg.c b/source3/lib/tallocmsg.c
> index b5ab21c..9be1bf5 100644
> --- a/source3/lib/tallocmsg.c
> +++ b/source3/lib/tallocmsg.c
> @@ -19,7 +19,46 @@
> #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);
> }
>
> /**
> diff --git a/source3/wscript b/source3/wscript
> index c93b605..97b51bb 100644
> --- a/source3/wscript
> +++ b/source3/wscript
> @@ -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)
> #
> --
> 2.7.4
>
More information about the samba-technical
mailing list