Blame SOURCES/glibc-rh740506.patch

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