From 8c3c57cd54a05b34cb80106f3a31f256dc5c887c Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Wed, 13 Sep 2023 00:21:20 -0500 Subject: [PATCH 1/4] fix support for je/mi malloc and the mallocallocator --- CMakeLists.txt | 2 ++ include/tscore/ink_config.h.cmake.in | 2 ++ include/tscore/ink_memory.h | 4 ++++ plugins/experimental/memory_profile/memory_profile.cc | 4 +--- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c871c599039..5f5b5a8b686 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ option(BUILD_REGRESSION_TESTING "Build regression tests (default ON)" ON) option(BUILD_EXPERIMENTAL_PLUGINS "Build the experimental plugins (default OFF)") set(DEFAULT_STACK_SIZE 1048576 CACHE STRING "Default stack size (default 1048576)") option(ENABLE_FAST_SDK "Use fast SDK APIs (default OFF)") +option(ENABLE_MALLOC_ALLOCATOR "Use direct malloc allocator over freelist allocator (default OFF)") option(ENABLE_DOCS "Build docs (default OFF)") option(ENABLE_DISK_FAILURE_TESTS "Build disk failure tests (enables AIO fault injection, default OFF)" OFF) if(ENABLE_DISK_FAILURE_TESTS) @@ -258,6 +259,7 @@ if(ENABLE_ASAN) add_link_options(-fsanitize=address) endif() +set(TS_USE_MALLOC_ALLOCATOR ${ENABLE_MALLOC_ALLOCATOR}) find_package(ZLIB REQUIRED) # ncurses is used in traffic_top diff --git a/include/tscore/ink_config.h.cmake.in b/include/tscore/ink_config.h.cmake.in index 7a0a300f0c1..e3312c031b8 100644 --- a/include/tscore/ink_config.h.cmake.in +++ b/include/tscore/ink_config.h.cmake.in @@ -125,6 +125,7 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@; #cmakedefine01 TS_HAS_IN6_IS_ADDR_UNSPECIFIED #cmakedefine01 TS_HAS_IP_TOS #cmakedefine01 TS_HAS_JEMALLOC +#cmakedefine01 TS_HAS_MIMALLOC #cmakedefine01 TS_HAS_PROFILER #cmakedefine01 TS_HAS_QUICHE #cmakedefine01 TS_HAS_SO_MARK @@ -139,6 +140,7 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@; #cmakedefine01 TS_USE_HWLOC #cmakedefine01 TS_USE_KQUEUE #cmakedefine01 TS_USE_LINUX_IO_URING +#cmakedefine01 TS_USE_MALLOC_ALLOCATOR #cmakedefine01 TS_USE_POSIX_CAP #cmakedefine01 TS_USE_QUIC #cmakedefine01 TS_USE_REMOTE_UNWINDING diff --git a/include/tscore/ink_memory.h b/include/tscore/ink_memory.h index 3dbac7b75a4..a7acbbc3f40 100644 --- a/include/tscore/ink_memory.h +++ b/include/tscore/ink_memory.h @@ -49,7 +49,11 @@ #endif #if TS_HAS_JEMALLOC +#if __has_include() #include +#else +#include +#endif #elif TS_HAS_MIMALLOC #include #elif HAVE_MALLOC_H diff --git a/plugins/experimental/memory_profile/memory_profile.cc b/plugins/experimental/memory_profile/memory_profile.cc index 84f91230160..6d25e76401b 100644 --- a/plugins/experimental/memory_profile/memory_profile.cc +++ b/plugins/experimental/memory_profile/memory_profile.cc @@ -33,9 +33,7 @@ #include #include #include -#if TS_HAS_JEMALLOC -#include -#endif +#include #define PLUGIN_NAME "memory_profile" From 3ace3427e834ce7e91a908f349d405ba6a526c22 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Wed, 20 Sep 2023 09:30:09 -0500 Subject: [PATCH 2/4] also fix includes for jemiallocator --- include/tscore/JeMiAllocator.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/tscore/JeMiAllocator.h b/include/tscore/JeMiAllocator.h index b7b35ee4bb9..3976778d0b0 100644 --- a/include/tscore/JeMiAllocator.h +++ b/include/tscore/JeMiAllocator.h @@ -32,7 +32,11 @@ #include #if TS_HAS_JEMALLOC +#if __has_include() #include +#else +#include +#endif #if (JEMALLOC_VERSION_MAJOR == 0) #error jemalloc has bogus version #endif From bd792dffec16f83a2918767c81c2b0a76c86b781 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Wed, 20 Sep 2023 10:23:38 -0500 Subject: [PATCH 3/4] fix target for linking jemalloc --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f5b5a8b686..93d6c39023d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,7 +230,7 @@ if(TS_HAS_JEMALLOC AND TS_HAS_MIMALLOC) endif() if(TS_HAS_JEMALLOC) - link_libraries(jemalloc) + link_libraries(jemalloc::jemalloc) elseif(TS_HAS_MIMALLOC) link_libraries(mimalloc) endif() From 2f10b2d02f1995113113b45b431ab7522642d2ae Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Mon, 25 Sep 2023 11:38:32 -0500 Subject: [PATCH 4/4] restore default off to jemalloc auto_option --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93d6c39023d..78a37e879f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,12 +51,13 @@ include(AutoOptionHelpers) auto_option(HWLOC FEATURE_VAR TS_USE_HWLOC PACKAGE_DEPENDS hwloc) auto_option(JEMALLOC FEATURE_VAR TS_HAS_JEMALLOC + DEFAULT OFF PACKAGE_DEPENDS jemalloc ) auto_option(MIMALLOC FEATURE_VAR TS_HAS_MIMALLOC - PACKAGE_DEPENDS mimalloc DEFAULT OFF + PACKAGE_DEPENDS mimalloc ) auto_option(LUAJIT PACKAGE_DEPENDS LuaJIT) auto_option(UNWIND FEATURE_VAR TS_USE_REMOTE_UNWINDING PACKAGE_DEPENDS unwind)