diff --git a/cmake/XrplCompiler.cmake b/cmake/XrplCompiler.cmake index cb4e797137..541d7abd21 100644 --- a/cmake/XrplCompiler.cmake +++ b/cmake/XrplCompiler.cmake @@ -242,7 +242,7 @@ elseif(use_gold AND is_gcc) disabling would be to figure out all the settings required to make gold play nicely with jemalloc. #]=========================================================] - if(("${LD_VERSION}" MATCHES "GNU gold") AND (NOT jemalloc)) + if(("${LD_VERSION}" MATCHES "GNU gold") AND (NOT jemalloc) AND (NOT tcmalloc)) target_link_libraries( common INTERFACE diff --git a/cmake/XrplInterface.cmake b/cmake/XrplInterface.cmake index 825cb63310..0bba3ab154 100644 --- a/cmake/XrplInterface.cmake +++ b/cmake/XrplInterface.cmake @@ -54,6 +54,11 @@ if(jemalloc) target_link_libraries(opts INTERFACE jemalloc::jemalloc) endif() +if(tcmalloc) + find_package(gperftools REQUIRED) + target_link_libraries(opts INTERFACE gperftools::gperftools) +endif() + #[===================================================================[ xrpld transitive library deps via an interface library #]===================================================================] diff --git a/cmake/XrplSettings.cmake b/cmake/XrplSettings.cmake index 757a596096..0c45744e28 100644 --- a/cmake/XrplSettings.cmake +++ b/cmake/XrplSettings.cmake @@ -125,6 +125,10 @@ else() endif() option(jemalloc "Enables jemalloc for heap profiling" OFF) +option(tcmalloc "Link xrpld against tcmalloc (gperftools) as the global allocator" OFF) +if(jemalloc AND tcmalloc) + message(FATAL_ERROR "jemalloc and tcmalloc are mutually exclusive") +endif() option(werr "treat warnings as errors" OFF) option( local_protobuf diff --git a/conanfile.py b/conanfile.py index 77666f5a2c..852350c255 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,6 +3,7 @@ import re from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout from conan import ConanFile +from conan.errors import ConanInvalidConfiguration class Xrpl(ConanFile): @@ -21,6 +22,7 @@ class Xrpl(ConanFile): "rocksdb": [True, False], "shared": [True, False], "static": [True, False], + "tcmalloc": [True, False], "telemetry": [True, False], "tests": [True, False], "unity": [True, False], @@ -53,6 +55,7 @@ class Xrpl(ConanFile): "rocksdb": True, "shared": False, "static": True, + "tcmalloc": False, "telemetry": True, "tests": False, "unity": False, @@ -125,6 +128,10 @@ class Xrpl(ConanFile): self.version = match.group(1) def configure(self): + if self.options.tcmalloc and self.options.jemalloc: + raise ConanInvalidConfiguration( + "jemalloc and tcmalloc cannot both be enabled" + ) if self.settings.compiler == "apple-clang": self.options["boost"].visibility = "global" if self.settings.compiler in ["clang", "gcc"]: @@ -135,6 +142,8 @@ class Xrpl(ConanFile): self.requires("date/3.0.4", transitive_headers=True) if self.options.jemalloc: self.requires("jemalloc/5.3.1") + if self.options.tcmalloc: + self.requires("gperftools/2.16") self.requires("lz4/1.10.0", force=True) self.requires("mpt-crypto/0.4.0-rc2", transitive_headers=True) self.requires("protobuf/6.33.5", force=True) @@ -171,6 +180,7 @@ class Xrpl(ConanFile): tc.variables["assert"] = self.options.assertions tc.variables["coverage"] = self.options.coverage tc.variables["jemalloc"] = self.options.jemalloc + tc.variables["tcmalloc"] = self.options.tcmalloc tc.variables["rocksdb"] = self.options.rocksdb tc.variables["BUILD_SHARED_LIBS"] = self.options.shared tc.variables["static"] = self.options.static diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 4620a3165b..3b7396c919 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -1129,7 +1129,8 @@ public: << "; size after: " << cachedSLEs_.size(); } - mallocTrim("doSweep", journal_); + // Disabled for allocator benchmark: no proactive malloc_trim on sweep. + // mallocTrim("doSweep", journal_); // Set timer to do another sweep later. setSweepTimer();