summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQi Wang <interwq@gwu.edu>2019-05-22 17:21:53 (GMT)
committerQi Wang <interwq@gmail.com>2019-05-22 21:28:38 (GMT)
commit1a71533511027dbe3f9d989659efeec446915d6b (patch)
treea072d2e089fce62bd41bc46c84a95e8273f808f6
parente13cf65a5f37bbd9b44badb198ccc138cbacc219 (diff)
downloadjemalloc-1a71533511027dbe3f9d989659efeec446915d6b.zip
jemalloc-1a71533511027dbe3f9d989659efeec446915d6b.tar.gz
jemalloc-1a71533511027dbe3f9d989659efeec446915d6b.tar.bz2
Avoid blocking on background thread lock for stats.
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).
-rw-r--r--src/background_thread.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/background_thread.c b/src/background_thread.c
index 5ed6c1c..57b9b25 100644
--- a/src/background_thread.c
+++ b/src/background_thread.c
@@ -799,7 +799,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);