Add ability to use system jemalloc

Signed-off-by: Maytham Alsudany <maytha8thedev@gmail.com>
This commit is contained in:
Chris Lamb 2024-04-02 10:20:29 +03:00 committed by Drew DeVault
parent 5f400152aa
commit 8794d03e2b
7 changed files with 34 additions and 0 deletions

2
deps/Makefile vendored
View File

@ -39,7 +39,9 @@ distclean:
-(cd hiredict && $(MAKE) clean) > /dev/null || true
-(cd linenoise && $(MAKE) clean) > /dev/null || true
-(cd lua && $(MAKE) clean) > /dev/null || true
ifneq ($(USE_SYSTEM_JEMALLOC),yes)
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
endif
-(cd hdr_histogram && $(MAKE) clean) > /dev/null || true
-(cd fpconv && $(MAKE) clean) > /dev/null || true
-(rm -f .make-*)

View File

@ -266,10 +266,15 @@ ifeq ($(MALLOC),tcmalloc_minimal)
endif
ifeq ($(MALLOC),jemalloc)
ifeq ($(USE_SYSTEM_JEMALLOC),yes)
FINAL_CFLAGS+= -DUSE_JEMALLOC -I/usr/include/jemalloc/include
FINAL_LIBS := -ljemalloc $(FINAL_LIBS)
else
DEPENDENCY_TARGETS+= jemalloc
FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS)
endif
endif
# LIBSSL & LIBCRYPTO
LIBSSL_LIBS=

View File

@ -56,6 +56,10 @@ void bugReportEnd(int killViaSignal, int sig);
void logStackTrace(void *eip, int uplevel, int current_thread);
void sigalrmSignalHandler(int sig, siginfo_t *info, void *secret);
#if defined(USE_JEMALLOC) && (USE_SYSTEM_JEMALLOC == yes)
#define je_mallctl mallctl
#endif
/* ================================= Debugging ============================== */
/* Compute the sha1 of string at 's' with 'len' bytes long.

View File

@ -15,6 +15,11 @@
#define strtold(a,b) ((long double)strtod((a),(b)))
#endif
#if defined(USE_JEMALLOC) && (USE_SYSTEM_JEMALLOC == yes)
#define je_mallctl mallctl
#define je_malloc_stats_print malloc_stats_print
#endif
/* ===================== Creation and parsing of objects ==================== */
robj *createObject(int type, void *ptr) {

View File

@ -24,6 +24,10 @@
#include "sds.h"
#include "sdsalloc.h"
#if USE_SYSTEM_JEMALLOC == yes
#define je_nallocx nallocx
#endif
const char *SDS_NOINIT = "SDS_NOINIT";
static inline int sdsHdrSize(char type) {

View File

@ -56,6 +56,15 @@ void zlibc_free(void *ptr) {
#define free(ptr) tc_free(ptr)
/* Explicitly override malloc/free etc when using jemalloc. */
#elif defined(USE_JEMALLOC)
#if USE_SYSTEM_JEMALLOC == yes
#define malloc(size) malloc(size)
#define calloc(count,size) calloc(count,size)
#define realloc(ptr,size) realloc(ptr,size)
#define free(ptr) free(ptr)
#define mallocx(size,flags) mallocx(size,flags)
#define dallocx(ptr,flags) dallocx(ptr,flags)
#define je_mallctl mallctl
#else
#define malloc(size) je_malloc(size)
#define calloc(count,size) je_calloc(count,size)
#define realloc(ptr,size) je_realloc(ptr,size)
@ -63,6 +72,7 @@ void zlibc_free(void *ptr) {
#define mallocx(size,flags) je_mallocx(size,flags)
#define dallocx(ptr,flags) je_dallocx(ptr,flags)
#endif
#endif
#define update_zmalloc_stat_alloc(__n) atomicIncr(used_memory,(__n))
#define update_zmalloc_stat_free(__n) atomicDecr(used_memory,(__n))

View File

@ -27,7 +27,11 @@
#include <jemalloc/jemalloc.h>
#if (JEMALLOC_VERSION_MAJOR == 2 && JEMALLOC_VERSION_MINOR >= 1) || (JEMALLOC_VERSION_MAJOR > 2)
#define HAVE_MALLOC_SIZE 1
#if USE_SYSTEM_JEMALLOC == yes
#define zmalloc_size(p) malloc_usable_size(p)
#else
#define zmalloc_size(p) je_malloc_usable_size(p)
#endif
#else
#error "Newer version of jemalloc required"
#endif