Skip to content

Commit c160b25

Browse files
committed
Drop support for unbundled jemalloc
unbundled jemalloc cannot be used, since it includes jemalloc_cpp.o that contains new/delete overrides, so as clickhouse [1]: ld.lld: error: duplicate symbol: operator delete(void*, unsigned long) >>> defined at new_delete.cpp:147 (../src/Common/new_delete.cpp:147) >>> new_delete.cpp.o:(operator delete(void*, unsigned long)) in archive src/libclickhouse_new_delete.a >>> defined at jemalloc_cpp.o:(.text+0x160) in archive /usr/lib/x86_64-linux-gnu/libjemalloc.a [1]: https://clickhouse-builds.s3.yandex.net/15828/35335f07dbf8cab89b4188a674b033c28409dc7b/clickhouse_build_check/build_log_793952627_1602401325.txt
1 parent 35335f0 commit c160b25

File tree

1 file changed

+102
-153
lines changed

1 file changed

+102
-153
lines changed

contrib/jemalloc-cmake/CMakeLists.txt

Lines changed: 102 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ else()
99
endif ()
1010

1111
if (NOT ENABLE_JEMALLOC)
12-
if(USE_INTERNAL_JEMALLOC_LIBRARY)
13-
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't use internal jemalloc with ENABLE_JEMALLOC=OFF")
14-
endif()
15-
1612
add_library(jemalloc INTERFACE)
1713
target_compile_definitions(jemalloc INTERFACE USE_JEMALLOC=0)
1814

@@ -24,164 +20,117 @@ if (NOT OS_LINUX)
2420
message (WARNING "jemalloc support on non-linux is EXPERIMENTAL")
2521
endif()
2622

