From 0478a1b76147f851361d14eaaea0d0f3f9fe4dbf Mon Sep 17 00:00:00 2001 From: Hummeltech <6109326+hummeltech@users.noreply.github.com> Date: Fri, 28 Jun 2024 18:08:49 -0700 Subject: [PATCH] Allow linking alternate memory management implementations (#454) With new `CMake CACHE` entry `MALLOC_LIB`, supporting the following values: * `libc` (default): Use the system's implementation * `jemalloc`: Use [jemalloc](http://jemalloc.net) * `mimalloc`: Use [mimalloc](https://github.com/microsoft/mimalloc) * `tcmalloc`: Use [tcmalloc](https://github.com/google/tcmalloc) Co-authored-by: Roland Bosa --- CMakeLists.txt | 16 ++++++++++++++++ src/CMakeLists.txt | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac57efb5..81fe49b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ set(USE_CAIRO ON CACHE BOOL "Add cairo support if available (for `store_ro_compo set(USE_CURL ON CACHE BOOL "Add curl support if available (for `store_ro_http_proxy.c` backend)") set(USE_MEMCACHED ON CACHE BOOL "Add memcached support if available (for `store_memcached.c` backend)") set(USE_RADOS ON CACHE BOOL "Add rados support if available (for `store_rados.c` backend)") +set(MALLOC_LIB "libc" CACHE STRING "Memory Management Library for `renderd`") +set_property(CACHE MALLOC_LIB PROPERTY STRINGS "libc" "jemalloc" "mimalloc" "tcmalloc") #----------------------------------------------------------------------------- # @@ -90,6 +92,20 @@ if(NOT HAVE_POW) find_library(MATH_LIBRARY m REQUIRED) endif() +if(NOT MALLOC_LIB STREQUAL "libc") + message(STATUS "Using '${MALLOC_LIB}' for memory managment") + if(MALLOC_LIB STREQUAL "jemalloc") + # jemalloc (http://jemalloc.net) + find_library(MALLOC_LIBRARY jemalloc REQUIRED) + elseif(MALLOC_LIB STREQUAL "mimalloc") + # mimalloc (https://github.com/microsoft/mimalloc) + find_library(MALLOC_LIBRARY mimalloc REQUIRED) + elseif(MALLOC_LIB STREQUAL "tcmalloc") + # tcmalloc (https://github.com/google/tcmalloc) + find_library(MALLOC_LIBRARY tcmalloc REQUIRED) + endif() +endif() + #----------------------------------------------------------------------------- # # Set variables diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e7e62d6d..046e49ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,7 +41,6 @@ set(RENDER_LIBRARIES ${COMMON_LIBRARIES} ${INIPARSER_LIBRARIES} ${MATH_LIBRARY} - Threads::Threads ) set(STORE_SRCS @@ -61,6 +60,11 @@ set(STORE_LIBRARIES ${LIBRADOS_LIBRARIES} ) +if(NOT MALLOC_LIB STREQUAL "libc") + message(STATUS "Prepending '${MALLOC_LIBRARY}' to RENDER_LIBRARIES") + list(PREPEND RENDER_LIBRARIES ${MALLOC_LIBRARY}) +endif() + #----------------------------------------------------------------------------- # # Installed targets