summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/malloc.c
diff options
context:
space:
mode:
authorJason Evans <jasone@FreeBSD.org>2006-03-26 23:41:35 +0000
committerJason Evans <jasone@FreeBSD.org>2006-03-26 23:41:35 +0000
commit9f9bc9367c83638c3d37953e7d96bdc67457c7c0 (patch)
tree74679f1f2dae3576c623b69204d8e69fde9dcd05 /lib/libc/stdlib/malloc.c
parent4328edf534b41e03ac688962268926000eff88d5 (diff)
Notes
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r--lib/libc/stdlib/malloc.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index b86f3a24988a..91357a0429fd 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) {