Skip to content

Commit

Permalink
Jemalloc: Avoid blocking on background thread lock for stats.
Browse files Browse the repository at this point in the history
Background threads may run for a long time, especially when the # of dirty pages
is high.  Avoid blocking stats calls because of this (which may cause latency
spikes).

see jemalloc/jemalloc#1502

cherry picked from commit 1a71533511027dbe3f9d989659efeec446915d6b
  • Loading branch information
oranagra committed Jun 2, 2019
1 parent fd0ee46 commit 2fec7d9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion deps/jemalloc/src/background_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,13 @@ background_thread_stats_read(tsdn_t *tsdn, background_thread_stats_t *stats) {
nstime_init(&stats->run_interval, 0);
for (unsigned i = 0; i < max_background_threads; i++) {
background_thread_info_t *info = &background_thread_info[i];
malloc_mutex_lock(tsdn, &info->mtx);
if (malloc_mutex_trylock(tsdn, &info->mtx)) {
/*
* Each background thread run may take a long time;
* avoid waiting on the stats if the thread is active.
*/
continue;
}
if (info->state != background_thread_stopped) {
num_runs += info->tot_n_runs;
nstime_add(&stats->run_interval, &info->tot_sleep_time);
Expand Down

0 comments on commit 2fec7d9

Please sign in to comment.