summaryrefslogtreecommitdiff
path: root/deps/jemalloc/src/mutex.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2023-05-01 15:38:08 +0300
committerOran Agra <oran@redislabs.com>2023-05-01 15:38:08 +0300
commitb8beda3cf8e5c8218fbe84539d6b5117b3f909d9 (patch)
tree66934c98c93ac48f6ca912ad547e651221e525d2 /deps/jemalloc/src/mutex.c
parentd659c734569be4ed32a270bac2527ccf35418c43 (diff)
parent6d23d3ac3b3f9d13ad2ce99029e69a9ea9f2e517 (diff)
downloadredis-b8beda3cf8e5c8218fbe84539d6b5117b3f909d9.tar.gz
Merge commit jemalloc 5.3.0
Diffstat (limited to 'deps/jemalloc/src/mutex.c')
-rw-r--r--deps/jemalloc/src/mutex.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/deps/jemalloc/src/mutex.c b/deps/jemalloc/src/mutex.c
index 3f920f5b1..0b3547a87 100644
--- a/deps/jemalloc/src/mutex.c
+++ b/deps/jemalloc/src/mutex.c
@@ -1,4 +1,3 @@
-#define JEMALLOC_MUTEX_C_
#include "jemalloc/internal/jemalloc_preamble.h"
#include "jemalloc/internal/jemalloc_internal_includes.h"
@@ -10,6 +9,12 @@
#define _CRT_SPINCOUNT 4000
#endif
+/*
+ * Based on benchmark results, a fixed spin with this amount of retries works
+ * well for our critical sections.
+ */
+int64_t opt_mutex_max_spin = 600;
+
/******************************************************************************/
/* Data. */
@@ -46,13 +51,13 @@ JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
void
malloc_mutex_lock_slow(malloc_mutex_t *mutex) {
mutex_prof_data_t *data = &mutex->prof_data;
- nstime_t before = NSTIME_ZERO_INITIALIZER;
+ nstime_t before;
if (ncpus == 1) {
goto label_spin_done;
}
- int cnt = 0, max_cnt = MALLOC_MUTEX_MAX_SPIN;
+ int cnt = 0;
do {
spin_cpu_spinwait();
if (!atomic_load_b(&mutex->locked, ATOMIC_RELAXED)
@@ -60,7 +65,7 @@ malloc_mutex_lock_slow(malloc_mutex_t *mutex) {
data->n_spin_acquired++;
return;
}
- } while (cnt++ < max_cnt);
+ } while (cnt++ < opt_mutex_max_spin || opt_mutex_max_spin == -1);
if (!config_stats) {
/* Only spin is useful when stats is off. */
@@ -68,7 +73,7 @@ malloc_mutex_lock_slow(malloc_mutex_t *mutex) {
return;
}
label_spin_done:
- nstime_update(&before);
+ nstime_init_update(&before);
/* Copy before to after to avoid clock skews. */
nstime_t after;
nstime_copy(&after, &before);
@@ -104,8 +109,8 @@ label_spin_done:
static void
mutex_prof_data_init(mutex_prof_data_t *data) {
memset(data, 0, sizeof(mutex_prof_data_t));
- nstime_init(&data->max_wait_time, 0);
- nstime_init(&data->tot_wait_time, 0);
+ nstime_init_zero(&data->max_wait_time);
+ nstime_init_zero(&data->tot_wait_time);
data->prev_owner = NULL;
}