[svn-commits] tilghman: branch tilghman/malloc_hold r209447 - /team/tilghman/malloc_hold/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 28 21:30:31 CDT 2009


Author: tilghman
Date: Tue Jul 28 21:30:26 2009
New Revision: 209447

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=209447
Log:
And no longer eating memory

Modified:
    team/tilghman/malloc_hold/main/astmm.c

Modified: team/tilghman/malloc_hold/main/astmm.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tilghman/malloc_hold/main/astmm.c?view=diff&rev=209447&r1=209446&r2=209447
==============================================================================
--- team/tilghman/malloc_hold/main/astmm.c (original)
+++ team/tilghman/malloc_hold/main/astmm.c Tue Jul 28 21:30:26 2009
@@ -265,7 +265,11 @@
 			MPROTECT(cur, sizeof(*cur), PROT_NONE);
 
 			ast_mutex_unlock(&reglock);
-			sleep(sleep_time);
+			if (sleep_time > 0) {
+				sleep(sleep_time);
+			} else {
+				sched_yield();
+			}
 		} else {
 			ast_mutex_unlock(&reglock);
 			astmm_log("Nothing in free list.  Sleeping for %d seconds.\n", HOLD_LENGTH);
@@ -435,7 +439,7 @@
 
 		/* If I don't find an exact match, then find me the smallest available
 		 * block that matches my needs. */
-		if (best_reg->fullsize > reg->fullsize) {
+		if (!best_reg || best_reg->fullsize > reg->fullsize) {
 			best_reg = reg;
 			best_prev = prev;
 		}
@@ -744,6 +748,60 @@
 
 	return size;
 }
+
+#ifdef MALLOC_HOLD
+static int handle_memory_show_free_available(int fd, int argc, char *argv[])
+{
+	int sizes[100] = { 0, }, i, isfree = 0;
+	struct ast_region *reg, *prev = NULL, *master;
+
+	if (!strcasecmp(argv[2], "free")) {
+		master = regions[FREE_LIST];
+		isfree = 1;
+	} else if (!strcasecmp(argv[2], "available")) {
+		master = regions[AVAILABLE_LIST];
+	} else if (!strcasecmp(argv[2], "polluted")) {
+		master = regions[POLLUTED_LIST];
+	} else {
+		ast_cli(fd, "Unknown list %s\n", argv[2]);
+		return RESULT_FAILURE;
+	}
+
+	ast_mutex_lock(&reglock);
+
+	if (isfree) {
+		MPROTECT(master, sizeof(*master), PROT_READ);
+		ast_cli(fd, "Top item on the free list has a date of %d (now is %d) and it %s\n", master->freetime, (int) time(NULL), time(NULL) > master->freetime + HOLD_LENGTH ? "is already past due (BAD!)" : "hasn't expired yet");
+	}
+
+	for (reg = master; reg;
+		prev = reg,
+		reg = reg->next) {
+		int mysize;
+		if (isfree) {
+			MPROTECT(reg, sizeof(*reg), PROT_READ);
+		}
+		if ((mysize = reg->fullsize / pagesize) > 100) {
+			mysize = 100;
+		}
+		if (isfree && prev) {
+			MPROTECT(prev, sizeof(*prev), PROT_NONE);
+		}
+		sizes[mysize - 1]++;
+	}
+	if (isfree && prev) {
+		MPROTECT(prev, sizeof(*prev), PROT_NONE);
+	}
+	ast_mutex_unlock(&reglock);
+
+	for (i = 0; i < ARRAY_LEN(sizes); i++) {
+		if (sizes[i] > 0) {
+			ast_cli(fd, "Size 4096 * %3d: %5d\n", i + 1, sizes[i]);
+		}
+	}
+	return RESULT_SUCCESS;
+}
+#endif
 
 static int handle_show_memory(int fd, int argc, char *argv[])
 {
@@ -881,6 +939,11 @@
 "       Summarizes heap memory allocations by file, or optionally\n"
 "by function, if a file is specified\n";
 
+#ifdef MALLOC_HOLD
+static char memory_show_free_available_help[] =
+"Usage: memory show {free|available|polluted}\n";
+#endif
+
 static struct ast_cli_entry cli_show_memory_allocations_deprecated = {
 	{ "show", "memory", "allocations", NULL },
 	handle_show_memory, NULL,
@@ -899,6 +962,20 @@
 	{ { "memory", "show", "summary", NULL },
 	handle_show_memory_summary, "Summarize outstanding memory allocations",
 	show_memory_summary_help, NULL, &cli_show_memory_summary_deprecated },
+
+#ifdef MALLOC_HOLD
+	{ { "memory", "show", "free", NULL },
+	handle_memory_show_free_available, "Show memory in a freed stage",
+	memory_show_free_available_help, },
+
+	{ { "memory", "show", "available", NULL },
+	handle_memory_show_free_available, "Show memory in an available stage",
+	memory_show_free_available_help, },
+
+	{ { "memory", "show", "polluted", NULL },
+	handle_memory_show_free_available, "Show memory removed from usage",
+	memory_show_free_available_help, },
+#endif
 };
 
 /*!




More information about the svn-commits mailing list