Skip to content

Commit cda77b0

Browse files
[Backport] 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 <roland.bosa@gmail.com>
1 parent c0ff2f5 commit cda77b0

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ set(USE_CAIRO ON CACHE BOOL "Add cairo support if available (for `store_ro_compo
3232
set(USE_CURL ON CACHE BOOL "Add curl support if available (for `store_ro_http_proxy.c` backend)")
3333
set(USE_MEMCACHED ON CACHE BOOL "Add memcached support if available (for `store_memcached.c` backend)")
3434
set(USE_RADOS ON CACHE BOOL "Add rados support if available (for `store_rados.c` backend)")
35+
set(MALLOC_LIB "libc" CACHE STRING "Memory Management Library for `renderd`")
36+
set_property(CACHE MALLOC_LIB PROPERTY STRINGS "libc" "jemalloc" "mimalloc" "tcmalloc")
3537

3638
#-----------------------------------------------------------------------------
3739
#
@@ -82,6 +84,21 @@ check_include_file(paths.h HAVE_PATHS_H)
8284
check_include_file(sys/cdefs.h HAVE_SYS_CDEFS_H)
8385
check_include_file(sys/loadavg.h HAVE_SYS_LOADAVG_H)
8486

87+
# Libraries
88+
if(NOT MALLOC_LIB STREQUAL "libc")
89+
message(STATUS "Using '${MALLOC_LIB}' for memory managment")
90+
if(MALLOC_LIB STREQUAL "jemalloc")
91+
# jemalloc (http://jemalloc.net)
92+
find_library(MALLOC_LIBRARY jemalloc REQUIRED)
93+
elseif(MALLOC_LIB STREQUAL "mimalloc")
94+
# mimalloc (https://github.com/microsoft/mimalloc)
95+
find_library(MALLOC_LIBRARY mimalloc REQUIRED)
96+
elseif(MALLOC_LIB STREQUAL "tcmalloc")
97+
# tcmalloc (https://github.com/google/tcmalloc)
98+
find_library(MALLOC_LIBRARY tcmalloc REQUIRED)
99+
endif()
100+
endif()
101+
85102
#-----------------------------------------------------------------------------
86103
#
87104
# Set variables

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ set(STORE_LIBRARIES
5757
${LIBRADOS_LIBRARIES}
5858
)
5959

60+
if(NOT MALLOC_LIB STREQUAL "libc")
61+
message(STATUS "Prepending '${MALLOC_LIBRARY}' to RENDER_LIBRARIES")
62+
list(PREPEND RENDER_LIBRARIES ${MALLOC_LIBRARY})
63+
endif()
64+
6065
#-----------------------------------------------------------------------------
6166
#
6267
# Installed targets

0 commit comments

Comments
 (0)