[Asterisk-code-review] core: Add some documentation to the malloc trim code (asterisk[certified/13.21])

Jenkins2 asteriskteam at digium.com
Thu Dec 6 05:55:38 CST 2018


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

Change subject: core: Add some documentation to the malloc_trim code
......................................................................

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
---
M main/cli.c
1 file changed, 34 insertions(+), 21 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/main/cli.c b/main/cli.c
index f980fc6..4127556 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1793,30 +1793,43 @@
 
 
 #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;
-		}
+/*!
+ * \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;
 
-		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;
+	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);

-- 
To view, visit https://gerrit.asterisk.org/10738
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: I1936185e78035bf123cd5e097b793a55eeebdc78
Gerrit-Change-Number: 10738
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>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181206/8beadd13/attachment-0001.html>


More information about the asterisk-code-review mailing list