[Asterisk-code-review] core: Merge malloc trim patch (asterisk[certified/13.21])

Jenkins2 asteriskteam at digium.com
Thu Dec 6 05:53:41 CST 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/10737 )

Change subject: core: Merge malloc_trim patch
......................................................................

core: Merge malloc_trim patch

We've had multiple opportunities where Richard Mudgett's
malloc_trim patch has been useful. Let's get it
pushed up to gerrit and merged.

Since malloc_trim is only available in libc, an entry is
added to configure.ac to create a definition for
HAVE_MALLOC_TRIM.

Change-Id: Ia38308c550149d9d6eae4ca414a649957de9700c
(cherry picked from commit 40ab571e0d07f7e1854c0f924b0fbda2da36c5a5)
---
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M main/cli.c
4 files changed, 38 insertions(+), 2 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/configure b/configure
index 732f6ca..c4920e9 100755
--- a/configure
+++ b/configure
@@ -16750,7 +16750,7 @@
 done
 
 
-for ac_func in asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl
+for ac_func in asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/configure.ac b/configure.ac
index 46f62b8..11b8dc9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -761,7 +761,7 @@
 AC_FUNC_STRTOD
 AC_FUNC_UTIME_NULL
 AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl])
+AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim])
 
 AC_MSG_CHECKING(for htonll)
 AC_LINK_IFELSE(
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 0fa2859..22daea0 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -462,6 +462,9 @@
 /* Define to 1 if you have the <malloc.h> header file. */
 #undef HAVE_MALLOC_H
 
+/* Define to 1 if you have the `malloc_trim' function. */
+#undef HAVE_MALLOC_TRIM
+
 /* Define to 1 if you have the `memchr' function. */
 #undef HAVE_MEMCHR
 
diff --git a/main/cli.c b/main/cli.c
index dc75acb..f980fc6 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1791,6 +1791,34 @@
 	return CLI_SUCCESS;
 }
 
+
+#ifdef HAVE_MALLOC_TRIM
+	/* BUGBUG malloc_trim() is a libc specific function.  Non-portable. */
+	static char *handle_cli_malloc_trim(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+	{
+		extern int malloc_trim(size_t __pad) __THROW;
+
+		switch (cmd) {
+		case CLI_INIT:
+			e->command = "malloc trim";
+			e->usage =
+				"Usage: malloc trim\n"
+				"       Try to give excess memory back to the OS.\n";
+			return NULL;
+		case CLI_GENERATE:
+			return NULL;
+		}
+
+		if (malloc_trim(0)) {
+			ast_cli(a->fd, "Returned some memory to the OS.\n");
+		} else {
+			ast_cli(a->fd, "No memory returned to the OS.\n");
+		}
+
+		return CLI_SUCCESS;
+	}
+#endif
+
 static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 
 static struct ast_cli_entry cli_cli[] = {
@@ -1837,6 +1865,11 @@
 	AST_CLI_DEFINE(handle_cli_check_permissions, "Try a permissions config for a user"),
 
 	AST_CLI_DEFINE(handle_cli_wait_fullybooted, "Wait for Asterisk to be fully booted"),
+
+#ifdef HAVE_MALLOC_TRIM
+	AST_CLI_DEFINE(handle_cli_malloc_trim, "Return excess memory to the OS"),
+#endif
+
 };
 
 /*!

-- 
To view, visit https://gerrit.asterisk.org/10737
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: certified/13.21
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia38308c550149d9d6eae4ca414a649957de9700c
Gerrit-Change-Number: 10737
Gerrit-PatchSet: 1
Gerrit-Owner: Chris Savinovich <csavinovich at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181206/2774b535/attachment.html>


More information about the asterisk-code-review mailing list