1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
From: Chris Lamb <lamby@debian.org>
From: Maytham Alsudany <maytha8thedev@gmail.com>
Subject: Add support for USE_SYSTEM_JEMALLOC flag.
Forwarded: https://codeberg.org/redict/redict/pulls/40
Applied-Upstream: https://codeberg.org/redict/redict/commit/5defea5b98
deps/Makefile | 2 ++
src/Makefile | 8 +++++++-
src/debug.c | 12 ++++++++----
src/object.c | 7 ++++++-
src/sds.c | 4 ++++
src/zmalloc.c | 10 ++++++++++
src/zmalloc.h | 4 ++++
7 files changed, 41 insertions(+), 6 deletions(-)
@@ -39,7 +39,9 @@
-(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-*)
@@ -266,10 +266,16 @@
endif
ifeq ($(MALLOC),jemalloc)
+ FINAL_CFLAGS+= -DUSE_JEMALLOC
+ifeq ($(USE_SYSTEM_JEMALLOC),yes)
+ FINAL_CFLAGS+= -DUSE_SYSTEM_JEMALLOC -I/usr/include/jemalloc/include
+ FINAL_LIBS := -ljemalloc $(FINAL_LIBS)
+else
DEPENDENCY_TARGETS+= jemalloc
- FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
+ FINAL_CFLAGS+= -I../deps/jemalloc/include
FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS)
endif
+endif
# LIBSSL & LIBCRYPTO
LIBSSL_LIBS=
@@ -56,6 +56,10 @@
void logStackTrace(void *eip, int uplevel, int current_thread);
void sigalrmSignalHandler(int sig, siginfo_t *info, void *secret);
+#if defined(USE_JEMALLOC) && defined(USE_SYSTEM_JEMALLOC)
+#define je_mallctl mallctl
+#endif
+
/*
/* Compute the sha1 of string at 's' with 'len' bytes long.
@@ -15,6 +15,11 @@
#define strtold(a,b) ((long double)strtod((a),(b)))
#endif
+#if defined(USE_JEMALLOC) && defined(USE_SYSTEM_JEMALLOC)
+#define je_mallctl mallctl
+#define je_malloc_stats_print malloc_stats_print
+#endif
+
/*
robj *createObject(int type, void *ptr) {
@@ -24,6 +24,10 @@
#include "sds.h"
#include "sdsalloc.h"
+#if defined(USE_JEMALLOC) && defined(USE_SYSTEM_JEMALLOC)
+#define je_nallocx nallocx
+#endif
+
const char *SDS_NOINIT = "SDS_NOINIT";
static inline int sdsHdrSize(char type) {
@@ -56,6 +56,15 @@
#define free(ptr) tc_free(ptr)
/* Explicitly override malloc/free etc when using jemalloc. */
#elif defined(USE_JEMALLOC)
+#if defined(USE_SYSTEM_JEMALLOC)
+#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 @@
#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))
@@ -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 defined(USE_SYSTEM_JEMALLOC)
+#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
|