From 71f2e61282c117307d0c02b43f3dc7e06f43e88c Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Sun, 5 Dec 2021 07:41:43 +0530 Subject: [PATCH] Remove jemalloc usage check. This change also removes usage of dlsym, whose API seems to have changed in recent glibc version, so breaking Typesense on newer Ubuntu/Fedora: https://stackoverflow.com/a/18825060/131050 --- src/typesense_server_utils.cpp | 35 +++++++--------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/typesense_server_utils.cpp b/src/typesense_server_utils.cpp index 0eaedd60..94ae8c23 100644 --- a/src/typesense_server_utils.cpp +++ b/src/typesense_server_utils.cpp @@ -24,21 +24,6 @@ HttpServer* server; std::atomic quit_raft_service; -extern "C" { - typedef int (*mallctl_t)(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen); -} - -bool using_jemalloc() { - // On OSX, jemalloc API is prefixed with "je_" - mallctl_t mallctl; -#ifdef __APPLE__ - mallctl = (mallctl_t) ::dlsym(RTLD_DEFAULT, "je_mallctl"); -#else - mallctl = (mallctl_t) ::dlsym(RTLD_DEFAULT, "mallctl"); -#endif - return (mallctl != nullptr); -} - void catch_interrupt(int sig) { LOG(INFO) << "Stopping Typesense server..."; signal(sig, SIG_IGN); // ignore for now as we want to shut down elegantly @@ -305,21 +290,15 @@ int start_raft_server(ReplicationState& replication_state, const std::string& st int run_server(const Config & config, const std::string & version, void (*master_server_routes)()) { LOG(INFO) << "Starting Typesense " << version << std::flush; - if(using_jemalloc()) { - LOG(INFO) << "Typesense is using jemalloc."; - - // Due to time based decay depending on application not being idle-ish, set `background_thread` - // to help with releasing memory back to the OS and improve tail latency. - // See: https://github.com/jemalloc/jemalloc/issues/1398 - bool background_thread = true; -#ifdef __APPLE__ + // Due to time based decay depending on application not being idle-ish, set `background_thread` + // to help with releasing memory back to the OS and improve tail latency. + // See: https://github.com/jemalloc/jemalloc/issues/1398 + bool background_thread = true; + #ifdef __APPLE__ je_mallctl("background_thread", nullptr, nullptr, &background_thread, sizeof(bool)); -#elif __linux__ + #elif __linux__ mallctl("background_thread", nullptr, nullptr, &background_thread, sizeof(bool)); -#endif - } else { - LOG(WARNING) << "Typesense is NOT using jemalloc."; - } + #endif quit_raft_service = false;