[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commits] r6938 - in /fsf/trunk/libc: ChangeLog malloc/malloc.c
- To: commits@xxxxxxxxxx
- Subject: [commits] r6938 - in /fsf/trunk/libc: ChangeLog malloc/malloc.c
- From: eglibc@xxxxxxxxxx
- Date: Sat, 13 Sep 2008 07:03:00 -0000
Author: eglibc
Date: Sat Sep 13 00:02:59 2008
New Revision: 6938
Log:
Import glibc-mainline for 2008-09-13
Modified:
fsf/trunk/libc/ChangeLog
fsf/trunk/libc/malloc/malloc.c
Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Sat Sep 13 00:02:59 2008
@@ -1,3 +1,10 @@
+2008-09-12 Flavio Leitner <fleitner@xxxxxxxxxx>
+ Ulrich Drepper <drepper@xxxxxxxxxx>
+
+ * malloc/malloc.c (public_vALLOc): Try other arenas in case
+ _int_valloc fails.
+ (public_pVALLOc): Likewise.
+
2008-09-02 Andreas Jaeger <aj@xxxxxxx>
* sysdeps/unix/sysv/linux/s390/s390-32/utmp-convert.h: Fix last
Modified: fsf/trunk/libc/malloc/malloc.c
==============================================================================
--- fsf/trunk/libc/malloc/malloc.c (original)
+++ fsf/trunk/libc/malloc/malloc.c Sat Sep 13 00:02:59 2008
@@ -3800,17 +3800,39 @@
if(__malloc_initialized < 0)
ptmalloc_init ();
+ size_t pagesz = mp_.pagesize;
+
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
__const __malloc_ptr_t)) =
__memalign_hook;
if (hook != NULL)
- return (*hook)(mp_.pagesize, bytes, RETURN_ADDRESS (0));
-
- arena_get(ar_ptr, bytes + mp_.pagesize + MINSIZE);
+ return (*hook)(pagesz, bytes, RETURN_ADDRESS (0));
+
+ arena_get(ar_ptr, bytes + pagesz + MINSIZE);
if(!ar_ptr)
return 0;
p = _int_valloc(ar_ptr, bytes);
(void)mutex_unlock(&ar_ptr->mutex);
+ if(!p) {
+ /* Maybe the failure is due to running out of mmapped areas. */
+ if(ar_ptr != &main_arena) {
+ (void)mutex_lock(&main_arena.mutex);
+ p = _int_memalign(&main_arena, pagesz, bytes);
+ (void)mutex_unlock(&main_arena.mutex);
+ } else {
+#if USE_ARENAS
+ /* ... or sbrk() has failed and there is still a chance to mmap() */
+ ar_ptr = arena_get2(ar_ptr->next ? ar_ptr : 0, bytes);
+ if(ar_ptr) {
+ p = _int_memalign(ar_ptr, pagesz, bytes);
+ (void)mutex_unlock(&ar_ptr->mutex);
+ }
+#endif
+ }
+ }
+ assert(!p || chunk_is_mmapped(mem2chunk(p)) ||
+ ar_ptr == arena_for_chunk(mem2chunk(p)));
+
return p;
}
@@ -3823,17 +3845,40 @@
if(__malloc_initialized < 0)
ptmalloc_init ();
+ size_t pagesz = mp_.pagesize;
+ size_t page_mask = mp_.pagesize - 1;
+ size_t rounded_bytes = (bytes + page_mask) & ~(page_mask);
+
__malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
__const __malloc_ptr_t)) =
__memalign_hook;
if (hook != NULL)
- return (*hook)(mp_.pagesize,
- (bytes + mp_.pagesize - 1) & ~(mp_.pagesize - 1),
- RETURN_ADDRESS (0));
-
- arena_get(ar_ptr, bytes + 2*mp_.pagesize + MINSIZE);
+ return (*hook)(pagesz, rounded_bytes, RETURN_ADDRESS (0));
+
+ arena_get(ar_ptr, bytes + 2*pagesz + MINSIZE);
p = _int_pvalloc(ar_ptr, bytes);
(void)mutex_unlock(&ar_ptr->mutex);
+ if(!p) {
+ /* Maybe the failure is due to running out of mmapped areas. */
+ if(ar_ptr != &main_arena) {
+ (void)mutex_lock(&main_arena.mutex);
+ p = _int_memalign(&main_arena, pagesz, rounded_bytes);
+ (void)mutex_unlock(&main_arena.mutex);
+ } else {
+#if USE_ARENAS
+ /* ... or sbrk() has failed and there is still a chance to mmap() */
+ ar_ptr = arena_get2(ar_ptr->next ? ar_ptr : 0,
+ bytes + 2*pagesz + MINSIZE);
+ if(ar_ptr) {
+ p = _int_memalign(ar_ptr, pagesz, rounded_bytes);
+ (void)mutex_unlock(&ar_ptr->mutex);
+ }
+#endif
+ }
+ }
+ assert(!p || chunk_is_mmapped(mem2chunk(p)) ||
+ ar_ptr == arena_for_chunk(mem2chunk(p)));
+
return p;
}