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.
This commit is contained in:
Jason Evans 2010-01-24 17:56:48 -08:00
parent 68ddb6736d
commit fbbb624fc1

View File

@ -1262,41 +1262,15 @@ JEMALLOC_P(malloc_stats_print)(void (*write4)(void *, const char *,
static void static void
jemalloc_prefork(void) jemalloc_prefork(void)
{ {
bool again; unsigned i;
unsigned i, j;
arena_t *larenas[narenas], *tarenas[narenas];
/* Acquire all mutexes in a safe order. */ /* Acquire all mutexes in a safe order. */
/* malloc_mutex_lock(&arenas_lock);
* arenas_lock must be acquired after all of the arena mutexes, in for (i = 0; i < narenas; i++) {
* order to avoid potential deadlock with arena_lock_balance[_hard](). if (arenas[i] != NULL)
* Since arenas_lock protects the arenas array, the following code has malloc_mutex_lock(&arenas[i]->lock);
* 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(&base_mtx); malloc_mutex_lock(&base_mtx);
@ -1315,7 +1289,6 @@ static void
jemalloc_postfork(void) jemalloc_postfork(void)
{ {
unsigned i; unsigned i;
arena_t *larenas[narenas];
/* Release all mutexes, now that fork() has completed. */ /* Release all mutexes, now that fork() has completed. */
@ -1331,10 +1304,9 @@ jemalloc_postfork(void)
malloc_mutex_unlock(&base_mtx); malloc_mutex_unlock(&base_mtx);
memcpy(larenas, arenas, sizeof(arena_t *) * narenas);
malloc_mutex_unlock(&arenas_lock);
for (i = 0; i < narenas; i++) { for (i = 0; i < narenas; i++) {
if (larenas[i] != NULL) if (arenas[i] != NULL)
malloc_mutex_unlock(&larenas[i]->lock); malloc_mutex_unlock(&arenas[i]->lock);
} }
malloc_mutex_unlock(&arenas_lock);
} }