+2013-12-10 Ondřej Bílka <neleai@seznam.cz>
+
+ * malloc/Makefile (CPPFLAGS-malloc.c): Remove -DPER_THREAD flag.
+ * malloc/arena.c: Remove PER_THREAD conditional.
+ [!PER_THREAD]: Remove code.
+ (ptmalloc_unlock_all2): Likewise.
+ (ptmalloc_init): Likewise.
+ (_int_new_arena): Likewise.
+ (arena_get2): Likewise.
+ * malloc/hooks.c (__malloc_get_state): Likewise.
+ (__malloc_set_state): Likewise.
+ * malloc/malloc.c: Likewise.
+ (struct malloc_state): Likewise.
+ (struct malloc_par): Likewise.
+ (__libc_realloc): Likewise.
+ (__libc_mallopt): Likewise.
+
2013-12-09 Adhemerval Zanella <azanella@linux.vnet.ibm.com>
* Versions.def (libm): Add GLIBC_2.3 and GLIBC_2.19.
static tsd_key_t arena_key;
static mutex_t list_lock = MUTEX_INITIALIZER;
-#ifdef PER_THREAD
static size_t narenas = 1;
static mstate free_list;
-#endif
#if THREAD_STATS
static int stat_n_heaps;
ptr = (mstate)tsd_getspecific(arena_key, vptr); \
} while(0)
-#ifdef PER_THREAD
# define arena_lock(ptr, size) do { \
if(ptr) \
(void)mutex_lock(&ptr->mutex); \
else \
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), NULL); \
-} while(0)
-#endif
/* find the heap and corresponding arena for a given ptr */
tsd_setspecific(arena_key, save_arena);
__malloc_hook = save_malloc_hook;
__free_hook = save_free_hook;
-#ifdef PER_THREAD
free_list = NULL;
-#endif
for(ar_ptr = &main_arena;;) {
mutex_init(&ar_ptr->mutex);
-#ifdef PER_THREAD
if (ar_ptr != save_arena) {
ar_ptr->next_free = free_list;
free_list = ar_ptr;
}
-#endif
ar_ptr = ar_ptr->next;
if(ar_ptr == &main_arena) break;
}
{
if (memcmp (envline, "MMAP_MAX_", 9) == 0)
__libc_mallopt(M_MMAP_MAX, atoi(&envline[10]));
-#ifdef PER_THREAD
else if (memcmp (envline, "ARENA_MAX", 9) == 0)
__libc_mallopt(M_ARENA_MAX, atoi(&envline[10]));
-#endif
}
break;
-#ifdef PER_THREAD
case 10:
if (! __builtin_expect (__libc_enable_secure, 0))
{
__libc_mallopt(M_ARENA_TEST, atoi(&envline[11]));
}
break;
-#endif
case 15:
if (! __builtin_expect (__libc_enable_secure, 0))
{
mutex_init(&a->mutex);
(void)mutex_lock(&a->mutex);
-#ifdef PER_THREAD
(void)mutex_lock(&list_lock);
-#endif
/* Add the new arena to the global list. */
a->next = main_arena.next;
atomic_write_barrier ();
main_arena.next = a;
-#ifdef PER_THREAD
(void)mutex_unlock(&list_lock);
-#endif
THREAD_STAT(++(a->stat_lock_loop));
}
-#ifdef PER_THREAD
static mstate
get_free_list (void)
{
return result;
}
-#endif
static mstate
internal_function
{
mstate a;
-#ifdef PER_THREAD
static size_t narenas_limit;
a = get_free_list ();
else
a = reused_arena (avoid_arena);
}
-#else
- if(!a_tsd)
- a = a_tsd = &main_arena;
- else {
- a = a_tsd->next;
- if(!a) {
- /* This can only happen while initializing the new arena. */
- (void)mutex_lock(&main_arena.mutex);
- THREAD_STAT(++(main_arena.stat_lock_wait));
- return &main_arena;
- }
- }
-
- /* Check the global, circularly linked list for available arenas. */
- bool retried = false;
- repeat:
- do {
- if(!mutex_trylock(&a->mutex)) {
- if (retried)
- (void)mutex_unlock(&list_lock);
- THREAD_STAT(++(a->stat_lock_loop));
- LIBC_PROBE (memory_arena_reuse, 2, a, a_tsd);
- tsd_setspecific(arena_key, (void *)a);
- return a;
- }
- a = a->next;
- } while(a != a_tsd);
-
- /* If not even the list_lock can be obtained, try again. This can
- happen during `atfork', or for example on systems where thread
- creation makes it temporarily impossible to obtain _any_
- locks. */
- if(!retried && mutex_trylock(&list_lock)) {
- /* We will block to not run in a busy loop. */
- LIBC_PROBE (memory_arena_reuse_wait, 3, &list_lock, NULL, a_tsd);
- (void)mutex_lock(&list_lock);
-
- /* Since we blocked there might be an arena available now. */
- retried = true;
- a = a_tsd;
- goto repeat;
- }
-
- /* Nothing immediately available, so generate a new arena. */
- a = _int_new_arena(size);
- (void)mutex_unlock(&list_lock);
-#endif
-
return a;
}
return ar_ptr;
}
-#ifdef PER_THREAD
static void __attribute__ ((section ("__libc_thread_freeres_fn")))
arena_thread_freeres (void)
{
}
}
text_set_element (__libc_thread_subfreeres, arena_thread_freeres);
-#endif
/*
* Local variables:
/* Linked list */
struct malloc_state *next;
-#ifdef PER_THREAD
/* Linked list for free arenas. */
struct malloc_state *next_free;
-#endif
/* Memory allocated from the system in this arena. */
INTERNAL_SIZE_T system_mem;
unsigned long trim_threshold;
INTERNAL_SIZE_T top_pad;
INTERNAL_SIZE_T mmap_threshold;
-#ifdef PER_THREAD
INTERNAL_SIZE_T arena_test;
INTERNAL_SIZE_T arena_max;
-#endif
/* Memory map support */
int n_mmaps;
.n_mmaps_max = DEFAULT_MMAP_MAX,
.mmap_threshold = DEFAULT_MMAP_THRESHOLD,
.trim_threshold = DEFAULT_TRIM_THRESHOLD,
-#ifdef PER_THREAD
# define NARENAS_FROM_NCORES(n) ((n) * (sizeof(long) == 4 ? 2 : 8))
.arena_test = NARENAS_FROM_NCORES (1)
-#endif
};
-#ifdef PER_THREAD
/* Non public mallopt parameters. */
#define M_ARENA_TEST -7
#define M_ARENA_MAX -8
-#endif
/* Maximum size of memory handled in fastbins. */
(void)mutex_lock(&ar_ptr->mutex);
#endif
-#if !defined PER_THREAD
- LIBC_PROBE (memory_arena_reuse_realloc, 1, ar_ptr);
- /* As in malloc(), remember this arena for the next allocation. */
- tsd_setspecific(arena_key, (void *)ar_ptr);
-#endif
newp = _int_realloc(ar_ptr, oldp, oldsize, nb);
perturb_byte = value;
break;
-#ifdef PER_THREAD
case M_ARENA_TEST:
if (value > 0)
{
mp_.arena_max = value;
}
break;
-#endif
}
(void)mutex_unlock(&av->mutex);
return res;