diff options
| author | otto <> | 2008-10-29 14:05:15 +0000 |
|---|---|---|
| committer | otto <> | 2008-10-29 14:05:15 +0000 |
| commit | 36c5e8ecef339cd13f51e8181ff18063de971ac3 (patch) | |
| tree | c9771a153fdef373a66fbf2dfa55d7fa51b9a08e /src/lib/libc | |
| parent | ae095d3b70be5653b67e6ec06101bd5bfc85294d (diff) | |
| download | openbsd-36c5e8ecef339cd13f51e8181ff18063de971ac3.tar.gz openbsd-36c5e8ecef339cd13f51e8181ff18063de971ac3.tar.bz2 openbsd-36c5e8ecef339cd13f51e8181ff18063de971ac3.zip | |
if MALLOC_STATS is defined, record how many "cheap reallocs" were
tried and how many actually succeeded.
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 3f3ec951d5..603cc55f18 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: malloc.c,v 1.103 2008/10/20 06:19:02 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.104 2008/10/29 14:05:15 otto Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> |
| 4 | * | 4 | * |
| @@ -108,6 +108,8 @@ struct dir_info { | |||
| 108 | size_t find_collisions; | 108 | size_t find_collisions; |
| 109 | size_t deletes; | 109 | size_t deletes; |
| 110 | size_t delete_moves; | 110 | size_t delete_moves; |
| 111 | size_t cheap_realloc_tries; | ||
| 112 | size_t cheap_reallocs; | ||
| 111 | #define STATS_INC(x) ((x)++) | 113 | #define STATS_INC(x) ((x)++) |
| 112 | #define STATS_ZERO(x) ((x) = 0) | 114 | #define STATS_ZERO(x) ((x) = 0) |
| 113 | #else | 115 | #else |
| @@ -271,6 +273,9 @@ malloc_dump1(int fd, struct dir_info *d) | |||
| 271 | snprintf(buf, sizeof(buf), "Deletes %zu/%zu\n", d->deletes, | 273 | snprintf(buf, sizeof(buf), "Deletes %zu/%zu\n", d->deletes, |
| 272 | d->delete_moves); | 274 | d->delete_moves); |
| 273 | write(fd, buf, strlen(buf)); | 275 | write(fd, buf, strlen(buf)); |
| 276 | snprintf(buf, sizeof(buf), "Cheap reallocs %zu/%zu\n", | ||
| 277 | d->cheap_reallocs, d->cheap_realloc_tries); | ||
| 278 | write(fd, buf, strlen(buf)); | ||
| 274 | snprintf(buf, sizeof(buf), "Regions slots free %zu\n", d->regions_free); | 279 | snprintf(buf, sizeof(buf), "Regions slots free %zu\n", d->regions_free); |
| 275 | write(fd, buf, strlen(buf)); | 280 | write(fd, buf, strlen(buf)); |
| 276 | for (i = 0; i < d->regions_total; i++) { | 281 | for (i = 0; i < d->regions_total; i++) { |
| @@ -1307,6 +1312,7 @@ orealloc(void *p, size_t newsz) | |||
| 1307 | 1312 | ||
| 1308 | if (rnewsz > roldsz) { | 1313 | if (rnewsz > roldsz) { |
| 1309 | if (!malloc_guard) { | 1314 | if (!malloc_guard) { |
| 1315 | STATS_INC(g_pool.cheap_realloc_tries); | ||
| 1310 | zapcacheregion(&g_pool, p + roldsz); | 1316 | zapcacheregion(&g_pool, p + roldsz); |
| 1311 | q = MMAPA(p + roldsz, rnewsz - roldsz); | 1317 | q = MMAPA(p + roldsz, rnewsz - roldsz); |
| 1312 | if (q == p + roldsz) { | 1318 | if (q == p + roldsz) { |
| @@ -1315,6 +1321,7 @@ orealloc(void *p, size_t newsz) | |||
| 1315 | memset(q, SOME_JUNK, | 1321 | memset(q, SOME_JUNK, |
| 1316 | rnewsz - roldsz); | 1322 | rnewsz - roldsz); |
| 1317 | r->size = newsz; | 1323 | r->size = newsz; |
| 1324 | STATS_INC(g_pool.cheap_reallocs); | ||
| 1318 | return p; | 1325 | return p; |
| 1319 | } else if (q != MAP_FAILED) | 1326 | } else if (q != MAP_FAILED) |
| 1320 | munmap(q, rnewsz - roldsz); | 1327 | munmap(q, rnewsz - roldsz); |
