From da1364c20c3668d8d3113e94a228d436391248e4 Mon Sep 17 00:00:00 2001 From: heamon7 Date: Thu, 31 Dec 2015 14:33:07 +0800 Subject: [PATCH 1/2] annotate Makefile --- src/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Makefile b/src/Makefile index 289371666..4a79a180c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,9 @@ # Dependencies are stored in the Makefile.dep file. To rebuild this file # Just use 'make dep', but this is only needed by developers. +# h7: 创建编译信息 release_hdr := $(shell sh -c './mkreleasehdr.sh') +# h7: sh -c 'uname -s 2>/dev/null || echo not' 这一句在linux下执行的结果为 Linux,在mac下执行的结果为 Darwin uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') OPTIMIZATION?=-O2 DEPENDENCY_TARGETS=hiredis linenoise lua @@ -26,6 +28,10 @@ PREFIX?=/usr/local INSTALL_BIN=$(PREFIX)/bin INSTALL=install +# h7: 根据上面系统信息,确定动态内存分配器类型,下面定义了使用facebook的jemalloc,此外,也可以选择libc原生的malloc,但需要在每次内存分配前加4个字节记录内存分配的长度信息,以实现malloc_size的功能。源码中已经自带了jemalloc的源码,可以看出官方还是比较推崇使用jemalloc的。 +# h7: linux 下默认使用 jemalloc +# h7: 详细信息可以参考: http://m.blog.csdn.net/blog/kaixin89/42217109 ;http://blog.sina.com.cn/s/blog_6f5b220601012x3x.html + # Default allocator ifeq ($(uname_S),Linux) MALLOC=jemalloc @@ -82,6 +88,7 @@ ifeq ($(MALLOC),tcmalloc_minimal) FINAL_LIBS+= -ltcmalloc_minimal endif +# h7: 引入 jemalloc 的静态库 ifeq ($(MALLOC),jemalloc) DEPENDENCY_TARGETS+= jemalloc FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include From 8db7271e62d292d1d3b96267150073683c303056 Mon Sep 17 00:00:00 2001 From: heamon7 Date: Thu, 31 Dec 2015 14:35:13 +0800 Subject: [PATCH 2/2] annotate config.h --- src/config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/config.h b/src/config.h index 8041f7ebe..c3e3ee888 100644 --- a/src/config.h +++ b/src/config.h @@ -133,6 +133,7 @@ void setproctitle(const char *fmt, ...); #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/ +// h7: 使用小端系统的平台 #if defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \ defined(vax) || defined(ns32000) || defined(sun386) || \ defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ @@ -185,6 +186,7 @@ void setproctitle(const char *fmt, ...); #error "Undefined or invalid BYTE_ORDER" #endif +// h7: 这里和后面在zmalloc.c中的定义有关,用于实现内存统计 #if (__i386 || __amd64) && __GNUC__ #define GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #if (GNUC_VERSION >= 40100) || defined(__clang__)