diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2008-10-03 18:42:46 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2008-10-03 18:42:46 +0000 |
commit | 73b4d6fa72b5d71c2cb3271fc2ac8c8321fa0b02 (patch) | |
tree | 7bffc7f49efa6b73fdc1e1f337245a93c0b5694b /lib | |
parent | d93a541cda90a80d40064aa191ea75d9dfaa921f (diff) |
avoid spitting up regions when purging stuff from the cache, it puts
too much pressure on the amaps. ok tedu@ deraadt@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdlib/malloc.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index be80640e813..1bd5c9f89c5 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.98 2008/08/25 17:56:17 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.99 2008/10/03 18:42:45 otto Exp $ */ /* * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> * @@ -402,28 +402,21 @@ unmap(struct dir_info *d, void *p, size_t sz) rsz = malloc_cache - d->free_regions_size; if (psz > rsz) tounmap = psz - rsz; - d->free_regions_size -= tounmap; offset = getrbyte(); for (i = 0; tounmap > 0 && i < malloc_cache; i++) { r = &d->free_regions[(i + offset) & (malloc_cache - 1)]; if (r->p != NULL) { - if (r->size <= tounmap) { - rsz = r->size << MALLOC_PAGESHIFT; - if (munmap(r->p, rsz)) - wrterror("munmap"); + rsz = r->size << MALLOC_PAGESHIFT; + if (munmap(r->p, rsz)) + wrterror("munmap"); + r->p = NULL; + if (tounmap > r->size) tounmap -= r->size; - r->p = NULL; - r->size = 0; - malloc_used -= rsz; - } else { - rsz = tounmap << MALLOC_PAGESHIFT; - if (munmap((char *)r->p + ((r->size - tounmap) - << MALLOC_PAGESHIFT), rsz)) - wrterror("munmap"); - r->size -= tounmap ; + else tounmap = 0; - malloc_used -= rsz; - } + d->free_regions_size -= r->size; + r->size = 0; + malloc_used -= rsz; } } if (tounmap > 0) |