summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortedu <>2012-06-20 13:13:15 +0000
committertedu <>2012-06-20 13:13:15 +0000
commit80020aecd05f49119bfeaec130105f3890a5258a (patch)
treeb9a33777b6bd390447e44927f9639e5045ab39ee /src
parent71b2db593f575c8e8ada85098d2b61ee7f67408b (diff)
downloadopenbsd-80020aecd05f49119bfeaec130105f3890a5258a.tar.gz
openbsd-80020aecd05f49119bfeaec130105f3890a5258a.tar.bz2
openbsd-80020aecd05f49119bfeaec130105f3890a5258a.zip
two small fixes to free page cache. first, we need two nibbles of random
in order to span the the entire cache. second, on free use the same offset to put things in the cache instead of always starting at zero. ok otto
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/malloc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index 6f646934b2..92efd7d68b 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.142 2012/06/18 17:03:51 matthew Exp $ */ 1/* $OpenBSD: malloc.c,v 1.143 2012/06/20 13:13:15 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
4 * 4 *
@@ -317,7 +317,7 @@ unmap(struct dir_info *d, void *p, size_t sz)
317 rsz = mopts.malloc_cache - d->free_regions_size; 317 rsz = mopts.malloc_cache - d->free_regions_size;
318 if (psz > rsz) 318 if (psz > rsz)
319 tounmap = psz - rsz; 319 tounmap = psz - rsz;
320 offset = getrnibble(); 320 offset = getrnibble() + getrnibble() << 4;
321 for (i = 0; tounmap > 0 && i < mopts.malloc_cache; i++) { 321 for (i = 0; tounmap > 0 && i < mopts.malloc_cache; i++) {
322 r = &d->free_regions[(i + offset) & (mopts.malloc_cache - 1)]; 322 r = &d->free_regions[(i + offset) & (mopts.malloc_cache - 1)];
323 if (r->p != NULL) { 323 if (r->p != NULL) {
@@ -337,7 +337,7 @@ unmap(struct dir_info *d, void *p, size_t sz)
337 if (tounmap > 0) 337 if (tounmap > 0)
338 wrterror("malloc cache underflow", NULL); 338 wrterror("malloc cache underflow", NULL);
339 for (i = 0; i < mopts.malloc_cache; i++) { 339 for (i = 0; i < mopts.malloc_cache; i++) {
340 r = &d->free_regions[i]; 340 r = &d->free_regions[(i + offset) & (mopts.malloc_cache - 1)];
341 if (r->p == NULL) { 341 if (r->p == NULL) {
342 if (mopts.malloc_hint) 342 if (mopts.malloc_hint)
343 madvise(p, sz, MADV_FREE); 343 madvise(p, sz, MADV_FREE);
@@ -398,7 +398,7 @@ map(struct dir_info *d, size_t sz, int zero_fill)
398 /* zero fill not needed */ 398 /* zero fill not needed */
399 return p; 399 return p;
400 } 400 }
401 offset = getrnibble(); 401 offset = getrnibble() + getrnibble() << 4;
402 for (i = 0; i < mopts.malloc_cache; i++) { 402 for (i = 0; i < mopts.malloc_cache; i++) {
403 r = &d->free_regions[(i + offset) & (mopts.malloc_cache - 1)]; 403 r = &d->free_regions[(i + offset) & (mopts.malloc_cache - 1)];
404 if (r->p != NULL) { 404 if (r->p != NULL) {