From 488ed47cda3a7e45909b065aac10236a6258255c Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Mon, 13 Sep 2021 13:21:12 -0300 Subject: [PATCH] Remove duplicate handling of jemalloc We were linking/loading it in different ways, one with cmake option `USE_JELLOC` and the other, older version `WITH_JEMALLOC`. This removes the latter (which was default OFF) and keeps the former (which was added and has been default ON since 0.9.4 or so). Also removes the `ifdef`ed JEMALLOC code in lokinet.cpp because we don't need it; just linking to jemalloc is enough to get the malloc/free replacements. --- CMakeLists.txt | 3 +-- cmake/unix.cmake | 9 --------- daemon/CMakeLists.txt | 3 --- daemon/lokinet.cpp | 26 -------------------------- 4 files changed, 1 insertion(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3077b523d..4fee4f2a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF) option(BUILD_LIBLOKINET "build liblokinet.so" ON) option(SHADOW "use shadow testing framework. linux only" OFF) option(XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF) -option(WITH_JEMALLOC "use jemalloc as allocator" OFF) +option(USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON) option(TESTNET "testnet build" OFF) option(WITH_COVERAGE "generate coverage data" OFF) option(USE_SHELLHOOKS "enable shell hooks on compile time (dangerous)" OFF) @@ -299,7 +299,6 @@ endif() add_subdirectory(external) include_directories(SYSTEM external/sqlite_orm/include) -option(USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON) if(USE_JEMALLOC AND NOT STATIC_LINK) pkg_check_modules(JEMALLOC jemalloc IMPORTED_TARGET) if(JEMALLOC_FOUND) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index c151fcdd9..3adbc844e 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -7,15 +7,6 @@ endif() include(CheckCXXSourceCompiles) include(CheckLibraryExists) -if(WITH_JEMALLOC) - find_package(Jemalloc REQUIRED) - if(NOT JEMALLOC_FOUND) - message(FATAL_ERROR "did not find jemalloc") - endif() - add_definitions(-DUSE_JEMALLOC) - message(STATUS "using jemalloc") -endif() - add_definitions(-DUNIX) add_definitions(-DPOSIX) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 1eea3132a..bc7be3a1f 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -62,9 +62,6 @@ foreach(exe ${exetargets}) target_link_directories(${exe} PRIVATE /usr/local/lib) endif() target_link_libraries(${exe} PUBLIC liblokinet) - if(WITH_JEMALLOC) - target_link_libraries(${exe} PUBLIC jemalloc) - endif() target_include_directories(${exe} PUBLIC "${PROJECT_SOURCE_DIR}") target_compile_definitions(${exe} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) add_log_tag(${exe}) diff --git a/daemon/lokinet.cpp b/daemon/lokinet.cpp index 316d1b856..4acff0272 100644 --- a/daemon/lokinet.cpp +++ b/daemon/lokinet.cpp @@ -18,32 +18,6 @@ #include #include -#ifdef USE_JEMALLOC -#include -#include - -void* -operator new(std::size_t sz) -{ - void* ptr = malloc(sz); - if (ptr) - return ptr; - else - throw std::bad_alloc{}; -} -void -operator delete(void* ptr) noexcept -{ - free(ptr); -} - -void -operator delete(void* ptr, size_t) noexcept -{ - free(ptr); -} -#endif - int lokinet_main(int, char**);