Repository navigation
Bug fix for prof_active switch - #1604
Conversation
|
While working on fixing this bug, I was thinking: an important reason why this bug was not identified earlier was the lack of test coverage, in two aspects:
|
The bug is subtle but critical: if application performs the following three actions in sequence: (a) turn `prof_active` off, (b) make at least one allocation that triggers the malloc slow path via the `if (unlikely(bytes_until_sample < 0))` path, and (c) turn `prof_active` back on, then the application would never get another sample (until a very very long time later). The fix is to properly reset `bytes_until_sample` rather than throwing it all the way to `SSIZE_MAX`. A side minor change is to call `prof_active_get_unlocked()` rather than directly grabbing the `prof_active` variable - it is the very reason why we defined the `prof_active_get_unlocked()` function.
02a362d to
8d0a97a
Compare
|
I'm now resetting One other minor remark is that I'm directly resetting via The only difference is that the reset is not randomized, but we probably don't need that anyway when |
This depends on tikv/jemalloc#2 , which is a cherry-pick of jemalloc/jemalloc#1604 . See jemalloc/jemalloc#1605 for details of the bug that this fixes; basically, it makes profiling/sampling fail to work under some conditions. We hit this in practice at Materialize when attempting to switch to tikv/jemallocator. Signed-off-by: Brennan Vincent <[email protected]>
The bug is subtle but critical: if application performs the following
three actions in sequence: (a) turn
prof_activeoff, (b) make atleast one allocation that triggers the malloc slow path via the
if (unlikely(bytes_until_sample < 0))path, and (c) turnprof_activeback on, then the application would never get anothersample (until a very very long time later).
The fix is to properly reset
bytes_until_samplerather thanthrowing it all the way to
SSIZE_MAX.A side minor change is to call
prof_active_get_unlocked()ratherthan directly grabbing the
prof_activevariable - it is the veryreason why we defined the
prof_active_get_unlocked()function.