25912ea
	* malloc/arena.c (arena_get2): Avoid unnecessarily
25912ea
	retrieving #cpus from /proc.
25912ea
	* malloc/malloc.c (mALLOPt): Clamp arena_test based on
25912ea
	the value of arena_max.
25912ea
7b27d27
commit 41b81892f11fe1353123e892158b53de73863d62
7b27d27
Author: Ulrich Drepper <drepper@gmail.com>
7b27d27
Date:   Tue Jan 31 14:42:34 2012 -0500
7b27d27
7b27d27
    Handle ARENA_TEST correctly
7b27d27
25912ea
diff --git a/malloc/arena.c b/malloc/arena.c
7b27d27
index d3cf4b9..b1c9469 100644
25912ea
--- a/malloc/arena.c
25912ea
+++ b/malloc/arena.c
25912ea
@@ -828,7 +828,7 @@ arena_get2(mstate a_tsd, size_t size)
25912ea
 	{
25912ea
 	  if (mp_.arena_max != 0)
25912ea
 	    narenas_limit = mp_.arena_max;
25912ea
-	  else
25912ea
+	  else if (narenas > mp_.arena_test)
25912ea
 	    {
25912ea
 	      int n  = __get_nprocs ();
25912ea
 
7b27d27
@@ -842,7 +842,14 @@ arena_get2(mstate a_tsd, size_t size)
7b27d27
 	}
7b27d27
     repeat:;
7b27d27
       size_t n = narenas;
7b27d27
-      if (__builtin_expect (n <= mp_.arena_test || n < narenas_limit, 0))
7b27d27
+      /* NB: the following depends on the fact that (size_t)0 - 1 is a
7b27d27
+	 very large number and that the underflow is OK.  If arena_max
7b27d27
+	 is set the value of arena_test is irrelevant.  If arena_test
7b27d27
+	 is set but narenas is not yet larger or equal to arena_test
7b27d27
+	 narenas_limit is 0.  There is no possibility for narenas to
7b27d27
+	 be too big for the test to always fail since there is not
7b27d27
+	 enough address space to create that many arenas.  */
7b27d27
+      if (__builtin_expect (n <= narenas_limit - 1, 0))
7b27d27
 	{
7b27d27
 	  if (catomic_compare_and_exchange_bool_acq (&narenas, n + 1, n))
7b27d27
 	    goto repeat;