diff options
author | jasone <jasone@FreeBSD.org> | 2006-03-26 23:41:35 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2006-03-26 23:41:35 +0000 |
commit | 0ed4b6d88e68ca2981c76cc1cc5235611cc98485 (patch) | |
tree | 74679f1f2dae3576c623b69204d8e69fde9dcd05 /lib/libc | |
parent | 9b6cd0a1ee32fc2c30e51fc412fabf3fa851df6d (diff) | |
download | FreeBSD-src-0ed4b6d88e68ca2981c76cc1cc5235611cc98485.zip FreeBSD-src-0ed4b6d88e68ca2981c76cc1cc5235611cc98485.tar.gz |
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().
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdlib/malloc.c | 18 |
1 files changed, 16 insertions, 2 deletions
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) { |