Properly integrate memkind

Former-commit-id: 82372cbce84a009ef162a611bb91c7ed67acc9e9
This commit is contained in:
John Sully 2019-02-01 15:21:00 -05:00
parent 833006226d
commit bb9f3eeb13
6 changed files with 46 additions and 18 deletions

5
deps/Makefile vendored
View File

@ -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

12
deps/memkind/Makefile vendored Normal file
View File

@ -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

View File

@ -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)

View File

@ -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;

View File

@ -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

View File

@ -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)