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
1 change: 1 addition & 0 deletions ci/conan/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def _configure_cmake(self):
self._cmake.definitions["ARROW_CSV"] = self.options.with_csv
self._cmake.definitions["ARROW_CUDA"] = self.options.with_cuda
self._cmake.definitions["ARROW_JEMALLOC"] = self._with_jemalloc()
self._cmake.definitions["jemalloc_SOURCE"] = "SYSTEM"
self._cmake.definitions["ARROW_JSON"] = self.options.with_json

self._cmake.definitions["BOOST_SOURCE"] = "SYSTEM"
Expand Down
3 changes: 3 additions & 0 deletions ci/scripts/conan_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ conan_args=()
if [ -n "${ARROW_CONAN_PARQUET:-}" ]; then
conan_args+=(--options arrow:parquet=${ARROW_CONAN_PARQUET})
fi
if [ -n "${ARROW_CONAN_WITH_JEMALLOC:-}" ]; then
conan_args+=(--options arrow:with_jemalloc=${ARROW_CONAN_WITH_JEMALLOC})
fi
if [ -n "${ARROW_CONAN_WITH_LZ4:-}" ]; then
conan_args+=(--options arrow:with_lz4=${ARROW_CONAN_WITH_LZ4})
fi
Expand Down
6 changes: 2 additions & 4 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,8 @@ if(ARROW_BUILD_BENCHMARKS)
endif()

if(ARROW_JEMALLOC)
add_definitions(-DARROW_JEMALLOC)
add_definitions(-DARROW_JEMALLOC_INCLUDE_DIR=${JEMALLOC_INCLUDE_DIR})
list(APPEND ARROW_LINK_LIBS jemalloc::jemalloc)
list(APPEND ARROW_STATIC_LINK_LIBS jemalloc::jemalloc)
list(APPEND ARROW_LINK_LIBS jemalloc)
list(APPEND ARROW_STATIC_LINK_LIBS jemalloc)
endif()

