summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2008-10-29 14:05:16 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2008-10-29 14:05:16 +0000
commit4ee8094396765fb6a634e48b4987843d3c280a67 (patch)
tree4cbde4d463a38583165ee727d304445fd46057bc /lib/libc
parent650a637536ab4a956a9e6b6f07e98f5d1b4e845e (diff)
if MALLOC_STATS is defined, record how many "cheap reallocs" were
tried and how many actually succeeded.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdlib/malloc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 3f3ec951d5f..603cc55f186 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/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 <otto@drijf.net>
*
@@ -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);