Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimalloc depdence #364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ option(CRANE_ADDRESS_SANITIZER "Enable address sanitizer" OFF)
option(CRANE_THREAD_SANITIZER "Enable thread sanitizer" OFF)

option(CRANE_MIN_LOG_LEVEL "Set the minimal log level (INFO/DEBUG/TRACE)" OFF)

option(CRANE_USE_MIMALLOC "Override malloc using mimalloc" OFF)
# Options end here -------------------------------------------------------------------------------

if (CRANE_ADDRESS_SANITIZER AND CRANE_THREAD_SANITIZER)
message(FATAL_ERROR "CRANE_ADDRESS_SANITIZER and CRANE_THREAD_SANITIZER cannot be enabled at the same time.")
endif()

set(CMAKE_CXX_STANDARD 20)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
4 changes: 3 additions & 1 deletion dependencies/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ add_subdirectory(mongodb-cxx-driver)
add_subdirectory(ranges-v3)
add_subdirectory(backward-cpp)
add_subdirectory(fpm)

if(CRANE_USE_MIMALLOC)
add_subdirectory(mimalloc)
endif()
#add_subdirectory(mariadb-connector-c)

include(${CMAKE_SOURCE_DIR}/CMakeModule/SuppressHeaderWarning.cmake)
Expand Down
16 changes: 16 additions & 0 deletions dependencies/cmake/mimalloc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include(FetchContent)
FetchContent_Declare(
mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
GIT_TAG v2.1.7
GIT_SHALLOW TRUE
)
# if MI_OVERRIDE is ON then operator new and delete will be override not only malloc and free
# https://github.com/microsoft/mimalloc/issues/535

if(CRANE_ADDRESS_SANITIZER AND NOT CRANE_THREAD_SANITIZER)
L-Xiafeng marked this conversation as resolved.
Show resolved Hide resolved
set(MI_TRACK_ASAN ON CACHE BOOL "Enable ASAN in mimalloc" FORCE)
message("Set ASAN enable in mimalloc")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些普通的message加一个STATUS

endif()

FetchContent_MakeAvailable(mimalloc)
6 changes: 5 additions & 1 deletion src/CraneCtld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ add_executable(cranectld
CtldPreCompiledHeader.h)

target_precompile_headers(cranectld PRIVATE CtldPreCompiledHeader.h)

if(CRANE_USE_MIMALLOC)
add_compile_definitions(cranectld PRIVATE MI_OVERRIDE=ON)
message("Override malloc with mimalloc in cranectld")
endif()
target_link_libraries(cranectld PRIVATE
spdlog::spdlog
concurrentqueue
Expand Down Expand Up @@ -49,6 +52,7 @@ target_link_libraries(cranectld PRIVATE
result

Backward::Interface
$<$<BOOL:${CRANE_USE_MIMALLOC}>:mimalloc>
)

if (ENABLE_BERKELEY_DB AND BERKELEYDB_FOUND)
Expand Down
8 changes: 7 additions & 1 deletion src/Craned/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ target_include_directories(

if(ENABLE_BPF)
add_dependencies(craned cgroup_dev_bpf_object)
target_compile_definitions(craned PRIVATE CRANE_ENABLE_BPF)
add_compile_definitions(craned PRIVATE CRANE_ENABLE_BPF)
endif()
if(CRANE_USE_MIMALLOC)
add_compile_definitions(craned PRIVATE MI_OVERRIDE=ON)
message("Override malloc with mimalloc in craned")
endif()
target_link_libraries(craned
concurrentqueue
Expand Down Expand Up @@ -58,6 +62,8 @@ target_link_libraries(craned
Backward::Interface

$<$<BOOL:${ENABLE_BPF}>:bpf>

$<$<BOOL:${CRANE_USE_MIMALLOC}>:mimalloc>
)

# Linker flag for c++ 17 filesystem library
Expand Down
6 changes: 6 additions & 0 deletions src/Misc/Pam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ set_target_properties(pam_crane PROPERTIES PREFIX "")

target_include_directories(pam_crane PUBLIC ${PAM_INCLUDE_DIR})

if(CRANE_USE_MIMALLOC)
add_compile_definitions(pam_crane PRIVATE MI_OVERRIDE=ON)
message("Override malloc with mimalloc in pam_crane")
endif()

target_link_libraries(pam_crane PUBLIC
${PAM_LIBRARIES}
Utility_PublicHeaderNoLogger
crane_proto_lib
fmt::fmt
yaml-cpp
$<$<BOOL:${CRANE_USE_MIMALLOC}>:mimalloc>
)

# Linker flag for c++ 17 filesystem library
Expand Down