diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-04-01 23:07:03 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-04-01 23:07:03 -0400 |
commit | bf8785825ac57371c268f54866923d6f89231639 (patch) | |
tree | e4df93ab7d90452da3bf170689acb930ce29e057 | |
parent | 952987a0cb9b1973fdf23e05f8ddc6fe3c98fd68 (diff) | |
download | musl-bf8785825ac57371c268f54866923d6f89231639.tar.gz |
avoid over-allocation of brk on first malloc
if init_malloc returns positive (successful first init), malloc will
retry getting a chunk from the free bins rather than expanding the
heap again. also pass init_malloc a hint for the size of the initial
allocation.
-rw-r--r-- | src/malloc/malloc.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index a4eefda9..ee6f170b 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -179,7 +179,7 @@ fail: return 0; } -static int init_malloc() +static int init_malloc(size_t n) { static int init, waiters; int state; @@ -196,7 +196,7 @@ static int init_malloc() mal.brk = __brk(0) + 2*SIZE_ALIGN-1 & -SIZE_ALIGN; - c = expand_heap(1); + c = expand_heap(n); if (!c) { a_store(&init, 0); @@ -210,7 +210,7 @@ static int init_malloc() a_store(&init, 2); if (waiters) __wake(&init, -1, 1); - return 0; + return 1; } static int adjust_size(size_t *n) @@ -347,7 +347,7 @@ void *malloc(size_t n) for (;;) { uint64_t mask = mal.binmap & -(1ULL<<i); if (!mask) { - init_malloc(); + if (init_malloc(n) > 0) continue; c = expand_heap(n); if (!c) return 0; if (alloc_rev(c)) { |