summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2019-09-09 14:35:06 +0300
committerantirez <antirez@gmail.com>2019-11-19 17:37:21 +0100
commit9f63fc98df63a842d64db8887e6f23b48746691a (patch)
treea7d7ef018dfb90af186f02c93e89c305e46900ba
parent1a9e70c1d75c1bd7f29d659ef2b63a819bf5032a (diff)
downloadredis-9f63fc98df63a842d64db8887e6f23b48746691a.tar.gz
RED-31295 - redis: avoid race between dlopen and thread creation
It seeems that since I added the creation of the jemalloc thread redis sometimes fails to start with the following error: Inconsistency detected by ld.so: dl-tls.c: 493: _dl_allocate_tls_init: Assertion `listp->slotinfo[cnt].gen <= GL(dl_tls_generation)' failed! This seems to be due to a race bug in ld.so, in which TLS creation on the thread, collide with dlopen. Move the creation of BIO and jemalloc threads to after modules are loaded. plus small bugfix when trying to disable the jemalloc thread at runtime
-rw-r--r--src/server.c10
-rw-r--r--src/zmalloc.c7
2 files changed, 17 insertions, 0 deletions
diff --git a/src/server.c b/src/server.c
index 6aeb5aa9a..280470f63 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2196,6 +2196,14 @@ void initServer(void) {
scriptingInit(1);
slowlogInit();
latencyMonitorInit();
+}
+
+/* Some steps in server initialization need to be done last (after modules
+ * are loaded).
+ * Specifically, creation of threads due to a race bug in ld.so, in which
+ * Thread Local Storage initialization collides with dlopen call.
+ * see: https://sourceware.org/bugzilla/show_bug.cgi?id=19329 */
+void InitServerLast() {
bioInit();
server.initial_memory_usage = zmalloc_used_memory();
}
@@ -4197,6 +4205,7 @@ int main(int argc, char **argv) {
linuxMemoryWarnings();
#endif
moduleLoadFromQueue();
+ InitServerLast();
loadDataFromDisk();
if (server.cluster_enabled) {
if (verifyClusterConfigWithData() == C_ERR) {
@@ -4211,6 +4220,7 @@ int main(int argc, char **argv) {
if (server.sofd > 0)
serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
} else {
+ InitServerLast();
sentinelIsRunning();
}
diff --git a/src/zmalloc.c b/src/zmalloc.c
index 2482f512b..dd655620c 100644
--- a/src/zmalloc.c
+++ b/src/zmalloc.c
@@ -323,6 +323,13 @@ int zmalloc_get_allocator_info(size_t *allocated,
je_mallctl("stats.allocated", allocated, &sz, NULL, 0);
return 1;
}
+
+void set_jemalloc_bg_thread(int enable) {
+ /* let jemalloc do purging asynchronously, required when there's no traffic
+ * after flushdb */
+ char val = !!enable;
+ je_mallctl("background_thread", NULL, 0, &val, 1);
+}
#else
int zmalloc_get_allocator_info(size_t *allocated,
size_t *active,