mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
Not use jemalloc on macosx, See Issue #99
This commit is contained in:
7
Makefile
7
Makefile
@@ -22,6 +22,7 @@ JEMALLOC_STATICLIB := 3rd/jemalloc/lib/libjemalloc_pic.a
|
|||||||
JEMALLOC_INC := 3rd/jemalloc/include/jemalloc
|
JEMALLOC_INC := 3rd/jemalloc/include/jemalloc
|
||||||
|
|
||||||
all : jemalloc
|
all : jemalloc
|
||||||
|
|
||||||
.PHONY : jemalloc
|
.PHONY : jemalloc
|
||||||
|
|
||||||
$(JEMALLOC_STATICLIB) : 3rd/jemalloc/Makefile
|
$(JEMALLOC_STATICLIB) : 3rd/jemalloc/Makefile
|
||||||
@@ -33,7 +34,7 @@ $(JEMALLOC_STATICLIB) : 3rd/jemalloc/Makefile
|
|||||||
3rd/jemalloc/Makefile : | 3rd/jemalloc/autogen.sh
|
3rd/jemalloc/Makefile : | 3rd/jemalloc/autogen.sh
|
||||||
cd 3rd/jemalloc && ./autogen.sh --with-jemalloc-prefix=je_ --disable-valgrind
|
cd 3rd/jemalloc && ./autogen.sh --with-jemalloc-prefix=je_ --disable-valgrind
|
||||||
|
|
||||||
jemalloc : $(JEMALLOC_STATICLIB)
|
jemalloc : $(MALLOC_STATICLIB)
|
||||||
|
|
||||||
# skynet
|
# skynet
|
||||||
|
|
||||||
@@ -50,8 +51,8 @@ all : \
|
|||||||
$(foreach v, $(CSERVICE), $(CSERVICE_PATH)/$(v).so) \
|
$(foreach v, $(CSERVICE), $(CSERVICE_PATH)/$(v).so) \
|
||||||
$(foreach v, $(LUA_CLIB), $(LUA_CLIB_PATH)/$(v).so)
|
$(foreach v, $(LUA_CLIB), $(LUA_CLIB_PATH)/$(v).so)
|
||||||
|
|
||||||
$(SKYNET_BUILD_PATH)/skynet : $(foreach v, $(SKYNET_SRC), skynet-src/$(v)) $(LUA_LIB) $(JEMALLOC_STATICLIB)
|
$(SKYNET_BUILD_PATH)/skynet : $(foreach v, $(SKYNET_SRC), skynet-src/$(v)) $(LUA_LIB) $(MALLOC_STATICLIB)
|
||||||
$(CC) $(CFLAGS) -o $@ $^ -Iskynet-src -I$(JEMALLOC_INC) $(LDFLAGS) $(EXPORT) $(LIBS)
|
$(CC) $(CFLAGS) -o $@ $^ -Iskynet-src -I$(JEMALLOC_INC) $(LDFLAGS) $(EXPORT) $(LIBS) $(SKYNET_DEFINES)
|
||||||
|
|
||||||
$(LUA_CLIB_PATH) :
|
$(LUA_CLIB_PATH) :
|
||||||
mkdir $(LUA_CLIB_PATH)
|
mkdir $(LUA_CLIB_PATH)
|
||||||
|
|||||||
@@ -31,4 +31,7 @@ freebsd : PLAT = freebsd
|
|||||||
macosx linux : LIBS += -ldl
|
macosx linux : LIBS += -ldl
|
||||||
macosx : SHARED := -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup
|
macosx : SHARED := -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup
|
||||||
macosx : EXPORT :=
|
macosx : EXPORT :=
|
||||||
|
macosx : MALLOC_STATICLIB :=
|
||||||
|
macosx : SKYNET_DEFINES :=-DNOUSE_JEMALLOC
|
||||||
linux freebsd : LIBS += -lrt
|
linux freebsd : LIBS += -lrt
|
||||||
|
linux freebsd : MALLOC_STATICLIB = $(JEMALLOC_STATICLIB)
|
||||||
|
|||||||
@@ -1,10 +1,32 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <malloc/malloc.h>
|
||||||
|
#define malloc_usable_size(ptr) malloc_size(ptr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#include <malloc_np.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NOUSE_JEMALLOC
|
||||||
|
|
||||||
|
#define je_malloc malloc
|
||||||
|
#define je_free free
|
||||||
|
#define je_calloc calloc
|
||||||
|
#define je_realloc realloc
|
||||||
|
#define je_malloc_usable_size malloc_usable_size
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#include "malloc_hook.h"
|
|
||||||
#include "jemalloc.h"
|
#include "jemalloc.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "malloc_hook.h"
|
||||||
#include "skynet.h"
|
#include "skynet.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -99,11 +121,34 @@ malloc_memory_block(void) {
|
|||||||
return _memory_block;
|
return _memory_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory_info_dump(void) {
|
#ifdef NOUSE_JEMALLOC
|
||||||
|
|
||||||
|
void
|
||||||
|
memory_info_dump(void) {
|
||||||
|
skynet_error(NULL, "No jemalloc");
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
mallctl_int64(const char* name, size_t* newval) {
|
||||||
|
skynet_error(NULL, "No jemalloc : mallctl_int64 %s.", name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mallctl_opt(const char* name, int* newval) {
|
||||||
|
skynet_error(NULL, "No jemalloc : mallctl_opt %s.", name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void
|
||||||
|
memory_info_dump(void) {
|
||||||
je_malloc_stats_print(0,0,0);
|
je_malloc_stats_print(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t mallctl_int64(const char* name, size_t* newval) {
|
size_t
|
||||||
|
mallctl_int64(const char* name, size_t* newval) {
|
||||||
size_t v = 0;
|
size_t v = 0;
|
||||||
size_t len = sizeof(v);
|
size_t len = sizeof(v);
|
||||||
if(newval) {
|
if(newval) {
|
||||||
@@ -115,7 +160,8 @@ size_t mallctl_int64(const char* name, size_t* newval) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mallctl_opt(const char* name, int* newval) {
|
int
|
||||||
|
mallctl_opt(const char* name, int* newval) {
|
||||||
int v = 0;
|
int v = 0;
|
||||||
size_t len = sizeof(v);
|
size_t len = sizeof(v);
|
||||||
if(newval) {
|
if(newval) {
|
||||||
@@ -132,6 +178,8 @@ int mallctl_opt(const char* name, int* newval) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
dump_c_mem() {
|
dump_c_mem() {
|
||||||
int i;
|
int i;
|
||||||
@@ -147,7 +195,7 @@ dump_c_mem() {
|
|||||||
printf("+total: %zdkb\n",total >> 10);
|
printf("+total: %zdkb\n",total >> 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook : malloc, realloc, memalign, free, calloc
|
// hook : malloc, realloc, free, calloc
|
||||||
|
|
||||||
void *
|
void *
|
||||||
skynet_malloc(size_t size) {
|
skynet_malloc(size_t size) {
|
||||||
@@ -198,3 +246,8 @@ skynet_lalloc(void *ud, void *ptr, size_t osize, size_t nsize) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
malloc_inithook(void) {
|
||||||
|
memset(mem_stats, 0, sizeof(mem_stats));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user