-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLASH-572] Use jemalloc instead of tcmalloc by default (#424)
* Use jemalloc instead of tcmalloc by default Signed-off-by: JaySon-Huang <[email protected]> * Fix build with libjemalloc * Use jemalloc in Linux and tcmalloc in MaxOS Signed-off-by: JaySon-Huang <[email protected]> * Fix bug: TMTContext should be free before background_pool Signed-off-by: JaySon-Huang <[email protected]> * Use of invalid iterator * Fix use after free in client-c Signed-off-by: JaySon-Huang <[email protected]>
- Loading branch information
1 parent
f98ab08
commit af17e0d
Showing
23 changed files
with
1,097 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
set(JEMALLOC_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/jemalloc) | ||
|
||
set(SRCS | ||
${JEMALLOC_SOURCE_DIR}/src/arena.c | ||
${JEMALLOC_SOURCE_DIR}/src/background_thread.c | ||
${JEMALLOC_SOURCE_DIR}/src/base.c | ||
${JEMALLOC_SOURCE_DIR}/src/bin.c | ||
${JEMALLOC_SOURCE_DIR}/src/bitmap.c | ||
${JEMALLOC_SOURCE_DIR}/src/ckh.c | ||
${JEMALLOC_SOURCE_DIR}/src/ctl.c | ||
${JEMALLOC_SOURCE_DIR}/src/div.c | ||
${JEMALLOC_SOURCE_DIR}/src/extent.c | ||
${JEMALLOC_SOURCE_DIR}/src/extent_dss.c | ||
${JEMALLOC_SOURCE_DIR}/src/extent_mmap.c | ||
${JEMALLOC_SOURCE_DIR}/src/hash.c | ||
${JEMALLOC_SOURCE_DIR}/src/hook.c | ||
${JEMALLOC_SOURCE_DIR}/src/jemalloc.c | ||
${JEMALLOC_SOURCE_DIR}/src/jemalloc_cpp.cpp | ||
${JEMALLOC_SOURCE_DIR}/src/large.c | ||
${JEMALLOC_SOURCE_DIR}/src/log.c | ||
${JEMALLOC_SOURCE_DIR}/src/malloc_io.c | ||
${JEMALLOC_SOURCE_DIR}/src/mutex.c | ||
${JEMALLOC_SOURCE_DIR}/src/mutex_pool.c | ||
${JEMALLOC_SOURCE_DIR}/src/nstime.c | ||
${JEMALLOC_SOURCE_DIR}/src/pages.c | ||
${JEMALLOC_SOURCE_DIR}/src/prng.c | ||
${JEMALLOC_SOURCE_DIR}/src/prof.c | ||
${JEMALLOC_SOURCE_DIR}/src/rtree.c | ||
${JEMALLOC_SOURCE_DIR}/src/sc.c | ||
${JEMALLOC_SOURCE_DIR}/src/stats.c | ||
${JEMALLOC_SOURCE_DIR}/src/sz.c | ||
${JEMALLOC_SOURCE_DIR}/src/tcache.c | ||
${JEMALLOC_SOURCE_DIR}/src/test_hooks.c | ||
${JEMALLOC_SOURCE_DIR}/src/ticker.c | ||
${JEMALLOC_SOURCE_DIR}/src/tsd.c | ||
${JEMALLOC_SOURCE_DIR}/src/witness.c | ||
) | ||
|
||
if(CMAKE_SYSTEM_NAME MATCHES "Darwin") | ||
list(APPEND SRCS ${JEMALLOC_SOURCE_DIR}/src/zone.c) | ||
endif() | ||
|
||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") | ||
endif () | ||
|
||
add_library(jemalloc STATIC ${SRCS}) | ||
|
||
target_include_directories(jemalloc PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/include_linux_x86_64) # jemalloc.h | ||
|
||
target_include_directories(jemalloc PRIVATE | ||
${JEMALLOC_SOURCE_DIR}/include) | ||
|
||
target_compile_definitions(jemalloc PRIVATE -DJEMALLOC_NO_PRIVATE_NAMESPACE) | ||
|
||
if (CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG") | ||
target_compile_definitions(jemalloc PRIVATE -DJEMALLOC_DEBUG=1 -DJEMALLOC_PROF=1) | ||
|
||
if (USE_UNWIND) | ||
target_compile_definitions (jemalloc PRIVATE -DJEMALLOC_PROF_LIBUNWIND=1) | ||
target_include_directories (jemalloc BEFORE PRIVATE ${UNWIND_INCLUDE_DIR}) | ||
target_link_libraries (jemalloc PRIVATE ${UNWIND_LIBRARY}) | ||
endif () | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
It allows to integrate JEMalloc into CMake project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <jemalloc/jemalloc_defs.h> | ||
#include <jemalloc/jemalloc_rename.h> | ||
#include <jemalloc/jemalloc_macros.h> | ||
#include <jemalloc/jemalloc_protos.h> | ||
#include <jemalloc/jemalloc_typedefs.h> | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Name mangling for public symbols is controlled by --with-mangling and | ||
* --with-jemalloc-prefix. With default settings the je_ prefix is stripped by | ||
* these macro definitions. | ||
*/ | ||
#ifndef JEMALLOC_NO_RENAME | ||
# define je_aligned_alloc aligned_alloc | ||
# define je_calloc calloc | ||
# define je_dallocx dallocx | ||
# define je_free free | ||
# define je_mallctl mallctl | ||
# define je_mallctlbymib mallctlbymib | ||
# define je_mallctlnametomib mallctlnametomib | ||
# define je_malloc malloc | ||
# define je_malloc_conf malloc_conf | ||
# define je_malloc_message malloc_message | ||
# define je_malloc_stats_print malloc_stats_print | ||
# define je_malloc_usable_size malloc_usable_size | ||
# define je_mallocx mallocx | ||
# define je_nallocx nallocx | ||
# define je_posix_memalign posix_memalign | ||
# define je_rallocx rallocx | ||
# define je_realloc realloc | ||
# define je_sallocx sallocx | ||
# define je_sdallocx sdallocx | ||
# define je_xallocx xallocx | ||
# define je_memalign memalign | ||
# define je_valloc valloc | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Here are pre-generated files from jemalloc on Linux x86_64. | ||
You can obtain these files by running ./autogen.sh inside jemalloc source directory. | ||
|
||
Added #define GNU_SOURCE | ||
Added JEMALLOC_OVERRIDE___POSIX_MEMALIGN because why not. | ||
Removed JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF because it's non standard. | ||
Removed JEMALLOC_PURGE_MADVISE_FREE because it's available only from Linux 4.5. |
Oops, something went wrong.