diff --git a/deps/Makefile b/deps/Makefile index eb35c1e1f..bacc8f48e 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -53,6 +53,11 @@ linenoise: .make-prerequisites .PHONY: linenoise +.PHONY: memkind +memkind: + cd memkind && $(MAKE) + + ifeq ($(uname_S),SunOS) # Make isinf() available LUA_CFLAGS= -D__C99FEATURES__=1 diff --git a/deps/memkind/Makefile b/deps/memkind/Makefile new file mode 100644 index 000000000..af75dfaa4 --- /dev/null +++ b/deps/memkind/Makefile @@ -0,0 +1,12 @@ +export JE_PREFIX=jemk_ + +.PHONY: all +all: + cd src; ./build_jemalloc.sh + cd src; ./build.sh + +.PHONY: clean +clean: + cd src; make clean + + diff --git a/src/Makefile b/src/Makefile index 9820ffcc8..966da199d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -38,7 +38,7 @@ MALLOC=libc ifneq ($(uname_M),armv6l) ifneq ($(uname_M),armv7l) ifeq ($(uname_S),Linux) - MALLOC=jemalloc + MALLOC=memkind endif endif endif @@ -119,7 +119,7 @@ ifeq ($(uname_S),DragonFly) else # All the other OSes (notably Linux) FINAL_LDFLAGS+= -rdynamic - FINAL_LIBS+=-ldl -pthread -lrt -lmemkind + FINAL_LIBS+=-ldl -pthread -lrt endif endif endif @@ -145,6 +145,12 @@ ifeq ($(MALLOC),jemalloc) FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS) endif +ifeq ($(MALLOC),memkind) + DEPENDENCY_TARGETS+= memkind + FINAL_CFLAGS+= -DUSE_MEMKIND -I../deps/memkind/src/include + FINAL_LIBS := ../deps/memkind/src/.libs/libmemkind.a -lnuma $(FINAL_LIBS) +endif + REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL) diff --git a/src/defrag.c b/src/defrag.c index 7729c594c..d67b6e253 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -72,8 +72,8 @@ void* activeDefragAlloc(void *ptr) { /* move this allocation to a new allocation. * make sure not to use the thread cache. so that we don't get back the same * pointers we try to free */ - size = zmalloc_size(ptr, MALLOC_LOCAL); - newptr = zmalloc_no_tcache(size, MALLOC_LOCAL); + size = zmalloc_size(ptr); + newptr = zmalloc_no_tcache(size); memcpy(newptr, ptr, size); zfree_no_tcache(ptr); return newptr; diff --git a/src/zmalloc.c b/src/zmalloc.c index 7d307bad7..3af72417f 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -57,7 +57,12 @@ void zlibc_free(void *ptr) { #endif /* Explicitly override malloc/free etc when using tcmalloc. */ -#if defined(USE_TCMALLOC) +#if defined(USE_MEMKIND) +#define malloc(size, type) salloc(size, type) +#define calloc(count, size, type) scalloc(count, size, type) +#define realloc(ptr, size) srealloc(ptr, size) +#define free(ptr) sfree(ptr) +#elif defined(USE_TCMALLOC) #define malloc(size) tc_malloc(size) #define calloc(count,size) tc_calloc(count,size) #define realloc(ptr,size) tc_realloc(ptr,size) @@ -70,16 +75,6 @@ void zlibc_free(void *ptr) { #define mallocx(size,flags) je_mallocx(size,flags) #define dallocx(ptr,flags) je_dallocx(ptr,flags) #endif -#include "storage.h" -#undef malloc -#undef calloc -#undef realloc -#undef free -#define malloc(size, type) salloc(size, type) -#define calloc(count, size, type) scalloc(count, size, type) -#define realloc(ptr, size) srealloc(ptr, size) -#define free(ptr) sfree(ptr) -//#define zmalloc_size(ptr) (sizeof(ptr)) #define update_zmalloc_stat_alloc(__n) do { \ size_t _n = (__n); \ @@ -106,7 +101,12 @@ static void zmalloc_default_oom(size_t size) { static void (*zmalloc_oom_handler)(size_t) = zmalloc_default_oom; void *zmalloc(size_t size, enum MALLOC_CLASS class) { +#ifdef USE_MEMKIND void *ptr = malloc(size+PREFIX_SIZE, class); +#else + (void)class; + void *ptr = malloc(size+PREFIX_SIZE); +#endif if (!ptr) zmalloc_oom_handler(size); #ifdef HAVE_MALLOC_SIZE @@ -138,7 +138,12 @@ void zfree_no_tcache(void *ptr) { #endif void *zcalloc(size_t size, enum MALLOC_CLASS class) { +#ifdef USE_MEMKIND void *ptr = calloc(1, size+PREFIX_SIZE, class); +#else + (void)class; + void *ptr = calloc(1, size+PREFIX_SIZE); +#endif if (!ptr) zmalloc_oom_handler(size); #ifdef HAVE_MALLOC_SIZE diff --git a/src/zmalloc.h b/src/zmalloc.h index 0692e64c2..2ad37b905 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -35,9 +35,9 @@ #define __xstr(s) __str(s) #define __str(s) #s -#if 1 - #define ZMALLOC_LIB ("custom") - #include "storage.h" +#include "storage.h" +#if defined(USE_MEMKIND) + #define ZMALLOC_LIB ("memkind") #undef USE_JEMALLOC #define USE_MALLOC_CLASS 1 #elif defined(USE_TCMALLOC)