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