This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 1/2] Consolidate heap in memalign when alignment is large.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Thu, 7 Nov 2013 21:50:00 +0100
- Subject: [PATCH 1/2] Consolidate heap in memalign when alignment is large.
- Authentication-results: sourceware.org; auth=none
Hi,
I looked how deduplicate malloc code. Funcions valloc/pvalloc should be
implemented by calling memalign, only difference is that they call heap
consolidation.
If consolidation is useful then memalign would benefit when user passes
page size alignments. Otherwise we should delete consolidation from
valloc.
Which alternative is better?
* malloc/malloc.c (__libc_memalign): Call heap consolidation
when alignment is multiple of page size.
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 897c43a..29a5488 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3005,6 +3005,9 @@ __libc_memalign(size_t alignment, size_t bytes)
mstate ar_ptr;
void *p;
+ if(__malloc_initialized < 0)
+ ptmalloc_init();
+
void *(*hook) (size_t, size_t, const void *) =
force_reg (__memalign_hook);
if (__builtin_expect (hook != NULL, 0))
@@ -3034,6 +3037,9 @@ __libc_memalign(size_t alignment, size_t bytes)
arena_get(ar_ptr, bytes + alignment + MINSIZE);
if(!ar_ptr)
return 0;
+
+ if (have_fastchunks(ar_ptr) && alignment >= GLRO(dl_pagesize))
+ malloc_consolidate(av);
p = _int_memalign(ar_ptr, alignment, bytes);
if(!p) {
LIBC_PROBE (memory_memalign_retry, 2, bytes, alignment);