1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00
* malloc.c/arena.c (reused_arena): New parameter, avoid_arena.
        When avoid_arena is set, don't retry in the that arena.  Pick the
        next one, whatever it might be.
        (arena_get2): New parameter avoid_arena, pass through to reused_arena.
        (arena_lock): Pass in new parameter to arena_get2.
        * malloc/malloc.c (__libc_memalign): Pass in new parameter to
        arena_get2.
        (__libc_malloc): Unify retrying after main arena failure with
        __libc_memalign version.
        (__libc_valloc, __libc_pvalloc, __libc_calloc): Likewise.
This commit is contained in:
Jeff Law
2012-08-10 09:37:04 -06:00
parent 2d83a317e9
commit bf51f568f1
4 changed files with 61 additions and 29 deletions

View File

@@ -120,14 +120,14 @@ int __malloc_initialized = -1;
if(ptr) \
(void)mutex_lock(&ptr->mutex); \
else \
ptr = arena_get2(ptr, (size)); \
ptr = arena_get2(ptr, (size), NULL); \
} while(0)
#else
# define arena_lock(ptr, size) do { \
if(ptr && !mutex_trylock(&ptr->mutex)) { \
THREAD_STAT(++(ptr->stat_lock_direct)); \
} else \
ptr = arena_get2(ptr, (size)); \
ptr = arena_get2(ptr, (size), NULL); \
} while(0)
#endif
@@ -778,9 +778,11 @@ get_free_list (void)
return result;
}
/* Lock and return an arena that can be reused for memory allocation.
Avoid AVOID_ARENA as we have already failed to allocate memory in
it and it is currently locked. */
static mstate
reused_arena (void)
reused_arena (mstate avoid_arena)
{
mstate result;
static mstate next_to_use;
@@ -797,6 +799,11 @@ reused_arena (void)
}
while (result != next_to_use);
/* Avoid AVOID_ARENA as we have already failed to allocate memory
in that arena and it is currently locked. */
if (result == avoid_arena)
result = result->next;
/* No arena available. Wait for the next in line. */
(void)mutex_lock(&result->mutex);
@@ -811,7 +818,7 @@ reused_arena (void)
static mstate
internal_function
arena_get2(mstate a_tsd, size_t size)
arena_get2(mstate a_tsd, size_t size, mstate avoid_arena)
{
mstate a;
@@ -856,7 +863,7 @@ arena_get2(mstate a_tsd, size_t size)
catomic_decrement (&narenas);
}
else
a = reused_arena ();
a = reused_arena (avoid_arena);
}
#else
if(!a_tsd)