Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ endif

ifeq ($(MALLOC),memkind)
FINAL_CFLAGS+= -DUSE_MEMKIND
FINAL_LIBS+= -lmemkind -ldaxctl
FINAL_LIBS+= -lmemkind -ldaxctl -lpmem
endif

REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
Expand Down
4 changes: 2 additions & 2 deletions src/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static sds sdsnewlenPM(const void *init, size_t initlen) {
if (init==SDS_NOINIT)
init = NULL;
else if (!init)
memset(sh, 0, hdrlen+initlen+1);
zmemset_pmem(sh, 0, hdrlen+initlen+1);
if (sh == NULL) return NULL;
s = (char*)sh+hdrlen;
fp = ((unsigned char*)s)-1;
Expand Down Expand Up @@ -215,7 +215,7 @@ static sds sdsnewlenPM(const void *init, size_t initlen) {
}
}
if (initlen && init)
memcpy(s, init, initlen);
zmemcpy_pmem(s, init, initlen);
s[initlen] = '\0';
return s;
}
Expand Down
23 changes: 23 additions & 0 deletions src/zmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void zlibc_free(void *ptr) {
#define dallocx(ptr,flags) je_dallocx(ptr,flags)
#elif defined(USE_MEMKIND)
#include <errno.h>
#include <libpmem.h>
#define malloc(size) memkind_malloc(MEMKIND_DEFAULT,size)
#define calloc(count,size) memkind_calloc(MEMKIND_DEFAULT,count,size)
#define realloc(ptr,size) memkind_realloc(NULL,ptr,size)
Expand Down Expand Up @@ -103,6 +104,20 @@ void *zmalloc_pmem(size_t size) {
zmalloc_pmem_not_available();
return NULL;
}
void *zmemcpy_pmem(void *dst, const void *src, size_t num) {
(void)(dst);
(void)(src);
(void)(num);
zmalloc_pmem_not_available();
return NULL;
}
void *zmemset_pmem(void *ptr, int value, size_t num) {
(void)(ptr);
(void)(value);
(void)(num);
zmalloc_pmem_not_available();
return NULL;
}
#endif

#define update_zmalloc_stat_alloc(__n) do { \
Expand Down Expand Up @@ -176,6 +191,14 @@ void *zmalloc_pmem(size_t size) {
return (char*)ptr+PREFIX_SIZE;
#endif
}

void *zmemcpy_pmem(void *dst, const void *src, size_t num) {
return pmem_memcpy(dst, src, num, PMEM_F_MEM_NONTEMPORAL|PMEM_F_MEM_NODRAIN);
}

void *zmemset_pmem(void *ptr, int value, size_t num) {
return pmem_memset(ptr, value, num, PMEM_F_MEM_NONTEMPORAL|PMEM_F_MEM_NODRAIN);
}
#endif

/* Allocation and free functions that bypass the thread cache
Expand Down
2 changes: 2 additions & 0 deletions src/zmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ size_t zmalloc_get_smap_bytes_by_field(char *field, long pid);
size_t zmalloc_get_memory_size(void);
void zlibc_free(void *ptr);
void *zmalloc_pmem(size_t size);
void *zmemcpy_pmem(void *dst, const void *src, size_t num);
void *zmemset_pmem(void *ptr, int value, size_t num);

#ifdef HAVE_DEFRAG
void zfree_no_tcache(void *ptr);
Expand Down