]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Handle ARENA_TEST correctly
authorUlrich Drepper <drepper@gmail.com>
Tue, 31 Jan 2012 19:42:34 +0000 (14:42 -0500)
committerCarlos O'Donell <carlos_odonell@mentor.com>
Fri, 25 May 2012 00:46:22 +0000 (20:46 -0400)
(cherry picked from commit 41b81892f11fe1353123e892158b53de73863d62)

ChangeLog
malloc/arena.c

index 267266b4cc8576256c06118248bc0ae3c58fa74c..911a76182cc2ac381a5484ba92df18a2e1b4da23 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * sysdeps/i386/fpu/feupdateenv.c (__feupdateenv) Invoke __feraiseexcept
        instead of feraiseexcept.
 
+2012-01-31  Ulrich Drepper  <drepper@gmail.com>
+
+       * malloc/arena.c (arena_get2): Really don't call __get_nprocs if
+       ARENA_TEST says not to.  Simplify test for creation of a new arena.
+       Partially based on a patch by Siddhesh Poyarekar <siddhesh@redhat.com>.
+
 2012-01-28  Chris Metcalf  <cmetcalf@tilera.com>
 
        * scripts/firstversions.awk: Fix bug in version range handling.
index cb8548ba3f0379ad5311e638c1a0ac64d66c49d4..f88b41d19b025d41791ea4cc5db60a5f913aa51f 100644 (file)
@@ -828,7 +828,7 @@ arena_get2(mstate a_tsd, size_t size)
        {
          if (mp_.arena_max != 0)
            narenas_limit = mp_.arena_max;
-         else
+         else if (narenas > mp_.arena_test)
            {
              int n  = __get_nprocs ();
 
@@ -842,7 +842,14 @@ arena_get2(mstate a_tsd, size_t size)
        }
     repeat:;
       size_t n = narenas;
-      if (__builtin_expect (n <= mp_.arena_test || n < narenas_limit, 0))
+      /* NB: the following depends on the fact that (size_t)0 - 1 is a
+        very large number and that the underflow is OK.  If arena_max
+        is set the value of arena_test is irrelevant.  If arena_test
+        is set but narenas is not yet larger or equal to arena_test
+        narenas_limit is 0.  There is no possibility for narenas to
+        be too big for the test to always fail since there is not
+        enough address space to create that many arenas.  */
+      if (__builtin_expect (n <= narenas_limit - 1, 0))
        {
          if (catomic_compare_and_exchange_bool_acq (&narenas, n + 1, n))
            goto repeat;