From 0ed4b6d88e68ca2981c76cc1cc5235611cc98485 Mon Sep 17 00:00:00 2001 From: jasone Date: Sun, 26 Mar 2006 23:41:35 +0000 Subject: Allow the 'n' option to decrease the number of arenas below the default, to as little as one arena. Also, limit the number of arenas to avoid a potential invariant violation in base_alloc(). --- lib/libc/stdlib/malloc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/libc/stdlib/malloc.c') diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index b86f3a2..91357a0 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -3200,8 +3200,22 @@ malloc_init_hard(void) /* Determine how many arenas to use. */ narenas = ncpus; - if (opt_narenas_lshift > 0) - narenas <<= opt_narenas_lshift; + if (opt_narenas_lshift > 0) { + if ((narenas << opt_narenas_lshift) > narenas) + narenas <<= opt_narenas_lshift; + /* + * Make sure not to exceed the limits of what base_malloc() + * can handle. + */ + if (narenas * sizeof(arena_t *) > chunk_size) + narenas = chunk_size / sizeof(arena_t *); + } else if (opt_narenas_lshift < 0) { + if ((narenas << opt_narenas_lshift) < narenas) + narenas <<= opt_narenas_lshift; + /* Make sure there is at least one arena. */ + if (narenas == 0) + narenas = 1; + } #ifdef NO_TLS if (narenas > 1) { -- cgit v1.1