gecko/memory/jemalloc/0005-Bug-1121314-Avoid-needing-the-arena-in-chunk_alloc_d.patch
Mike Hommey beac51295d Bug 1121314 - Avoid needing the arena in chunk_alloc_default to avoid possible infinite loops involving a0malloc. r=njn
The infinite loop happens if chunk_alloc_arena needs to be called when a0malloc
is called. It in turn calls chunk_alloc_default, which uses tsd, which calls
a0malloc if it's the first time the tsd is being gotten from the current thread.
tsd only uses a0malloc on platforms where there is no native thread local storage
support, which, for Mozilla, essentially means anything that is not Linux.

But the tsd is only neededto get the dss precedence setting of the given arena.
That setting has no effect when dss is disabled, which it is on Windows and Mac.

Moreover, the default setting for dss precedence is "secondary", which means
jemalloc only tries dss after it failed to get memory with mmap/VirtualAlloc.
Considering the cases where mmap/VirtualAlloc would fail essentially means
there is shortage of address space, sbrk() is not going to have much more
success, so we might as well disable dss support on all platforms, avoiding
the infinite loop problem on Android and B2G as well.
2015-01-14 15:18:49 +09:00

59 lines
1.6 KiB
Diff

From 722400adde3b4cb307fdc310e6296e10e6ace7ae Mon Sep 17 00:00:00 2001
From: Mike Hommey <mh+mozilla@glandium.org>
Date: Wed, 14 Jan 2015 12:49:24 +0900
Subject: [PATCH] Bug 1121314 - Avoid needing the arena in chunk_alloc_default
to avoid possible infinite loops involving a0malloc
---
src/chunk.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/chunk.c b/src/chunk.c
index 7926452..32e659c 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -247,27 +247,32 @@ chunk_alloc_arena(chunk_alloc_t *chunk_alloc, chunk_dalloc_t *chunk_dalloc,
return (ret);
}
/* Default arena chunk allocation routine in the absence of user override. */
void *
chunk_alloc_default(void *new_addr, size_t size, size_t alignment, bool *zero,
unsigned arena_ind)
{
- arena_t *arena;
+ dss_prec_t dss_prec = dss_prec_disabled;
- arena = arena_get(tsd_fetch(), arena_ind, false, true);
- /*
- * The arena we're allocating on behalf of must have been initialized
- * already.
- */
- assert(arena != NULL);
+ if (have_dss) {
+ arena_t *arena;
+
+ arena = arena_get(tsd_fetch(), arena_ind, false, true);
+ /*
+ * The arena we're allocating on behalf of must have been
+ * initialized already.
+ */
+ assert(arena != NULL);
+ dss_prec = arena->dss_prec;
+ }
return (chunk_alloc_core(new_addr, size, alignment, false, zero,
- arena->dss_prec));
+ dss_prec));
}
static void
chunk_record(extent_tree_t *chunks_szad, extent_tree_t *chunks_ad, void *chunk,
size_t size)
{
bool unzeroed;
extent_node_t *xnode, *node, *prev, *xprev, key;
--
2.2.1.dirty