diff options
author | Jason Evans <jasone@canonware.com> | 2014-10-08 06:14:57 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2014-10-08 06:14:57 (GMT) |
commit | 8bb3198f72fc7587dc93527f9f19fb5be52fa553 (patch) | |
tree | 5a530b077511daf9afe60be7280907937924f52f /src/tcache.c | |
parent | bf40641c5c9496d2912ad9ff2c38ee9ce2bfbde6 (diff) | |
download | jemalloc-8bb3198f72fc7587dc93527f9f19fb5be52fa553.zip jemalloc-8bb3198f72fc7587dc93527f9f19fb5be52fa553.tar.gz jemalloc-8bb3198f72fc7587dc93527f9f19fb5be52fa553.tar.bz2 |
Refactor/fix arenas manipulation.
Abstract arenas access to use arena_get() (or a0get() where appropriate)
rather than directly reading e.g. arenas[ind]. Prior to the addition of
the arenas.extend mallctl, the worst possible outcome of directly
accessing arenas was a stale read, but arenas.extend may allocate and
assign a new array to arenas.
Add a tsd-based arenas_cache, which amortizes arenas reads. This
introduces some subtle bootstrapping issues, with tsd_boot() now being
split into tsd_boot[01]() to support tsd wrapper allocation
bootstrapping, as well as an arenas_cache_bypass tsd variable which
dynamically terminates allocation of arenas_cache itself.
Promote a0malloc(), a0calloc(), and a0free() to be generally useful for
internal allocation, and use them in several places (more may be
appropriate).
Abstract arena->nthreads management and fix a missing decrement during
thread destruction (recent tsd refactoring left arenas_cleanup()
unused).
Change arena_choose() to propagate OOM, and handle OOM in all callers.
This is important for providing consistent allocation behavior when the
MALLOCX_ARENA() flag is being used. Prior to this fix, it was possible
for an OOM to result in allocation silently allocating from a different
arena than the one specified.
Diffstat (limited to 'src/tcache.c')
-rw-r--r-- | src/tcache.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/tcache.c b/src/tcache.c index 2c968c6..1bf7026 100644 --- a/src/tcache.c +++ b/src/tcache.c @@ -246,6 +246,14 @@ tcache_arena_associate(tcache_t *tcache, arena_t *arena) } void +tcache_arena_reassociate(tcache_t *tcache, arena_t *arena) +{ + + tcache_arena_dissociate(tcache); + tcache_arena_associate(tcache, arena); +} + +void tcache_arena_dissociate(tcache_t *tcache) { @@ -261,13 +269,17 @@ tcache_arena_dissociate(tcache_t *tcache) tcache_t * tcache_get_hard(tsd_t *tsd) { + arena_t *arena; if (!tcache_enabled_get()) { if (tsd_nominal(tsd)) tcache_enabled_set(false); /* Memoize. */ return (NULL); } - return (tcache_create(choose_arena(tsd, NULL))); + arena = arena_choose(tsd, NULL); + if (unlikely(arena == NULL)) + return (NULL); + return (tcache_create(arena)); } tcache_t * |