<p>Chris Savinovich has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10730">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Merge malloc_trim patch<br><br>We've had multiple opportunities where Richard Mudgett's<br>malloc_trim patch has been useful. Let's get it<br>pushed up to gerrit and merged.<br><br>Since malloc_trim is only available in libc, an entry is<br>added to configure.ac to create a definition for<br>HAVE_MALLOC_TRIM.<br><br>Change-Id: Ia38308c550149d9d6eae4ca414a649957de9700c<br>---<br>M configure<br>M configure.ac<br>M include/asterisk/autoconfig.h.in<br>M main/cli.c<br>4 files changed, 38 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/30/10730/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configure b/configure</span><br><span>index 1f8f756..9eafe66 100755</span><br><span>--- a/configure</span><br><span>+++ b/configure</span><br><span>@@ -17095,7 +17095,7 @@</span><br><span> done</span><br><span> </span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-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</span><br><span style="color: hsl(120, 100%, 40%);">+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</span><br><span> do :</span><br><span> as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`</span><br><span> ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"</span><br><span>diff --git a/configure.ac b/configure.ac</span><br><span>index d1ea560..94a6633 100644</span><br><span>--- a/configure.ac</span><br><span>+++ b/configure.ac</span><br><span>@@ -794,7 +794,7 @@</span><br><span> AC_FUNC_STRTOD</span><br><span> AC_FUNC_UTIME_NULL</span><br><span> AC_FUNC_VPRINTF</span><br><span style="color: hsl(0, 100%, 40%);">-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])</span><br><span style="color: hsl(120, 100%, 40%);">+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])</span><br><span> </span><br><span> AC_MSG_CHECKING(for htonll)</span><br><span> AC_LINK_IFELSE(</span><br><span>diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in</span><br><span>index edfb9be..f401e57 100644</span><br><span>--- a/include/asterisk/autoconfig.h.in</span><br><span>+++ b/include/asterisk/autoconfig.h.in</span><br><span>@@ -468,6 +468,9 @@</span><br><span> /* Define to 1 if you have the <malloc.h> header file. */</span><br><span> #undef HAVE_MALLOC_H</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Define to 1 if you have the `malloc_trim' function. */</span><br><span style="color: hsl(120, 100%, 40%);">+#undef HAVE_MALLOC_TRIM</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Define to 1 if you have the `memchr' function. */</span><br><span> #undef HAVE_MEMCHR</span><br><span> </span><br><span>diff --git a/main/cli.c b/main/cli.c</span><br><span>index dc75acb..f980fc6 100644</span><br><span>--- a/main/cli.c</span><br><span>+++ b/main/cli.c</span><br><span>@@ -1791,6 +1791,34 @@</span><br><span> return CLI_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_MALLOC_TRIM</span><br><span style="color: hsl(120, 100%, 40%);">+ /* BUGBUG malloc_trim() is a libc specific function. Non-portable. */</span><br><span style="color: hsl(120, 100%, 40%);">+ static char *handle_cli_malloc_trim(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+ extern int malloc_trim(size_t __pad) __THROW;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ e->command = "malloc trim";</span><br><span style="color: hsl(120, 100%, 40%);">+ e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+ "Usage: malloc trim\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " Try to give excess memory back to the OS.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_GENERATE:</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (malloc_trim(0)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Returned some memory to the OS.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "No memory returned to the OS.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);</span><br><span> </span><br><span> static struct ast_cli_entry cli_cli[] = {</span><br><span>@@ -1837,6 +1865,11 @@</span><br><span> AST_CLI_DEFINE(handle_cli_check_permissions, "Try a permissions config for a user"),</span><br><span> </span><br><span> AST_CLI_DEFINE(handle_cli_wait_fullybooted, "Wait for Asterisk to be fully booted"),</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_MALLOC_TRIM</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_cli_malloc_trim, "Return excess memory to the OS"),</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10730">change 10730</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10730"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ia38308c550149d9d6eae4ca414a649957de9700c </div>
<div style="display:none"> Gerrit-Change-Number: 10730 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Chris Savinovich <csavinovich@digium.com> </div>