]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
core: Merge malloc_trim patch
authorChris-Savinovich <csavinovich@digium.com>
Mon, 3 Dec 2018 20:01:01 +0000 (14:01 -0600)
committerChris Savinovich <csavinovich@digium.com>
Mon, 3 Dec 2018 20:07:17 +0000 (15:07 -0500)
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

configure
configure.ac
include/asterisk/autoconfig.h.in
main/cli.c

index faf078185b1e160047d0e8955132280744224636..061845f907c20321860cc84e72dfd11f8fbfab8e 100755 (executable)
--- a/configure
+++ b/configure
@@ -16847,7 +16847,7 @@ fi
 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"
index dd0c8edd13c2b8a5098f014333b76974191ddafa..e541e33b3aa19e9d9bdc4c675a0a78f426a3c74d 100644 (file)
@@ -784,7 +784,7 @@ AC_FUNC_STRNLEN
 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(
index 30bb90749df7bf753ece1ccc027c969c422e47da..d0141fbbb69c40dec414ee6ef336d771879a06d7 100644 (file)
 /* 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 <math.h> header file. */
 #undef HAVE_MATH_H
 
index cf51d0d9521c4a693372a9deaf56628f0d4f84b8..5a6fdbe4484da5829fc9829adbd539006e97bc37 100644 (file)
@@ -1788,6 +1788,34 @@ static char *handle_cli_wait_fullybooted(struct ast_cli_entry *e, int cmd, struc
        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[] = {
@@ -1833,6 +1861,11 @@ static struct ast_cli_entry cli_cli[] = {
        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
+
 };
 
 /*!