Browse Source

avoid spitting up regions when purging stuff from the cache, it puts

too much pressure on the amaps. ok tedu@ deraadt@
OPENBSD_4_5
otto 15 years ago
parent
commit
013c97fa02
1 changed files with 10 additions and 17 deletions
  1. +10
    -17
      src/lib/libc/stdlib/malloc.c

+ 10
- 17
src/lib/libc/stdlib/malloc.c View File

@ -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)


Loading…
Cancel
Save