mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 21:23:06 +00:00
Fix fork-related bugs.
Acquire/release arena bin locks as part of the prefork/postfork. This
bug made deadlock in the child between fork and exec a possibility.
Split jemalloc_postfork() into jemalloc_postfork_{parent,child}() so
that the child can reinitialize mutexes rather than unlocking them. In
practice, this bug tended not to cause problems.
This commit is contained in:
30
src/arena.c
30
src/arena.c
@@ -2169,3 +2169,33 @@ arena_boot(void)
|
||||
|
||||
bin_info_init();
|
||||
}
|
||||
|
||||
void
|
||||
arena_prefork(arena_t *arena)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
malloc_mutex_prefork(&arena->lock);
|
||||
for (i = 0; i < NBINS; i++)
|
||||
malloc_mutex_prefork(&arena->bins[i].lock);
|
||||
}
|
||||
|
||||
void
|
||||
arena_postfork_parent(arena_t *arena)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < NBINS; i++)
|
||||
malloc_mutex_postfork_parent(&arena->bins[i].lock);
|
||||
malloc_mutex_postfork_parent(&arena->lock);
|
||||
}
|
||||
|
||||
void
|
||||
arena_postfork_child(arena_t *arena)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < NBINS; i++)
|
||||
malloc_mutex_postfork_child(&arena->bins[i].lock);
|
||||
malloc_mutex_postfork_child(&arena->lock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user