Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${CMAKE_BINARY_DIR}/generators/")
# Export compile commands for configuring language servers or debugging the build
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# ---------------------------------------------------------------------------
# Allocator
# ---------------------------------------------------------------------------

option(USE_MIMALLOC "Use mimalloc allocator" ON)

# Only use mimalloc in Release mode, because of conflicts with ASAN
if(USE_MIMALLOC AND ${CMAKE_BUILD_TYPE} STREQUAL "Release")
message("Using mimalloc as allocator")
find_package(mimalloc REQUIRED)
add_compile_definitions(SILO_USE_MIMALLOC=1)
set(MIMALLOC_LIB mimalloc-static)
else()
set(MIMALLOC_LIB "")
endif()


# ---------------------------------------------------------------------------
# Compile definitions
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -113,6 +130,7 @@ add_library(silolib OBJECT ${SRC_SILO_WITHOUT_MAIN})
target_link_libraries(
silolib
PUBLIC
${MIMALLOC_LIB} # this should be first
Arrow::arrow_static
ArrowAcero::arrow_acero_static
${Boost_LIBRARIES}
Expand Down
10 changes: 8 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class SiloRecipe(ConanFile):
requires = [
"arrow/22.0.0",
"boost/1.85.0",
"poco/1.13.3",
"nlohmann_json/3.12.0",
"gtest/1.16.0",
"mimalloc/2.2.4",
"nlohmann_json/3.12.0",
"poco/1.13.3",
"re2/20240702",
"roaring/4.2.1",
"simdjson/3.12.3",
Expand All @@ -22,6 +23,7 @@ class SiloRecipe(ConanFile):
default_options = {
"abseil/*:shared": False,

"arrow/*:with_mimalloc": False,
Comment thread
pflanze marked this conversation as resolved.
"arrow/*:compute": True,
"arrow/*:acero": True,

Expand Down Expand Up @@ -65,6 +67,9 @@ class SiloRecipe(ConanFile):

"hwloc/*:shared": False,

# this statically overrides the `malloc` symbol to use mimalloc
"mimalloc/*:override": True,

"poco/*:shared": False,
"poco/*:enable_json": True,
"poco/*:enable_net": True,
Expand Down Expand Up @@ -104,6 +109,7 @@ def generate(self):
deps.set_property("boost", "cmake_find_mode", "both")
deps.set_property("gtest", "cmake_find_mode", "both")
deps.set_property("hwloc", "cmake_find_mode", "both")
deps.set_property("mimalloc", "cmake_find_mode", "both")
deps.set_property("nlohmann_json", "cmake_find_mode", "both")
deps.set_property("pcre2", "cmake_find_mode", "both")
deps.set_property("poco", "cmake_find_mode", "both")
Expand Down
7 changes: 3 additions & 4 deletions src/silo/api/memory_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#if defined(__linux__)

#include <malloc.h>

#include <filesystem>
#include <fstream>
#include <optional>
Expand All @@ -12,6 +10,8 @@

#include <spdlog/spdlog.h>

#include "silo/common/allocator.h"

namespace {

std::optional<uint32_t> parseVmRSSLine(const std::string& line) {
Expand Down Expand Up @@ -73,8 +73,7 @@ void MemoryMonitor::checkRssAndLimit(Poco::Timer& /*timer*/) {
SPDLOG_INFO("Current memory consumption: {} KB", rss.value());

if (soft_memory_limit_in_kb.has_value() && rss.value() > soft_memory_limit_in_kb.value()) {
SPDLOG_INFO("Manually invoking malloc_trim() to give back memory to OS.");
malloc_trim(0);
silo::common::Allocator::trim();
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/silo/common/allocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifdef SILO_USE_MIMALLOC
#include <mimalloc.h>
#elif defined(__linux__)
#include <malloc.h>
#endif

#include <spdlog/spdlog.h>

namespace silo::common {

class Allocator {
public:
#ifdef SILO_USE_MIMALLOC
static void trim() {
SPDLOG_INFO("Manually invoking mi_collect(true) to give back memory to OS.");
mi_collect(true);
mi_collect(true); // This should be invoked twice
}
#elif defined(__linux__)
static void trim() {
SPDLOG_INFO("Manually invoking malloc_trim() to give back memory to OS.");
malloc_trim(0);
}
#else
static void trim() { SPDLOG_INFO("Allocator::trim() is not implemented for this platform."); }
#endif
};

} // namespace silo::common
Comment thread
pflanze marked this conversation as resolved.