From 184996d92589ba8ff95e7c5ba23b8ac1df3b3712 Mon Sep 17 00:00:00 2001 From: Dominik Gleich Date: Fri, 20 Oct 2017 16:53:24 +0200 Subject: [PATCH] Change allocator. Summary: There seems to be a gain all over memgraph. I strongly suggest including this in the codebase. Link to project: https://github.com/r-lyeh/ltalloc Reviewers: teon.banek, mferencevic, mislav.bradac, florijan Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D914 --- CMakeLists.txt | 12 ++++++++++++ libs/CMakeLists.txt | 6 ++++++ libs/setup.sh | 7 +++++++ src/database/graph_db.cpp | 9 --------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc766dd33..201c9dfbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,10 @@ add_custom_target(clean_all # threading find_package(Threads REQUIRED) +# optional Ltalloc +option(USE_LTALLOC "Use Ltalloc instead of default allocator (default ON). \ +Set this to OFF to prevent linking with Ltalloc." ON) + # optional readline option(USE_READLINE "Use GNU Readline library if available (default ON). \ Set this to OFF to prevent linking with Readline even if it is available." ON) @@ -69,6 +73,7 @@ endif() # set(CMAKE_CXX_STANDARD_REQUIRED ON) # For now, explicitly set -std= flag for C++17. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -Wall") + # Don't omit frame pointer in RelWithDebInfo, for additional callchain debug. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer") @@ -215,6 +220,13 @@ set(memgraph_src_files # memgraph_lib depend on these libraries set(MEMGRAPH_ALL_LIBS stdc++fs Threads::Threads fmt cppitertools antlr_opencypher_parser_lib dl glog gflags) + +if (USE_LTALLOC) + list(APPEND MEMGRAPH_ALL_LIBS ltalloc) +# TODO(mferencevic): Enable this when clang is updated on apollo. +# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto") +endif() + if (READLINE_FOUND) list(APPEND MEMGRAPH_ALL_LIBS readline) endif() diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index ac9225823..2d29c6a62 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -94,6 +94,12 @@ import_external_library(fmt STATIC # Skip testing. CMAKE_ARGS -DFMT_TEST=OFF) + +# Setup ltalloc library +add_library(ltalloc STATIC ltalloc/ltalloc.cc) +# TODO(mferencevic): Enable this when clang on apollo is updated +#target_compile_options(ltalloc PUBLIC -flto) + # setup rapidcheck (it cannot be external, since it doesn't have install # target) set(RC_ENABLE_GTEST ON CACHE BOOL "Build Google Test integration" FORCE) diff --git a/libs/setup.sh b/libs/setup.sh index 49c35f071..e8a0bf17a 100755 --- a/libs/setup.sh +++ b/libs/setup.sh @@ -107,3 +107,10 @@ cd json #wget "https://raw.githubusercontent.com/nlohmann/json/91e003285312167ad8365f387438ea371b465a7e/src/json.hpp" wget -nv http://deps.memgraph.io/json.hpp cd .. + +#ltalloc +git clone https://github.com/r-lyeh/ltalloc.git +ltalloc_tag="aefde2afa5cd49c9d1a797aa08ec08b2bec13a36" # Sep 15, 2017 +cd ltalloc +git checkout ${ltalloc_tag} +cd .. diff --git a/src/database/graph_db.cpp b/src/database/graph_db.cpp index 596e4326b..24e898b40 100644 --- a/src/database/graph_db.cpp +++ b/src/database/graph_db.cpp @@ -1,7 +1,5 @@ #include -#include - #include #include @@ -136,13 +134,6 @@ void GraphDb::CollectGarbage() { << x.Elapsed().count(); } - { - utils::Timer x; - malloc_trim(0); - VLOG(1) << "Garbage collector malloc trim phase time: " - << x.Elapsed().count(); - } - LOG(INFO) << "Garbage collector finished"; VLOG(2) << "gc snapshot: " << snapshot; VLOG(2) << "edge_record_deleter_ size: " << edge_record_deleter_.Count();