This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PING][PATCH 2/*] Expand arena_get macro.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Mon, 30 Dec 2013 16:21:35 +0100
- Subject: [PING][PATCH 2/*] Expand arena_get macro.
- Authentication-results: sourceware.org; auth=none
- References: <20131211102701 dot GA25483 at domone dot podge> <20131211113916 dot GA26438 at domone dot podge>
ping
On Wed, Dec 11, 2013 at 12:39:16PM +0100, OndÅej BÃlka wrote:
> Hi,
>
> For thread local caches we would need to distinguish arena data from
> thread data. As this access was hidden in arena_get macro we expand it.
>
> This also could allow more simplification, is a check if arena is null
> now needeed?
>
> Ok to commit?
>
> * malloc/arena.c (arena_get, arena_lookup, arena_lock): Delete.
> * malloc/malloc.c (__libc_malloc, _mid_memalign, __libc_calloc):
> Expand arena_get to its body.
>
>
> >From 9b800422414f8dac2e98a23633715ff66042dce8 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Ond=C5=99ej=20B=C3=ADlka?= <neleai@seznam.cz>
> Date: Wed, 11 Dec 2013 11:50:33 +0100
> Subject: [PATCH] expand arena
>
> ---
> malloc/arena.c | 26 --------------------------
> malloc/malloc.c | 25 +++++++++++++++++++++----
> 2 files changed, 21 insertions(+), 30 deletions(-)
>
> diff --git a/malloc/arena.c b/malloc/arena.c
> index 850c503..6c31445 100644
> --- a/malloc/arena.c
> +++ b/malloc/arena.c
> @@ -94,32 +94,6 @@ int __malloc_initialized = -1;
>
> /**************************************************************************/
>
> -
> -/* arena_get() acquires an arena and locks the corresponding mutex.
> - First, try the one last locked successfully by this thread. (This
> - is the common case and handled with a macro for speed.) Then, loop
> - once over the circularly linked list of arenas. If no arena is
> - readily available, create a new one. In this latter case, `size'
> - is just a hint as to how much memory will be required immediately
> - in the new arena. */
> -
> -#define arena_get(ptr, size) do { \
> - arena_lookup (ptr); \
> - arena_lock (ptr, size); \
> - } while (0)
> -
> -#define arena_lookup(ptr) do { \
> - void *vptr = NULL; \
> - ptr = (mstate) tsd_getspecific (arena_key, vptr); \
> - } while (0)
> -
> -#define arena_lock(ptr, size) do { \
> - if (ptr) \
> - (void) mutex_lock (&ptr->mutex); \
> - else \
> - ptr = arena_get2 (ptr, (size), NULL); \
> - } while (0)
> -
> /* find the heap and corresponding arena for a given ptr */
>
> #define heap_for_ptr(ptr) \
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index d0f85a7..9611498 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -2879,9 +2879,13 @@ __libc_malloc (size_t bytes)
> if (__builtin_expect (hook != NULL, 0))
> return (*hook)(bytes, RETURN_ADDRESS (0));
>
> - arena_lookup (ar_ptr);
> + void *vptr = NULL;
> + ar_ptr = (mstate) tsd_getspecific (arena_key, vptr);
> + if (ar_ptr)
> + (void) mutex_lock (&ar_ptr->mutex);
> + else
> + ar_ptr = arena_get2 (NULL, bytes, NULL);
>
> - arena_lock (ar_ptr, bytes);
> if (!ar_ptr)
> return 0;
>
> @@ -3096,7 +3100,14 @@ _mid_memalign (size_t alignment, size_t bytes, void *address)
> alignment = a;
> }
>
> - arena_get (ar_ptr, bytes + alignment + MINSIZE);
> + void *vptr = NULL;
> + ar_ptr = (mstate) tsd_getspecific (arena_key, vptr);
> + if (ar_ptr)
> + (void) mutex_lock (&ar_ptr->mutex);
> + else
> + ar_ptr = arena_get2 (NULL, bytes + alignment + MINSIZE, NULL);
> +
> +
> if (!ar_ptr)
> return 0;
>
> @@ -3191,7 +3202,13 @@ __libc_calloc (size_t n, size_t elem_size)
>
> sz = bytes;
>
> - arena_get (av, sz);
> + void *vptr = NULL;
> + av = (mstate) tsd_getspecific (av, vptr);
> + if (av)
> + (void) mutex_lock (&av->mutex);
> + else
> + av = arena_get2 (NULL, sz, NULL);
> +
> if (!av)
> return 0;
>
> --
> 1.8.4.rc3
>
--
Communist revolutionaries taking over the server room and demanding all the computers in the building or they shoot the sysadmin. Poor misguided fools.