From: Sean Bright Date: Mon, 3 Dec 2018 22:41:56 +0000 (-0500) Subject: core: Add some documentation to the malloc_trim code X-Git-Tag: 13.24.0-rc1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44c8868fb16c37e2b3d655488fad3c92a5378202;p=thirdparty%2Fasterisk.git core: Add some documentation to the malloc_trim code This adds documentation to handle_cli_malloc_trim() indicating how it can be useful when debugging OOM conditions. Change-Id: I1936185e78035bf123cd5e097b793a55eeebdc78 --- diff --git a/main/cli.c b/main/cli.c index f980fc6397..412755681a 100644 --- a/main/cli.c +++ b/main/cli.c @@ -1793,30 +1793,43 @@ static char *handle_cli_wait_fullybooted(struct ast_cli_entry *e, int cmd, struc #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"); - } +/*! + * \internal + * \brief Attempt to reclaim unused heap memory. + * + * Users have reported that asterisk will sometimes be killed because it can't allocate + * more than around 3G of memory on a 32 bit system. + * + * Using malloc_trim() will help us to determine if it's because there's a leak or because + * the heap is so fragmented that there isn't enough contiguous memory available. + * + * \note malloc_trim() is a GNU extension and is therefore not 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; - return CLI_SUCCESS; + 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);