if(ARROW_MIMALLOC)
Expand Down
4 changes: 4 additions & 0 deletions cpp/cmake_modules/DefineOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ if(ARROW_DEFINE_OPTIONS)
define_option(ARROW_GRPC_USE_SHARED "Rely on gRPC shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

define_option(ARROW_JEMALLOC_USE_SHARED
"Rely on jemalloc shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

define_option(ARROW_LZ4_USE_SHARED "Rely on lz4 shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

Expand Down
113 changes: 51 additions & 62 deletions cpp/cmake_modules/Findjemalloc.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -17,78 +16,68 @@
#
# find_package(jemalloc)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# JEMALLOC_HOME -
# When set, this path is inspected instead of standard library locations as
# the root of the jemalloc installation. The environment variable
# JEMALLOC_HOME overrides this veriable.
#
# This module defines
# JEMALLOC_INCLUDE_DIR, directory containing headers
# JEMALLOC_SHARED_LIB, path to libjemalloc.so/dylib
# JEMALLOC_FOUND, whether jemalloc has been found
# jemalloc::jemalloc, target to use jemalloc

if(NOT "${JEMALLOC_HOME}" STREQUAL "")
file(TO_CMAKE_PATH "${JEMALLOC_HOME}" _native_path)
list(APPEND _jemalloc_roots ${_native_path})
elseif(JEMALLOC_HOME)
list(APPEND _jemalloc_roots ${JEMALLOC_HOME})
if(ARROW_JEMALLOC_USE_SHARED)
set(jemalloc_LIB_NAMES)
if(CMAKE_IMPORT_LIBRARY_SUFFIX)
list(APPEND jemalloc_LIB_NAMES
"${CMAKE_IMPORT_LIBRARY_PREFIX}jemalloc${CMAKE_IMPORT_LIBRARY_SUFFIX}")
endif()
list(APPEND jemalloc_LIB_NAMES
"${CMAKE_SHARED_LIBRARY_PREFIX}jemalloc${CMAKE_SHARED_LIBRARY_SUFFIX}")
else()
set(jemalloc_LIB_NAMES
"${CMAKE_STATIC_LIBRARY_PREFIX}jemalloc${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()

set(LIBJEMALLOC_NAMES jemalloc libjemalloc.so.1 libjemalloc.so.2 libjemalloc.dylib)

# Try the parameterized roots, if they exist
if(_jemalloc_roots)
find_path(JEMALLOC_INCLUDE_DIR
if(jemalloc_ROOT)
find_library(jemalloc_LIB
NAMES ${jemallc_LIB_NAMES}
PATHS ${jemallc_ROOT}
PATH_SUFFIXES ${ARROW_LIBRARY_PATH_SUFFIXES}
NO_DEFAULT_PATH)
find_path(jemalloc_INCLUDE_DIR
NAMES jemalloc/jemalloc.h
PATHS ${_jemalloc_roots}
PATHS ${jemalloc_ROOT}
NO_DEFAULT_PATH
PATH_SUFFIXES "include")
find_library(JEMALLOC_SHARED_LIB
NAMES ${LIBJEMALLOC_NAMES}
PATHS ${_jemalloc_roots}
NO_DEFAULT_PATH
PATH_SUFFIXES "lib")
find_library(JEMALLOC_STATIC_LIB
NAMES jemalloc_pic
PATHS ${_jemalloc_roots}
NO_DEFAULT_PATH
PATH_SUFFIXES "lib")
else()
find_path(JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h)
message(STATUS ${JEMALLOC_INCLUDE_DIR})
find_library(JEMALLOC_SHARED_LIB NAMES ${LIBJEMALLOC_NAMES})
message(STATUS ${JEMALLOC_SHARED_LIB})
find_library(JEMALLOC_STATIC_LIB NAMES jemalloc_pic)
message(STATUS ${JEMALLOC_STATIC_LIB})
endif()
PATH_SUFFIXES ${ARROW_INCLUDE_PATH_SUFFIXES})

if(JEMALLOC_INCLUDE_DIR AND JEMALLOC_SHARED_LIB)
set(JEMALLOC_FOUND TRUE)
else()
set(JEMALLOC_FOUND FALSE)
find_package(PkgConfig QUIET)
pkg_check_modules(jemalloc_PC jemalloc)
if(jemalloc_PC_FOUND)
set(jemalloc_INCLUDE_DIR "${jemalloc_PC_INCLUDEDIR}")
list(APPEND jemalloc_PC_LIBRARY_DIRS "${jemalloc_PC_LIBDIR}")
find_library(jemalloc_LIB
NAMES ${jemalloc_LIB_NAMES}
PATHS ${jemalloc_PC_LIBRARY_DIRS}
NO_DEFAULT_PATH
PATH_SUFFIXES ${ARROW_LIBRARY_PATH_SUFFIXES})
else()
find_library(jemalloc_LIB
NAMES ${jemalloc_LIB_NAMES}
PATH_SUFFIXES ${ARROW_LIBRARY_PATH_SUFFIXES})
find_path(jemalloc_INCLUDE_DIR
NAMES jemalloc/jemalloc.h
PATH_SUFFIXES ${ARROW_INCLUDE_PATH_SUFFIXES})
endif()
endif()

if(JEMALLOC_FOUND)
if(NOT jemalloc_FIND_QUIETLY)
message(STATUS "Found the jemalloc library: ${JEMALLOC_LIBRARIES}")
endif()
else()
if(NOT jemalloc_FIND_QUIETLY)
set(JEMALLOC_ERR_MSG "Could not find the jemalloc library. Looked in ")
if(_jemalloc_roots)
set(JEMALLOC_ERR_MSG "${JEMALLOC_ERR_MSG} in ${_jemalloc_roots}.")
find_package_handle_standard_args(jemalloc REQUIRED_VARS jemalloc_LIB
jemalloc_INCLUDE_DIR)

if(jemalloc_FOUND)
if(NOT TARGET jemalloc::jemalloc)
if(ARROW_JEMALLOC_USE_SHARED)
add_library(jemalloc::jemalloc SHARED IMPORTED)
else()
set(JEMALLOC_ERR_MSG "${JEMALLOC_ERR_MSG} system search paths.")
add_library(jemalloc::jemalloc STATIC IMPORTED)
endif()
if(jemalloc_FIND_REQUIRED)
message(FATAL_ERROR "${JEMALLOC_ERR_MSG}")
else(jemalloc_FIND_REQUIRED)
message(STATUS "${JEMALLOC_ERR_MSG}")
endif(jemalloc_FIND_REQUIRED)
set_target_properties(jemalloc::jemalloc
PROPERTIES IMPORTED_LOCATION "${jemalloc_LIB}"
INTERFACE_INCLUDE_DIRECTORIES
"${jemalloc_INCLUDE_DIR}")
endif()
endif()

mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_SHARED_LIB)
35 changes: 26 additions & 9 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(ARROW_THIRDPARTY_DEPENDENCIES
google_cloud_cpp_storage
gRPC
GTest
jemalloc
LLVM
lz4
nlohmann_json
Expand Down Expand Up @@ -102,6 +103,11 @@ if("${lz4_SOURCE}" STREQUAL "" AND NOT "${Lz4_SOURCE}" STREQUAL "")
set(lz4_SOURCE ${Lz4_SOURCE})
endif()

# For backward compatibility. We use bundled jemalloc by default.
if("${jemalloc_SOURCE}" STREQUAL "")
set(jemalloc_SOURCE "BUNDLED")
endif()

message(STATUS "Using ${ARROW_DEPENDENCY_SOURCE} approach to find dependencies")

if(ARROW_DEPENDENCY_SOURCE STREQUAL "CONDA")
Expand Down Expand Up @@ -162,6 +168,8 @@ macro(build_dependency DEPENDENCY_NAME)
build_grpc()
elseif("${DEPENDENCY_NAME}" STREQUAL "GTest")
build_gtest()
elseif("${DEPENDENCY_NAME}" STREQUAL "jemalloc")
build_jemalloc()
elseif("${DEPENDENCY_NAME}" STREQUAL "lz4")
build_lz4()
elseif("${DEPENDENCY_NAME}" STREQUAL "nlohmann_json")
Expand Down Expand Up @@ -1762,13 +1770,12 @@ endif()
# ----------------------------------------------------------------------
# jemalloc - Unix-only high-performance allocator

if(ARROW_JEMALLOC)
message(STATUS "Building (vendored) jemalloc from source")
# We only use a vendored jemalloc as we want to control its version.
# Also our build of jemalloc is specially prefixed so that it will not
macro(build_jemalloc)
# Our build of jemalloc is specially prefixed so that it will not
# conflict with the default allocator as well as other jemalloc
# installations.
# find_package(jemalloc)

message(STATUS "Building jemalloc from source")

set(ARROW_JEMALLOC_USE_SHARED OFF)
set(JEMALLOC_PREFIX
Expand Down Expand Up @@ -1823,15 +1830,23 @@ if(ARROW_JEMALLOC)
set(JEMALLOC_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/jemalloc_ep-prefix/src/")
# The include directory must exist before it is referenced by a target.
file(MAKE_DIRECTORY "${JEMALLOC_INCLUDE_DIR}")
add_library(jemalloc::jemalloc STATIC IMPORTED)
set_target_properties(jemalloc::jemalloc
add_library(jemalloc STATIC IMPORTED)
set_target_properties(jemalloc
PROPERTIES INTERFACE_LINK_LIBRARIES Threads::Threads
IMPORTED_LOCATION "${JEMALLOC_STATIC_LIB}"
INTERFACE_INCLUDE_DIRECTORIES
"${JEMALLOC_INCLUDE_DIR}")
add_dependencies(jemalloc::jemalloc jemalloc_ep)
add_dependencies(jemalloc jemalloc_ep)

list(APPEND ARROW_BUNDLED_STATIC_LIBS jemalloc)

list(APPEND ARROW_BUNDLED_STATIC_LIBS jemalloc::jemalloc)
set(jemalloc_VENDORED TRUE)
# For config.h.cmake
set(ARROW_JEMALLOC_VENDORED ${jemalloc_VENDORED})
endmacro()

if(ARROW_JEMALLOC)
resolve_dependency(jemalloc)
endif()

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -1889,6 +1904,8 @@ if(ARROW_MIMALLOC)
add_dependencies(toolchain mimalloc_ep)

list(APPEND ARROW_BUNDLED_STATIC_LIBS mimalloc::mimalloc)

set(mimalloc_VENDORED TRUE)
endif()

# ----------------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ set(ARROW_SRCS
vendored/double-conversion/diy-fp.cc
vendored/double-conversion/strtod.cc)

if(ARROW_JEMALLOC)
list(APPEND ARROW_SRCS memory_pool_jemalloc.cc)
endif()

append_avx2_src(util/bpacking_avx2.cc)
append_avx512_src(util/bpacking_avx512.cc)

Expand Down Expand Up @@ -325,10 +329,10 @@ set(ARROW_TESTING_SRCS
# (see https://gitlab.kitware.com/cmake/cmake/issues/19677)

set(_allocator_dependencies "") # Empty list
if(ARROW_JEMALLOC)
if(jemalloc_VENDORED)
list(APPEND _allocator_dependencies jemalloc_ep)
endif()
if(ARROW_MIMALLOC)
if(mimalloc_VENDORED)
list(APPEND _allocator_dependencies mimalloc_ep)
endif()

Expand Down
Loading