Skip to content

Commit

Permalink
ARROW-XXX: WIP: [C++] Add support for system mimalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 11, 2024
1 parent ab764f4 commit 228931c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
27 changes: 17 additions & 10 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(ARROW_THIRDPARTY_DEPENDENCIES
jemalloc
LLVM
lz4
mimalloc
nlohmann_json
opentelemetry-cpp
orc
Expand Down Expand Up @@ -200,6 +201,8 @@ macro(build_dependency DEPENDENCY_NAME)
build_jemalloc()
elseif("${DEPENDENCY_NAME}" STREQUAL "lz4")
build_lz4()
elseif("${DEPENDENCY_NAME}" STREQUAL "mimalloc")
build_mimalloc()
elseif("${DEPENDENCY_NAME}" STREQUAL "nlohmann_json")
build_nlohmann_json()
elseif("${DEPENDENCY_NAME}" STREQUAL "opentelemetry-cpp")
Expand Down Expand Up @@ -2194,7 +2197,7 @@ endif()
# ----------------------------------------------------------------------
# mimalloc - Cross-platform high-performance allocator, from Microsoft

if(ARROW_MIMALLOC)
macro(build_mimalloc)
if(NOT ARROW_ENABLE_THREADING)
message(FATAL_ERROR "Can't use mimalloc with ARROW_ENABLE_THREADING=OFF")
endif()
Expand Down Expand Up @@ -2234,20 +2237,24 @@ if(ARROW_MIMALLOC)

file(MAKE_DIRECTORY ${MIMALLOC_INCLUDE_DIR})

add_library(mimalloc::mimalloc STATIC IMPORTED)
set_target_properties(mimalloc::mimalloc PROPERTIES IMPORTED_LOCATION
"${MIMALLOC_STATIC_LIB}")
target_include_directories(mimalloc::mimalloc BEFORE
INTERFACE "${MIMALLOC_INCLUDE_DIR}")
target_link_libraries(mimalloc::mimalloc INTERFACE Threads::Threads)
add_library(mimalloc STATIC IMPORTED)
set_target_properties(mimalloc PROPERTIES IMPORTED_LOCATION "${MIMALLOC_STATIC_LIB}")
target_include_directories(mimalloc BEFORE INTERFACE "${MIMALLOC_INCLUDE_DIR}")
target_link_libraries(mimalloc INTERFACE Threads::Threads)
if(WIN32)
target_link_libraries(mimalloc::mimalloc INTERFACE "bcrypt.lib" "psapi.lib")
target_link_libraries(mimalloc INTERFACE "bcrypt.lib" "psapi.lib")
endif()
add_dependencies(mimalloc::mimalloc mimalloc_ep)
add_dependencies(mimalloc mimalloc_ep)

list(APPEND ARROW_BUNDLED_STATIC_LIBS mimalloc::mimalloc)
list(APPEND ARROW_BUNDLED_STATIC_LIBS mimalloc)

set(mimalloc_VENDORED TRUE)
endmacro()

if(ARROW_MIMALLOC)
set(CMAKE_FIND_DEBUG_MODE ON)
resolve_dependency(mimalloc)
set(CMAKE_FIND_DEBUG_MODE OFF)
endif()

# ----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ if(ARROW_JEMALLOC)
endif()
if(ARROW_MIMALLOC)
foreach(ARROW_MEMORY_POOL_TARGET ${ARROW_MEMORY_POOL_TARGETS})
target_link_libraries(${ARROW_MEMORY_POOL_TARGET} PRIVATE mimalloc::mimalloc)
target_link_libraries(${ARROW_MEMORY_POOL_TARGET} PRIVATE mimalloc)
endforeach()
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ RUN \
libgrpc++-dev \
libgtest-dev \
liblz4-dev \
libmimalloc-dev \
libprotobuf-dev \
libprotoc-dev \
libre2-dev \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ RUN \
libgrpc++-dev \
libgtest-dev \
liblz4-dev \
libmimalloc-dev \
libmlir-15-dev \
libprotobuf-dev \
libprotoc-dev \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ RUN \
llvm-static \
lz4-devel \
make \
mimalloc-devel \
ncurses-devel \
ninja-build \
openssl-devel \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ RUN \
llvm-static \
lz4-devel \
make \
mimalloc-devel \
ncurses-devel \
ninja-build \
openssl-devel \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RUN \
llvm-devel \
lz4-devel \
make \
mimalloc-devel \
ncurses-devel \
ninja-build \
openssl-devel \
Expand Down

0 comments on commit 228931c

Please sign in to comment.