diff options
author | Jason Evans <jasone@canonware.com> | 2010-01-25 01:56:48 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2010-01-25 01:56:48 (GMT) |
commit | fbbb624fc1972f4187b7c04faaebf5b47218025f (patch) | |
tree | ddf918b70f39867706593efe5cdcf22e20e28d00 /jemalloc | |
parent | 68ddb6736db319f6714547f2828777399595657e (diff) | |
download | jemalloc-fbbb624fc1972f4187b7c04faaebf5b47218025f.zip jemalloc-fbbb624fc1972f4187b7c04faaebf5b47218025f.tar.gz jemalloc-fbbb624fc1972f4187b7c04faaebf5b47218025f.tar.bz2 |
Simplify malloc_{pre,post}fork().
Revert to simpler lock acquistion/release code in
malloc_{pre,post}fork(), since dynamic arena rebalancing is no longer
implemented.
Diffstat (limited to 'jemalloc')
-rw-r--r-- | jemalloc/src/jemalloc.c | 46 |
1 files changed, 9 insertions, 37 deletions
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c index a6e9793..a18a157 100644 --- a/jemalloc/src/jemalloc.c +++ b/jemalloc/src/jemalloc.c @@ -1262,41 +1262,15 @@ JEMALLOC_P(malloc_stats_print)(void (*write4)(void *, const char *, static void jemalloc_prefork(void) { - bool again; - unsigned i, j; - arena_t *larenas[narenas], *tarenas[narenas]; + unsigned i; /* Acquire all mutexes in a safe order. */ - /* - * arenas_lock must be acquired after all of the arena mutexes, in - * order to avoid potential deadlock with arena_lock_balance[_hard](). - * Since arenas_lock protects the arenas array, the following code has - * to race with arenas_extend() callers until it succeeds in locking - * all arenas before locking arenas_lock. - */ - memset(larenas, 0, sizeof(arena_t *) * narenas); - do { - again = false; - - malloc_mutex_lock(&arenas_lock); - for (i = 0; i < narenas; i++) { - if (arenas[i] != larenas[i]) { - memcpy(tarenas, arenas, sizeof(arena_t *) * - narenas); - malloc_mutex_unlock(&arenas_lock); - for (j = 0; j < narenas; j++) { - if (larenas[j] != tarenas[j]) { - larenas[j] = tarenas[j]; - malloc_mutex_lock( - &larenas[j]->lock); - } - } - again = true; - break; - } - } - } while (again); + malloc_mutex_lock(&arenas_lock); + for (i = 0; i < narenas; i++) { + if (arenas[i] != NULL) + malloc_mutex_lock(&arenas[i]->lock); + } malloc_mutex_lock(&base_mtx); @@ -1315,7 +1289,6 @@ static void jemalloc_postfork(void) { unsigned i; - arena_t *larenas[narenas]; /* Release all mutexes, now that fork() has completed. */ @@ -1331,10 +1304,9 @@ jemalloc_postfork(void) malloc_mutex_unlock(&base_mtx); - memcpy(larenas, arenas, sizeof(arena_t *) * narenas); - malloc_mutex_unlock(&arenas_lock); for (i = 0; i < narenas; i++) { - if (larenas[i] != NULL) - malloc_mutex_unlock(&larenas[i]->lock); + if (arenas[i] != NULL) + malloc_mutex_unlock(&arenas[i]->lock); } + malloc_mutex_unlock(&arenas_lock); } |