Reference article: http://blog.sina.com.cn/s/blog_51df3eae01016peu.html
We know that Redis does not implement its own memory pool, and does not add its own stuff to the standard system memory allocator. Therefore, the performance and fragmentation rate of the system memory allocator can have some performance impact on Redis.
In the zmalloc.c source of Redis, we can see the following code:
#if defined (use_tcmalloc) #define malloc (size) tc_malloc (size) Wuyi #define CALLOC (count,size) tc_calloc (count,size) #define REALLOC (ptr,size) tc_realloc (ptr,size) #define FREE (PTR) tc_free (PTR) #elif defined (use_jemalloc) #def INE malloc (size) je_malloc (size) #define CALLOC (count,size) je_calloc (count,size) #define REALLOC (ptr,size) je_ ReAlloc (ptr,size) #define FREE (PTR) je_free (PTR) #endif
As we can see from the code above, Redis will first determine whether to use Tcmallocwhen compiling, and if so, replace the function implementation in the standard libc with the tcmalloc corresponding function. The second is to determine whether Jemalloc makes, and finally if not used, the standard LIBC memory management functions.
The installation method for installing Tcmalloc is listed in the
Reference, so I'll say Jemalloc installation method
tar jxf jemalloc-3.6 . 0 . tar .BZ2CD jemalloc -0 /configure make Use_jemalloc=yes force_libc_ Malloc=yes #指定用jemalloc make install
CP -a/root/jemalloc-3.6 . 0 /include/jemalloc/USR/INCLUDE/CD. Cat/etc/ld.so.conf.d/local_lib.confecho "/usr/local/lib" >/etc/ld.so.conf.d/local_lib.conf/sbin/ldconfig
#至于是选择tcmalloc还是jemalloc, I'm looking at a man's liking.
Ptmalloc is the GLIBC memory allocation management module
Tcmalloc is Google's memory allocation management module
Jemalloc is BSD's memory allocation management module
Next, Redis uses a different memory allocator