mirror of
https://github.com/XTXMarkets/ternfs.git
synced 2025-12-16 16:26:47 -06:00
Use mimalloc in release and alpine builds
This should make the alpine build usable in production.
This commit is contained in:
committed by
Francesco Mazzoli
parent
b744242b5a
commit
02891b6863
@@ -158,8 +158,6 @@ Will build all the artifacts apart from the Kernel module. The output binaries w
|
||||
|
||||
There's also `./build.sh ubuntu` which will do the same but in a Ubuntu container, and `./build.sh release` which will build outside docker, which means that you'll have to install some dependencies in the host machine. Both of these build options will have glibc as the only dynamically linked dependency.
|
||||
|
||||
We use the Ubuntu-built version in production, mostly due to jemalloc not playing well with Alpine. It should be easy to produce a performant Alpine build, we just never had the need so far.
|
||||
|
||||
## Testing
|
||||
|
||||
```
|
||||
|
||||
@@ -50,10 +50,9 @@ set(SANITIZE_OPTIONS "-fsanitize=undefined,address,integer,function;-fno-sanitiz
|
||||
add_compile_options("$<$<CONFIG:sanitized>:${SANITIZE_OPTIONS}>")
|
||||
add_link_options("$<$<CONFIG:sanitized>:${SANITIZE_OPTIONS}>")
|
||||
|
||||
# we only use jemalloc in release builds, alpine doesn't seem to
|
||||
# like jemalloc very much, and sanitizer etc works better without it
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "release")
|
||||
set(TERNFS_JEMALLOC_LIBS "jemalloc")
|
||||
# we only use mimalloc in release builds, sanitizer etc works better without it
|
||||
if("${CMAKE_BUILD_TYPE}" MATCHES "^(release|alpine)$")
|
||||
set(TERNFS_MIMALLOC_LIBS "mimalloc")
|
||||
endif()
|
||||
|
||||
include(thirdparty.cmake)
|
||||
|
||||
@@ -8,4 +8,4 @@ add_library(cdc CDC.cpp CDC.hpp CDCDB.cpp CDCDB.hpp CDCDBData.hpp)
|
||||
target_link_libraries(cdc PRIVATE core)
|
||||
|
||||
add_executable(terncdc terncdc.cpp)
|
||||
target_link_libraries(terncdc PRIVATE core shard cdc ${TERNFS_JEMALLOC_LIBS})
|
||||
target_link_libraries(terncdc PRIVATE core shard cdc ${TERNFS_MIMALLOC_LIBS})
|
||||
|
||||
@@ -8,4 +8,4 @@ add_library(sharddbtools ShardDBTools.hpp ShardDBTools.cpp LogsDBTools.hpp LogsD
|
||||
target_link_libraries(sharddbtools PRIVATE core shard cdc)
|
||||
|
||||
add_executable(terndbtools terndbtools.cpp)
|
||||
target_link_libraries(terndbtools PRIVATE core shard sharddbtools ${TERNFS_JEMALLOC_LIBS})
|
||||
target_link_libraries(terndbtools PRIVATE core shard sharddbtools ${TERNFS_MIMALLOC_LIBS})
|
||||
|
||||
@@ -9,4 +9,4 @@ add_library(registry Registry.hpp Registry.cpp RegistryDB.hpp RegistryDB.cpp
|
||||
target_link_libraries(registry PRIVATE core)
|
||||
|
||||
add_executable(ternregistry ternregistry.cpp)
|
||||
target_link_libraries(ternregistry PRIVATE core registry crc32c ${TERNFS_JEMALLOC_LIBS})
|
||||
target_link_libraries(ternregistry PRIVATE core registry crc32c ${TERNFS_MIMALLOC_LIBS})
|
||||
|
||||
@@ -8,4 +8,4 @@ add_library(shard Shard.cpp Shard.hpp ShardDB.cpp ShardDB.hpp ShardDBData.cpp Sh
|
||||
target_link_libraries(shard PRIVATE core)
|
||||
|
||||
add_executable(ternshard ternshard.cpp)
|
||||
target_link_libraries(ternshard PRIVATE core shard crc32c ${TERNFS_JEMALLOC_LIBS})
|
||||
target_link_libraries(ternshard PRIVATE core shard crc32c ${TERNFS_MIMALLOC_LIBS})
|
||||
|
||||
@@ -165,31 +165,39 @@ ExternalProject_Get_property(make_xxhash INSTALL_DIR)
|
||||
include_directories(SYSTEM ${INSTALL_DIR}/include)
|
||||
set_target_properties(xxhash PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/lib/libxxhash.a)
|
||||
|
||||
set(DEP_MIMALLOC_CMAKE_ARGS
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DMI_BUILD_SHARED:BOOL=OFF
|
||||
-DMI_BUILD_TESTS:BOOL=OFF
|
||||
-DMI_OPT_ARCH:BOOL=ON
|
||||
)
|
||||
if("${CMAKE_BUILD_TYPE}" MATCHES "^alpine")
|
||||
list(APPEND DEP_MIMALLOC_CMAKE_ARGS -DMI_LIBC_MUSL:BOOL=ON)
|
||||
endif()
|
||||
|
||||
# License: BSD
|
||||
ExternalProject_Add(make_jemalloc
|
||||
ExternalProject_Add(make_mimalloc
|
||||
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
||||
URL https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2
|
||||
URL_HASH SHA256=2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa
|
||||
PREFIX thirdparty/jemalloc
|
||||
URL https://github.com/microsoft/mimalloc/archive/refs/tags/v3.0.10.tar.gz
|
||||
URL_HASH SHA256=ee5556a31060f2289497f00126e90bf871e90933f98e21ea13dca3578e9ccfb5
|
||||
PREFIX thirdparty/mimalloc
|
||||
UPDATE_COMMAND ""
|
||||
SOURCE_DIR ${make_jemalloc_SOURCE_DIR}
|
||||
CONFIGURE_COMMAND ./configure --prefix=<INSTALL_DIR> --disable-libdl
|
||||
BUILD_IN_SOURCE 1
|
||||
BUILD_COMMAND ${MAKE_EXE} -j ${MAKE_PARALLELISM}
|
||||
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/libjemalloc.a
|
||||
INSTALL_COMMAND ${MAKE_EXE} install PREFIX=<INSTALL_DIR>
|
||||
SOURCE_DIR ${make_mimalloc_SOURCE_DIR}
|
||||
CMAKE_ARGS ${DEP_MIMALLOC_CMAKE_ARGS}
|
||||
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/mimalloc-3.0/libmimalloc.a
|
||||
LOG_DOWNLOAD ON
|
||||
LOG_CONFIGURE ON
|
||||
LOG_INSTALL ON
|
||||
LOG_BUILD ON
|
||||
LOG_OUTPUT_ON_FAILURE ON
|
||||
)
|
||||
add_library(jemalloc STATIC IMPORTED)
|
||||
ExternalProject_Get_property(make_jemalloc INSTALL_DIR)
|
||||
add_library(mimalloc STATIC IMPORTED)
|
||||
ExternalProject_Get_property(make_mimalloc INSTALL_DIR)
|
||||
include_directories(SYSTEM ${INSTALL_DIR}/include)
|
||||
set_target_properties(jemalloc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/lib/libjemalloc.a)
|
||||
set_target_properties(mimalloc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/lib/mimalloc-3.0/libmimalloc.a)
|
||||
|
||||
# This explicit dependency tracking is needed for ninja, which is blind to the
|
||||
# include dependencies from our code into the above, apparently.
|
||||
add_custom_target(thirdparty)
|
||||
add_dependencies(thirdparty make_uring make_lz4 make_zstd make_rocksdb make_xxhash make_jemalloc)
|
||||
add_dependencies(thirdparty make_uring make_lz4 make_zstd make_rocksdb make_xxhash make_mimalloc)
|
||||
|
||||
Reference in New Issue
Block a user