14 - jemalloc

最後更新: 2019-04-03

 

介紹

jemalloc 它的功能是 malloc

Homepage: http://jemalloc.net/

比 Linux Default 的 glibc 優點:

 * fragmentation avoidance(躲避)
 * scalable concurrency
 * heap profiling
 * Valgrind integration ( Valgrind is an instrumentation framework for building dynamic analysis tools )
 * monitoring / tuning hooks

Version

V3.X Last: https://github.com/jemalloc/jemalloc/releases/download/3.6.0/jemalloc-3....

V4.0 Last: https://github.com/jemalloc/jemalloc/releases/download/4.0.4/jemalloc-4....

目錄

  • jemalloc module
  • tengine with jemalloc

 


jemalloc module

 

DL Source:

[1]

cd /usr/src

wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2

tar -jxf jemalloc-3.6.0.tar.bz2

cd jemalloc-*

[2]

cd /usr/src

git clone https://github.com/jemalloc/jemalloc

cd jemalloc

git checkout stable-3

Complie:

# 如果沒有 "./configure" 的話, 就要行一次 ./autogen.sh

# 建議用 ./configure --prefix /opt/jemalloc

./configure

...................................
autogen            : 0
experimental       : 1
cc-silence         : 0
debug              : 0
code-coverage      : 0
stats              : 1
prof               : 0
prof-libunwind     : 0
prof-libgcc        : 0
prof-gcc           : 0
tcache             : 1
fill               : 1
utrace             : 0
valgrind           : 0
xmalloc            : 0
mremap             : 0
munmap             : 0
dss                : 0
lazy_lock          : 0
tls                : 1

--with-jemalloc-prefix=<prefix>

Prefix all public APIs with <prefix>. By default, the prefix is ""

For example: malloc()  --> prefix_malloc()

make

make install

install -d /usr/local/bin
install -m 755 bin/jemalloc-config /usr/local/bin
install -m 755 bin/jemalloc.sh /usr/local/bin
install -m 755 bin/jeprof /usr/local/bin
install -d /usr/local/include/jemalloc
install -m 644 include/jemalloc/jemalloc.h /usr/local/include/jemalloc
install -d /usr/local/lib
install -m 755 lib/libjemalloc.so.2 /usr/local/lib
ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so
install -d /usr/local/lib
install -m 755 lib/libjemalloc.a /usr/local/lib
install -m 755 lib/libjemalloc_pic.a /usr/local/lib
install -d /usr/local/lib/pkgconfig
install -m 644 jemalloc.pc /usr/local/lib/pkgconfig
install -d /usr/local/share/doc/jemalloc
install -m 644 doc/jemalloc.html /usr/local/share/doc/jemalloc
install -d /usr/local/share/man/man3
install -m 644 doc/jemalloc.3 /usr/local/share/man/man3

 

Configure Library

echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf

ldconfig

Checking

ls /usr/local/lib

ldconfig -v | grep jemalloc

/opt/jemalloc/lib:
        libjemalloc.so.1 -> libjemalloc.so.1

 



tengine with jemalloc

 

Remark

tengine 2.1.3 support jemalloc-3.6.0 (如果用 V4 會 compile 唔到)

安裝

cd /usr/src/jemalloc-3.6.0

./configure

make

cd /usr/src/tengine

./configure --with-jemalloc --with-jemalloc=/usr/src/jemalloc-3.6.0 --prefix=/opt

Output

.................................................

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library
  + using system jemalloc library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx dso module path: "/usr/local/nginx/modules/"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

make

Checking:

strings /usr/sbin/nginx | grep jemalloc

OR

ldd /usr/sbin/nginx | libjemalloc

 


Other Info.

 

Google's tcmalloc:

https://github.com/gperftools/gperftools

Scalable memory allocation using jemalloc:

http://www.facebook.com/notes/facebook-engineering/scalable-memory-allocation-using-jemalloc/480222803919

 


DOC

man jemalloc