From 02508dddff9091e1c77fc642b11bb109eb4fe52c Mon Sep 17 00:00:00 2001 From: otto <> Date: Wed, 29 Oct 2008 14:05:15 +0000 Subject: [PATCH] if MALLOC_STATS is defined, record how many "cheap reallocs" were tried and how many actually succeeded. --- src/lib/libc/stdlib/malloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 3f3ec951..603cc55f 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.103 2008/10/20 06:19:02 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.104 2008/10/29 14:05:15 otto Exp $ */ /* * Copyright (c) 2008 Otto Moerbeek * @@ -108,6 +108,8 @@ struct dir_info { size_t find_collisions; size_t deletes; size_t delete_moves; + size_t cheap_realloc_tries; + size_t cheap_reallocs; #define STATS_INC(x) ((x)++) #define STATS_ZERO(x) ((x) = 0) #else @@ -271,6 +273,9 @@ malloc_dump1(int fd, struct dir_info *d) snprintf(buf, sizeof(buf), "Deletes %zu/%zu\n", d->deletes, d->delete_moves); write(fd, buf, strlen(buf)); + snprintf(buf, sizeof(buf), "Cheap reallocs %zu/%zu\n", + d->cheap_reallocs, d->cheap_realloc_tries); + write(fd, buf, strlen(buf)); snprintf(buf, sizeof(buf), "Regions slots free %zu\n", d->regions_free); write(fd, buf, strlen(buf)); for (i = 0; i < d->regions_total; i++) { @@ -1307,6 +1312,7 @@ orealloc(void *p, size_t newsz) if (rnewsz > roldsz) { if (!malloc_guard) { + STATS_INC(g_pool.cheap_realloc_tries); zapcacheregion(&g_pool, p + roldsz); q = MMAPA(p + roldsz, rnewsz - roldsz); if (q == p + roldsz) { @@ -1315,6 +1321,7 @@ orealloc(void *p, size_t newsz) memset(q, SOME_JUNK, rnewsz - roldsz); r->size = newsz; + STATS_INC(g_pool.cheap_reallocs); return p; } else if (q != MAP_FAILED) munmap(q, rnewsz - roldsz);