Blame SOURCES/glibc-rh740506.patch

b40826
2011-11-14  Andreas Schwab  <schwab@redhat.com>
b40826
b40826
	* malloc/arena.c (arena_get2): Don't call reused_arena when
b40826
	_int_new_arena failed.
b40826
b40826
2011-11-10  Andreas Schwab  <schwab@redhat.com>
b40826
b40826
	* malloc/arena.c (_int_new_arena): Don't increment narenas.
b40826
	(reused_arena): Don't check arena limit.
b40826
	(arena_get2): Atomically check arena limit.
b40826
b40826
diff --git a/malloc/arena.c b/malloc/arena.c
b40826
index 9114fd2..042cac8 100644
b40826
--- a/malloc/arena.c
b40826
+++ b/malloc/arena.c
b40826
@@ -747,8 +747,6 @@ _int_new_arena(size_t size)
b40826
   main_arena.next = a;
b40826
 
b40826
 #ifdef PER_THREAD
b40826
-  ++narenas;
b40826
-
b40826
   (void)mutex_unlock(&list_lock);
b40826
 #endif
b40826
 
b40826
@@ -786,30 +784,6 @@ get_free_list (void)
b40826
 static mstate
b40826
 reused_arena (void)
b40826
 {
b40826
-  if (narenas <= mp_.arena_test)
b40826
-    return NULL;
b40826
-
b40826
-  static int narenas_limit;
b40826
-  if (narenas_limit == 0)
b40826
-    {
b40826
-      if (mp_.arena_max != 0)
b40826
-	narenas_limit = mp_.arena_max;
b40826
-      else
b40826
-	{
b40826
-	  int n  = __get_nprocs ();
b40826
-
b40826
-	  if (n >= 1)
b40826
-	    narenas_limit = NARENAS_FROM_NCORES (n);
b40826
-	  else
b40826
-	    /* We have no information about the system.  Assume two
b40826
-	       cores.  */
b40826
-	    narenas_limit = NARENAS_FROM_NCORES (2);
b40826
-	}
b40826
-    }
b40826
-
b40826
-  if (narenas < narenas_limit)
b40826
-    return NULL;
b40826
-
b40826
   mstate result;
b40826
   static mstate next_to_use;
b40826
   if (next_to_use == NULL)
b40826
@@ -844,10 +818,41 @@ arena_get2(mstate a_tsd, size_t size)
b40826
   mstate a;
b40826
 
b40826
 #ifdef PER_THREAD
b40826
-  if ((a = get_free_list ()) == NULL
b40826
-      && (a = reused_arena ()) == NULL)
b40826
-    /* Nothing immediately available, so generate a new arena.  */
b40826
-    a = _int_new_arena(size);
b40826
+  static size_t narenas_limit;
b40826
+
b40826
+  a = get_free_list ();
b40826
+  if (a == NULL)
b40826
+    {
b40826
+      /* Nothing immediately available, so generate a new arena.  */
b40826
+      if (narenas_limit == 0)
b40826
+	{
b40826
+	  if (mp_.arena_max != 0)
b40826
+	    narenas_limit = mp_.arena_max;
b40826
+	  else
b40826
+	    {
b40826
+	      int n  = __get_nprocs ();
b40826
+
b40826
+	      if (n >= 1)
b40826
+		narenas_limit = NARENAS_FROM_NCORES (n);
b40826
+	      else
b40826
+		/* We have no information about the system.  Assume two
b40826
+		   cores.  */
b40826
+		narenas_limit = NARENAS_FROM_NCORES (2);
b40826
+	    }
b40826
+	}
b40826
+    repeat:;
b40826
+      size_t n = narenas;
b40826
+      if (__builtin_expect (n <= mp_.arena_test || n < narenas_limit, 0))
b40826
+	{
b40826
+	  if (catomic_compare_and_exchange_bool_acq(&narenas, n + 1, n))
b40826
+	    goto repeat;
b40826
+	  a = _int_new_arena (size);
b40826
+	  if (__builtin_expect (a != NULL, 1))
b40826
+	    return a;
b40826
+	  catomic_decrement(&narenas);
b40826
+	}
b40826
+      a = reused_arena ();
b40826
+    }
b40826
 #else
b40826
   if(!a_tsd)
b40826
     a = a_tsd = &main_arena;
b40826
b40826
commit a5fb313cb7b7e692fd4684916aaa98e03ec7e8b6
b40826
Author: Andreas Schwab <schwab@redhat.com>
b40826
Date:   Mon Nov 14 11:41:52 2011 +0100
b40826
b40826
    Don't call reused_arena when _int_new_arena failed
b40826
b40826
diff --git a/malloc/arena.c b/malloc/arena.c
b40826
index 042cac8..cb8548b 100644
b40826
--- a/malloc/arena.c
b40826
+++ b/malloc/arena.c
b40826
@@ -844,14 +844,14 @@ arena_get2(mstate a_tsd, size_t size)
b40826
       size_t n = narenas;
b40826
       if (__builtin_expect (n <= mp_.arena_test || n < narenas_limit, 0))
b40826
 	{
b40826
-	  if (catomic_compare_and_exchange_bool_acq(&narenas, n + 1, n))
b40826
+	  if (catomic_compare_and_exchange_bool_acq (&narenas, n + 1, n))
b40826
 	    goto repeat;
b40826
 	  a = _int_new_arena (size);
b40826
-	  if (__builtin_expect (a != NULL, 1))
b40826
-	    return a;
b40826
-	  catomic_decrement(&narenas);
b40826
+	  if (__builtin_expect (a == NULL, 0))
b40826
+	    catomic_decrement (&narenas);
b40826
 	}
b40826
-      a = reused_arena ();
b40826
+      else
b40826
+	a = reused_arena ();
b40826
     }
b40826
 #else
b40826
   if(!a_tsd)