Closed
Bug 985759
Opened 12 years ago
Closed 12 years ago
It should be possible to turn jemalloc on and off dynamically
Categories
(Core :: Memory Allocator, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: smichaud, Unassigned)
Details
This is spun off from bug 984447, which concerns crashes/hangs that happen as a result of a bad interaction between jemalloc and the Java plugin.
The specific problem is that the Java plugin calls fork() on a secondary thread, and that this often results in a hang in the call to fork() -- on the child process side in jemalloc code, and on the parent side waiting for the call to fork() to finish. For more information see bug 984447 comment #35.
One workaround would be to use pthread_atfork() to turn jemalloc off before the call to fork, then turn it on again on the parent side. Allocations made during the call to fork() would then (presumably) be made using the "original" malloc code.
We should in principle be able to do this by turning osx_use_jemalloc on and off in the following code:
http://hg.mozilla.org/mozilla-central/annotate/e84a391b604b/memory/mozjemalloc/jemalloc.c#l6173
But I tried this and it doesn't work: There is at least one kind of crash.
I'm unlikely ever to have time to do more work on this myself. But I think it's a task worth doing -- especially since the existing code indicates that some effort has already been spent on it. So I'm opening this bug.
You should figure out why we don't do the pthread_atfork handling on Darwin.
http://hg.mozilla.org/mozilla-central/annotate/e84a391b604b/memory/mozjemalloc/jemalloc.c#l5902
| Reporter | ||
Comment 2•12 years ago
|
||
I know we don't, but that doesn't matter.
If I just comment out those defines, we *always* hang (at fork()) with the testcase for bug 984447. Which isn't surprising, since _malloc_prefork locks all the arena locks.
But even the following doesn't work (leads to crashes):
static void
turn_off_jemalloc(void)
{
osx_use_jemalloc = false;
}
static void
turn_off_jemalloc(void)
{
osx_use_jemalloc = true;
}
pthread_atfork(turn_off_jemalloc, turn_on_jemalloc, NULL);
And setting osx_use_jemalloc to false here also crashes very quickly:
http://hg.mozilla.org/mozilla-central/annotate/e84a391b604b/memory/mozjemalloc/jemalloc.c#l6146
osx_use_jemalloc just doesn't work as is appears it should.
Well once you switch allocators you've basically guaranteed you'll have an allocator mismatch at some point, which should crash us, right?
| Reporter | ||
Comment 4•12 years ago
|
||
I don't know the jemalloc code well. But it does seem (from the code comments) that the original intention was to make it possible to turn it off and on dynamically.
| Reporter | ||
Comment 5•12 years ago
|
||
At least on OS X.
| Reporter | ||
Comment 6•12 years ago
|
||
Using things like the DARWIN_ONLY() macro.
Comment 7•12 years ago
|
||
What you really want is to fix whatever makes fork dead-lock. Not work around it in weird ways.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•