27-
option (USE_INTERNAL_JEMALLOC_LIBRARY "Use internal jemalloc library" ${NOT_UNBUNDLED})
28-
29-
if (NOT USE_INTERNAL_JEMALLOC_LIBRARY)
30-
find_library(LIBRARY_JEMALLOC jemalloc)
31-
find_path(INCLUDE_JEMALLOC jemalloc/jemalloc.h)
32-
33-
if (LIBRARY_JEMALLOC AND INCLUDE_JEMALLOC)
34-
set(EXTERNAL_JEMALLOC_LIBRARY_FOUND 1)
35-
36-
set(THREADS_PREFER_PTHREAD_FLAG ON)
37-
find_package(Threads)
38-
39-
set(JEMALLOC_LIBRARIES ${LIBRARY_JEMALLOC} Threads::Threads dl)
40-
41-
set (CMAKE_REQUIRED_LIBRARIES ${JEMALLOC_LIBRARIES})
42-
set (CMAKE_REQUIRED_INCLUDES ${INCLUDE_JEMALLOC})
43-
check_cxx_source_compiles (
44-
"
45-
#include <jemalloc/jemalloc.h>
46-
47-
int main() {
48-
free(mallocx(1, 0));
49-
}
50-
"
51-
EXTERNAL_JEMALLOC_LIBRARY_WORKS
52-
)
53-
54-
if (EXTERNAL_JEMALLOC_LIBRARY_WORKS)
55-
add_library (jemalloc INTERFACE)
56-
set_property (TARGET jemalloc PROPERTY INTERFACE_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
57-
set_property (TARGET jemalloc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INCLUDE_JEMALLOC})
58-
else()
59-
message (${RECONFIGURE_MESSAGE_LEVEL} "External jemalloc is unusable: ${LIBRARY_JEMALLOC} ${INCLUDE_JEMALLOC}")
60-
endif ()
61-
62-
else()
63-
set(EXTERNAL_JEMALLOC_LIBRARY_FOUND 0)
64-
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find system jemalloc")
65-
endif()
23+
if (OS_LINUX)
24+
# ThreadPool select job randomly, and there can be some threads that had been
25+
# performed some memory heavy task before and will be inactive for some time,
26+
# but until it will became active again, the memory will not be freed since by
27+
# default each thread has it's own arena, but there should be not more then
28+
# 4*CPU arenas (see opt.nareans description).
29+
#
30+
# By enabling percpu_arena number of arenas limited to number of CPUs and hence
31+
# this problem should go away.
32+
#
33+
# muzzy_decay_ms -- use MADV_FREE when available on newer Linuxes, to
34+
# avoid spurious latencies and additional work associated with
35+
# MADV_DONTNEED. See
36+
# https://github.com/ClickHouse/ClickHouse/issues/11121 for motivation.
37+
set (JEMALLOC_CONFIG_MALLOC_CONF "percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:10000")
38+
else()
39+
set (JEMALLOC_CONFIG_MALLOC_CONF "oversize_threshold:0,muzzy_decay_ms:10000")
40+
endif()
41+
# CACHE variable is empty, to allow changing defaults without necessity
42+
# to purge cache
43+
set (JEMALLOC_CONFIG_MALLOC_CONF_OVERRIDE "" CACHE STRING "Change default configuration string of JEMalloc" )
44+
if (JEMALLOC_CONFIG_MALLOC_CONF_OVERRIDE)
45+
set (JEMALLOC_CONFIG_MALLOC_CONF "${JEMALLOC_CONFIG_MALLOC_CONF_OVERRIDE}")
46+
endif()
47+
message (STATUS "jemalloc malloc_conf: ${JEMALLOC_CONFIG_MALLOC_CONF}")
48+
49+
set (LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/jemalloc")
50+
51+
set (SRCS
52+
${LIBRARY_DIR}/src/arena.c
53+
${LIBRARY_DIR}/src/background_thread.c
54+
${LIBRARY_DIR}/src/base.c
55+
${LIBRARY_DIR}/src/bin.c
56+
${LIBRARY_DIR}/src/bitmap.c
57+
${LIBRARY_DIR}/src/ckh.c
58+
${LIBRARY_DIR}/src/ctl.c
59+
${LIBRARY_DIR}/src/div.c
60+
${LIBRARY_DIR}/src/extent.c
61+
${LIBRARY_DIR}/src/extent_dss.c
62+
${LIBRARY_DIR}/src/extent_mmap.c
63+
${LIBRARY_DIR}/src/hash.c
64+
${LIBRARY_DIR}/src/hook.c
65+
${LIBRARY_DIR}/src/jemalloc.c
66+
${LIBRARY_DIR}/src/large.c
67+
${LIBRARY_DIR}/src/log.c
68+
${LIBRARY_DIR}/src/malloc_io.c
69+
${LIBRARY_DIR}/src/mutex.c
70+
${LIBRARY_DIR}/src/mutex_pool.c
71+
${LIBRARY_DIR}/src/nstime.c
72+
${LIBRARY_DIR}/src/pages.c
73+
${LIBRARY_DIR}/src/prng.c
74+
${LIBRARY_DIR}/src/prof.c
75+
${LIBRARY_DIR}/src/rtree.c
76+
${LIBRARY_DIR}/src/sc.c
77+
${LIBRARY_DIR}/src/stats.c
78+
${LIBRARY_DIR}/src/sz.c
79+
${LIBRARY_DIR}/src/tcache.c
80+
${LIBRARY_DIR}/src/test_hooks.c
81+
${LIBRARY_DIR}/src/ticker.c
82+
${LIBRARY_DIR}/src/tsd.c
83+
${LIBRARY_DIR}/src/witness.c
84+
${LIBRARY_DIR}/src/safety_check.c
85+
)
86+
if (OS_DARWIN)
87+
list(APPEND SRCS ${LIBRARY_DIR}/src/zone.c)
6688
endif ()
6789

68-
if (NOT EXTERNAL_JEMALLOC_LIBRARY_FOUND OR NOT EXTERNAL_JEMALLOC_LIBRARY_WORKS)
69-
set(USE_INTERNAL_JEMALLOC_LIBRARY 1)
70-
71-
if (OS_LINUX)
72-
# ThreadPool select job randomly, and there can be some threads that had been
73-
# performed some memory heavy task before and will be inactive for some time,
74-
# but until it will became active again, the memory will not be freed since by
75-
# default each thread has it's own arena, but there should be not more then
76-
# 4*CPU arenas (see opt.nareans description).
77-
#
78-
# By enabling percpu_arena number of arenas limited to number of CPUs and hence
79-
# this problem should go away.
80-
#
81-
# muzzy_decay_ms -- use MADV_FREE when available on newer Linuxes, to
82-
# avoid spurious latencies and additional work associated with
83-
# MADV_DONTNEED. See
84-
# https://github.com/ClickHouse/ClickHouse/issues/11121 for motivation.
85-
set (JEMALLOC_CONFIG_MALLOC_CONF "percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:10000")
86-
else()
87-
set (JEMALLOC_CONFIG_MALLOC_CONF "oversize_threshold:0,muzzy_decay_ms:10000")
88-
endif()
89-
# CACHE variable is empty, to allow changing defaults without necessity
90-
# to purge cache
91-
set (JEMALLOC_CONFIG_MALLOC_CONF_OVERRIDE "" CACHE STRING "Change default configuration string of JEMalloc" )
92-
if (JEMALLOC_CONFIG_MALLOC_CONF_OVERRIDE)
93-
set (JEMALLOC_CONFIG_MALLOC_CONF "${JEMALLOC_CONFIG_MALLOC_CONF_OVERRIDE}")
94-
endif()
95-
message (STATUS "jemalloc malloc_conf: ${JEMALLOC_CONFIG_MALLOC_CONF}")
96-
97-
set (LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/jemalloc")
98-
99-
set (SRCS
100-
${LIBRARY_DIR}/src/arena.c
101-
${LIBRARY_DIR}/src/background_thread.c
102-
${LIBRARY_DIR}/src/base.c
103-
${LIBRARY_DIR}/src/bin.c
104-
${LIBRARY_DIR}/src/bitmap.c
105-
${LIBRARY_DIR}/src/ckh.c
106-
${LIBRARY_DIR}/src/ctl.c
107-
${LIBRARY_DIR}/src/div.c
108-
${LIBRARY_DIR}/src/extent.c
109-
${LIBRARY_DIR}/src/extent_dss.c
110-
${LIBRARY_DIR}/src/extent_mmap.c
111-
${LIBRARY_DIR}/src/hash.c
112-
${LIBRARY_DIR}/src/hook.c
113-
${LIBRARY_DIR}/src/jemalloc.c
114-
${LIBRARY_DIR}/src/large.c
115-
${LIBRARY_DIR}/src/log.c
116-
${LIBRARY_DIR}/src/malloc_io.c
117-
${LIBRARY_DIR}/src/mutex.c
118-
${LIBRARY_DIR}/src/mutex_pool.c
119-
${LIBRARY_DIR}/src/nstime.c
120-
${LIBRARY_DIR}/src/pages.c
121-
${LIBRARY_DIR}/src/prng.c
122-
${LIBRARY_DIR}/src/prof.c
123-
${LIBRARY_DIR}/src/rtree.c
124-
${LIBRARY_DIR}/src/sc.c
125-
${LIBRARY_DIR}/src/stats.c
126-
${LIBRARY_DIR}/src/sz.c
127-
${LIBRARY_DIR}/src/tcache.c
128-
${LIBRARY_DIR}/src/test_hooks.c
129-
${LIBRARY_DIR}/src/ticker.c
130-
${LIBRARY_DIR}/src/tsd.c
131-
${LIBRARY_DIR}/src/witness.c
132-
${LIBRARY_DIR}/src/safety_check.c
133-
)
134-
if (OS_DARWIN)
135-
list(APPEND SRCS ${LIBRARY_DIR}/src/zone.c)
136-
endif ()
137-
138-
add_library(jemalloc ${SRCS})
139-
target_include_directories(jemalloc PRIVATE ${LIBRARY_DIR}/include)
140-
target_include_directories(jemalloc SYSTEM PUBLIC include)
141-
142-
set (JEMALLOC_INCLUDE_PREFIX)
143-
# OS_
144-
if (OS_LINUX)
145-
set (JEMALLOC_INCLUDE_PREFIX "include_linux")
146-
elseif (OS_FREEBSD)
147-
set (JEMALLOC_INCLUDE_PREFIX "include_freebsd")
148-
elseif (OS_DARWIN)
149-
set (JEMALLOC_INCLUDE_PREFIX "include_darwin")
150-
else ()
151-
message (FATAL_ERROR "internal jemalloc: This OS is not supported")
152-
endif ()
153-
# ARCH_
154-
if (ARCH_AMD64)
155-
set(JEMALLOC_INCLUDE_PREFIX "${JEMALLOC_INCLUDE_PREFIX}_x86_64")
156-
elseif (ARCH_ARM)
157-
set(JEMALLOC_INCLUDE_PREFIX "${JEMALLOC_INCLUDE_PREFIX}_aarch64")
158-
else ()
159-
message (FATAL_ERROR "internal jemalloc: This arch is not supported")
160-
endif ()
90+
add_library(jemalloc ${SRCS})
91+
target_include_directories(jemalloc PRIVATE ${LIBRARY_DIR}/include)
92+
target_include_directories(jemalloc SYSTEM PUBLIC include)
93+
94+
set (JEMALLOC_INCLUDE_PREFIX)
95+
# OS_
96+
if (OS_LINUX)
97+
set (JEMALLOC_INCLUDE_PREFIX "include_linux")
98+
elseif (OS_FREEBSD)
99+
set (JEMALLOC_INCLUDE_PREFIX "include_freebsd")
100+
elseif (OS_DARWIN)
101+
set (JEMALLOC_INCLUDE_PREFIX "include_darwin")
102+
else ()
103+
message (FATAL_ERROR "internal jemalloc: This OS is not supported")
104+
endif ()
105+
# ARCH_
106+
if (ARCH_AMD64)
107+
set(JEMALLOC_INCLUDE_PREFIX "${JEMALLOC_INCLUDE_PREFIX}_x86_64")
108+
elseif (ARCH_ARM)
109+
set(JEMALLOC_INCLUDE_PREFIX "${JEMALLOC_INCLUDE_PREFIX}_aarch64")
110+
else ()
111+
message (FATAL_ERROR "internal jemalloc: This arch is not supported")
112+
endif ()
161113

162-
configure_file(${JEMALLOC_INCLUDE_PREFIX}/jemalloc/internal/jemalloc_internal_defs.h.in
163-
${JEMALLOC_INCLUDE_PREFIX}/jemalloc/internal/jemalloc_internal_defs.h)
164-
target_include_directories(jemalloc SYSTEM PRIVATE
165-
${CMAKE_CURRENT_BINARY_DIR}/${JEMALLOC_INCLUDE_PREFIX}/jemalloc/internal)
114+
configure_file(${JEMALLOC_INCLUDE_PREFIX}/jemalloc/internal/jemalloc_internal_defs.h.in
115+
${JEMALLOC_INCLUDE_PREFIX}/jemalloc/internal/jemalloc_internal_defs.h)
116+
target_include_directories(jemalloc SYSTEM PRIVATE
117+
${CMAKE_CURRENT_BINARY_DIR}/${JEMALLOC_INCLUDE_PREFIX}/jemalloc/internal)
166118

167-
target_compile_definitions(jemalloc PRIVATE -DJEMALLOC_NO_PRIVATE_NAMESPACE)
119+
target_compile_definitions(jemalloc PRIVATE -DJEMALLOC_NO_PRIVATE_NAMESPACE)
168120

169-
if (CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG")
170-
target_compile_definitions(jemalloc PRIVATE -DJEMALLOC_DEBUG=1 -DJEMALLOC_PROF=1)
121+
if (CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG")
122+
target_compile_definitions(jemalloc PRIVATE -DJEMALLOC_DEBUG=1 -DJEMALLOC_PROF=1)
171123

172-
if (USE_UNWIND)
173-
target_compile_definitions (jemalloc PRIVATE -DJEMALLOC_PROF_LIBUNWIND=1)
174-
target_link_libraries (jemalloc PRIVATE unwind)
175-
endif ()
124+
if (USE_UNWIND)
125+
target_compile_definitions (jemalloc PRIVATE -DJEMALLOC_PROF_LIBUNWIND=1)
126+
target_link_libraries (jemalloc PRIVATE unwind)
176127
endif ()
177-
178-
target_compile_options(jemalloc PRIVATE -Wno-redundant-decls)
179-
# for RTLD_NEXT
180-
target_compile_options(jemalloc PRIVATE -D_GNU_SOURCE)
181-
182-
set (USE_INTERNAL_JEMALLOC_LIBRARY 1)
183128
endif ()
184129

130+
target_compile_options(jemalloc PRIVATE -Wno-redundant-decls)
131+
# for RTLD_NEXT
132+
target_compile_options(jemalloc PRIVATE -D_GNU_SOURCE)
133+
185134
set_property(TARGET jemalloc APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS USE_JEMALLOC=1)
186135
if (MAKE_STATIC_LIBRARIES)
187136
# To detect whether we need to register jemalloc for osx as default zone.

0 commit comments

Comments
 (0)