From f36e38a2a4d3e3a877ac02adc14ba42389a971e9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 11 Apr 2016 11:23:47 +0100 Subject: [PATCH] [Feature] Allow building rspamd with jemalloc --- CMakeLists.txt | 6 ++++++ config.h.in | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e111ec3aa..d8e39300a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ OPTION(ENABLE_CLANG_PLUGIN "Enable clang static analysing plugin [default: OFF]" OPTION(ENABLE_HYPERSCAN "Enable hyperscan for fast regexp processing [default: OFF]" OFF) OPTION(ENABLE_FANN "Enable fann for neural network plugin [default: OFF]" OFF) OPTION(ENABLE_PCRE2 "Enable pcre2 instead of pcre [default: OFF]" OFF) +OPTION(ENABLE_JEMALLOC "Build rspamd with jemalloc allocator [default: OFF]" OFF) INCLUDE(FindArch.cmake) TARGET_ARCHITECTURE(ARCH) @@ -653,6 +654,11 @@ ELSE() ProcessPackage(PCRE LIBRARY pcre INCLUDE pcre.h INCLUDE_SUFFIXES include/pcre ROOT ${PCRE_ROOT_DIR} MODULES pcre libpcre pcre3 libpcre3) ENDIF() +IF(ENABLE_JEMALLOC MATCHES "ON") + ProcessPackage(JEMALLOC LIBRARY jemalloc INCLUDE jemalloc.h INCLUDE_SUFFIXES include/jemalloc + ROOT ${JEMALLOC_ROOT_DIR} MODULES jemalloc) + SET(WITH_JEMALLOC "1") +ENDIF() ProcessPackage(GMIME LIBRARY gmime-2.6 gmime-2.4 gmime-2.2 gmime-2 INCLUDE gmime.h INCLUDE_SUFFIXES include/gmime ROOT ${GMIME_ROOT_DIR} MODULES gmime-2.6 gmime-2.4 gmime-2.0) ProcessPackage(LIBEVENT LIBRARY event INCLUDE event.h INCLUDE_SUFFIXES include/event diff --git a/config.h.in b/config.h.in index 50a17c0a5..2b553efe3 100644 --- a/config.h.in +++ b/config.h.in @@ -122,6 +122,7 @@ #cmakedefine WITH_GPERF_TOOLS 1 #cmakedefine WITH_HIREDIS 1 #cmakedefine WITH_HYPERSCAN 1 +#cmakedefine WITH_JEMALLOC 1 #cmakedefine WITH_JUDY 1 #cmakedefine WITH_LUA 1 #cmakedefine WITH_PCRE2 1 @@ -244,6 +245,10 @@ #include #endif +#ifdef WITH_JEMALLOC +#include +#endif + /* stdio */ #ifdef HAVE_STDIO_H #include @@ -330,4 +335,12 @@ typedef off_t goffset; extern uint64_t ottery_rand_uint64(void); #define UCL_RANDOM_FUNCTION ottery_rand_uint64() +/* Disable slab allocator if jemalloc is already in the system */ +#if defined(WITH_JEMALLOC) || defined(__FreeBSD__) || \ + (defined(__NetBSD__) && __NetBSD_Version__ >= 500000000) + #define g_slice_alloc(sz) g_malloc(sz) + #define g_slice_alloc0(sz) g_malloc0(sz) + #define g_slice_free1(sz, p) g_free(p) +#endif + #endif -- 2.39.5