Blame SOURCES/glibc-rh789238-2.patch

b9ba6d
diff -rup a/malloc/arena.c b/malloc/arena.c
b9ba6d
--- a/malloc/arena.c	2012-03-02 10:22:47.025002715 -0700
b9ba6d
+++ b/malloc/arena.c	2012-03-02 10:27:47.442361529 -0700
b9ba6d
@@ -123,14 +123,14 @@ int __malloc_initialized = -1;
b9ba6d
   if(ptr) \
b9ba6d
     (void)mutex_lock(&ptr->mutex); \
b9ba6d
   else \
b9ba6d
-    ptr = arena_get2(ptr, (size)); \
b9ba6d
+    ptr = arena_get2(ptr, (size), false); \
b9ba6d
 } while(0)
b9ba6d
 #else
b9ba6d
 #define arena_lock(ptr, size) do { \
b9ba6d
   if(ptr && !mutex_trylock(&ptr->mutex)) { \
b9ba6d
     THREAD_STAT(++(ptr->stat_lock_direct)); \
b9ba6d
   } else \
b9ba6d
-    ptr = arena_get2(ptr, (size)); \
b9ba6d
+    ptr = arena_get2(ptr, (size), false); \
b9ba6d
 } while(0)
b9ba6d
 #endif
b9ba6d
 
b9ba6d
@@ -982,7 +982,7 @@ get_free_list (void)
b9ba6d
 
b9ba6d
 
b9ba6d
 static mstate
b9ba6d
-reused_arena (void)
b9ba6d
+reused_arena (bool retrying)
b9ba6d
 {
b9ba6d
   mstate result;
b9ba6d
   static mstate next_to_use;
b9ba6d
@@ -999,6 +999,15 @@ reused_arena (void)
b9ba6d
     }
b9ba6d
   while (result != next_to_use);
b9ba6d
 
b9ba6d
+  /* If we are retrying due to a failure to allocate in the main
b9ba6d
+     arena, don't wait for the main arena to become available, select
b9ba6d
+     another.
b9ba6d
+
b9ba6d
+     To really fix this right we would have to try the allocation
b9ba6d
+     in every other arena, but that seems like severe overkill.  */
b9ba6d
+  if (retrying && result == &main_arena)
b9ba6d
+    result = result->next;
b9ba6d
+
b9ba6d
   /* No arena available.  Wait for the next in line.  */
b9ba6d
   (void)mutex_lock(&result->mutex);
b9ba6d
 
b9ba6d
@@ -1014,9 +1023,9 @@ reused_arena (void)
b9ba6d
 static mstate
b9ba6d
 internal_function
b9ba6d
 #if __STD_C
b9ba6d
-arena_get2(mstate a_tsd, size_t size)
b9ba6d
+arena_get2(mstate a_tsd, size_t size, bool retrying)
b9ba6d
 #else
b9ba6d
-arena_get2(a_tsd, size) mstate a_tsd; size_t size;
b9ba6d
+arena_get2(a_tsd, size, retrying) mstate a_tsd; size_t size; bool retrying
b9ba6d
 #endif
b9ba6d
 {
b9ba6d
   mstate a;
b9ba6d
@@ -1055,7 +1064,7 @@ arena_get2(a_tsd, size) mstate a_tsd; si
b9ba6d
 	    catomic_decrement (&narenas);
b9ba6d
 	}
b9ba6d
       else
b9ba6d
-	a = reused_arena ();
b9ba6d
+	a = reused_arena (retrying);
b9ba6d
     }
b9ba6d
 #else
b9ba6d
   if(!a_tsd)
b9ba6d
diff -rup a/malloc/malloc.c b/malloc/malloc.c
b9ba6d
--- a/malloc/malloc.c	2012-03-02 10:22:47.061002519 -0700
b9ba6d
+++ b/malloc/malloc.c	2012-03-02 10:23:53.151643863 -0700
b9ba6d
@@ -3671,7 +3671,7 @@ public_mALLOc(size_t bytes)
b9ba6d
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b9ba6d
       mstate prev = ar_ptr->next ? ar_ptr : 0;
b9ba6d
       (void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
-      ar_ptr = arena_get2(prev, bytes);
b9ba6d
+      ar_ptr = arena_get2(prev, bytes, true);
b9ba6d
       if(ar_ptr) {
b9ba6d
 	victim = _int_malloc(ar_ptr, bytes);
b9ba6d
 	(void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
@@ -3892,7 +3892,7 @@ public_mEMALIGn(size_t alignment, size_t
b9ba6d
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b9ba6d
       mstate prev = ar_ptr->next ? ar_ptr : 0;
b9ba6d
       (void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
-      ar_ptr = arena_get2(prev, bytes);
b9ba6d
+      ar_ptr = arena_get2(prev, bytes, true);
b9ba6d
       if(ar_ptr) {
b9ba6d
 	p = _int_memalign(ar_ptr, alignment, bytes);
b9ba6d
 	(void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
@@ -3943,7 +3943,7 @@ public_vALLOc(size_t bytes)
b9ba6d
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b9ba6d
       mstate prev = ar_ptr->next ? ar_ptr : 0;
b9ba6d
       (void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
-      ar_ptr = arena_get2(prev, bytes);
b9ba6d
+      ar_ptr = arena_get2(prev, bytes, true);
b9ba6d
       if(ar_ptr) {
b9ba6d
 	p = _int_memalign(ar_ptr, pagesz, bytes);
b9ba6d
 	(void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
@@ -3992,7 +3992,7 @@ public_pVALLOc(size_t bytes)
b9ba6d
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b9ba6d
       mstate prev = ar_ptr->next ? ar_ptr : 0;
b9ba6d
       (void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
-      ar_ptr = arena_get2(prev, bytes + 2*pagesz + MINSIZE);
b9ba6d
+      ar_ptr = arena_get2(prev, bytes + 2*pagesz + MINSIZE, true);
b9ba6d
       if(ar_ptr) {
b9ba6d
 	p = _int_memalign(ar_ptr, pagesz, rounded_bytes);
b9ba6d
 	(void)mutex_unlock(&ar_ptr->mutex);
b9ba6d
@@ -4086,7 +4086,7 @@ public_cALLOc(size_t n, size_t elem_size
b9ba6d
       /* ... or sbrk() has failed and there is still a chance to mmap() */
b9ba6d
       mstate prev = av->next ? av : 0;
b9ba6d
       (void)mutex_unlock(&av->mutex);
b9ba6d
-      av = arena_get2(prev, sz);
b9ba6d
+      av = arena_get2(prev, sz, true);
b9ba6d
       if(av) {
b9ba6d
 	mem = _int_malloc(av, sz);
b9ba6d
 	(void)mutex_unlock(&av->mutex);