From d9452a54a02ba2266d0400bf1ca9ff7d9a95d7f5 Mon Sep 17 00:00:00 2001 From: tfheen Date: Wed, 24 Sep 2008 12:41:29 +0000 Subject: [PATCH] Use jemalloc by default on Linux We seem to run into trouble with regular glibc malloc on Linux, so use jemalloc instead of glibc's malloc. This can be disabled using --disable-jemalloc git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3216 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/Makefile.am | 1 + varnish-cache/configure.ac | 23 +++++++++++++++++++ varnish-cache/lib/Makefile.am | 3 ++- varnish-cache/lib/libjemalloc/Makefile | 23 ------------------- varnish-cache/lib/libjemalloc/Makefile.am | 27 +++++++++++++++++++++++ 5 files changed, 53 insertions(+), 24 deletions(-) delete mode 100644 varnish-cache/lib/libjemalloc/Makefile create mode 100644 varnish-cache/lib/libjemalloc/Makefile.am diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index 81f0e8e8..f43e2af2 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -79,6 +79,7 @@ varnishd_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvcl/libvcl.la \ + @JEMALLOC_LDADD@ \ ${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM} EXTRA_DIST = default.vcl diff --git a/varnish-cache/configure.ac b/varnish-cache/configure.ac index a8d01ee4..8f9ee910 100644 --- a/varnish-cache/configure.ac +++ b/varnish-cache/configure.ac @@ -340,6 +340,28 @@ esac AC_DEFINE_UNQUOTED([VCC_CC],"$VCC_CC",[C compiler command line for VCL code]) +# Use jemalloc on Linux +JEMALLOC_SUBDIR= +JEMALLOC_LDADD= +AC_ARG_ENABLE(jemalloc, +AS_HELP_STRING([--disable-jemalloc],[do not use jemalloc (default is yes on Linux, no everywhere else)]), +[if "x$enableval" = "xyes"; then + JEMALLOC_SUBDIR=libjemalloc + JEMALLOC_LDADD='$(top_builddir)/lib/libjemalloc/libjemalloc_mt.la' +fi], +[case $host in #( +*-*-linux*) + JEMALLOC_SUBDIR=libjemalloc + JEMALLOC_LDADD='$(top_builddir)/lib/libjemalloc/libjemalloc_mt.la' + ;; #( +*) + true + ;; +esac]) + +AC_SUBST(JEMALLOC_SUBDIR) +AC_SUBST(JEMALLOC_LDADD) + # Generate output AC_CONFIG_FILES([ Makefile @@ -361,6 +383,7 @@ AC_CONFIG_FILES([ lib/libvarnishapi/Makefile lib/libvarnishcompat/Makefile lib/libvcl/Makefile + lib/libjemalloc/Makefile man/Makefile redhat/Makefile varnishapi.pc diff --git a/varnish-cache/lib/Makefile.am b/varnish-cache/lib/Makefile.am index b6fc8fc9..e757b3d1 100644 --- a/varnish-cache/lib/Makefile.am +++ b/varnish-cache/lib/Makefile.am @@ -4,4 +4,5 @@ SUBDIRS = \ libvarnish \ libvarnishapi \ libvarnishcompat \ - libvcl + libvcl \ + @JEMALLOC_SUBDIR@ diff --git a/varnish-cache/lib/libjemalloc/Makefile b/varnish-cache/lib/libjemalloc/Makefile deleted file mode 100644 index 49f4197d..00000000 --- a/varnish-cache/lib/libjemalloc/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -CFLAGS := -O3 -g -# See source code comments to avoid memory leaks when enabling MALLOC_MAG. -#CPPFLAGS := -DMALLOC_PRODUCTION -DMALLOC_MAG -CPPFLAGS := -DMALLOC_PRODUCTION - -all: libjemalloc.so.0 libjemalloc_mt.so.0 - -jemalloc_linux_mt.o: jemalloc_linux.c - gcc $(CFLAGS) -c -DPIC -fPIC $(CPPFLAGS) -D__isthreaded=true -o $@ $+ - -jemalloc_linux.o: jemalloc_linux.c - gcc $(CFLAGS) -c -DPIC -fPIC $(CPPFLAGS) -D__isthreaded=false -o $@ $+ - -libjemalloc_mt.so.0: jemalloc_linux_mt.o - gcc -shared -lpthread -o $@ $+ - ln -sf $@ libjemalloc_mt.so - -libjemalloc.so.0: jemalloc_linux.o - gcc -shared -lpthread -o $@ $+ - ln -sf $@ libjemalloc.so - -clean: - rm -f *.o *.so.0 *.so diff --git a/varnish-cache/lib/libjemalloc/Makefile.am b/varnish-cache/lib/libjemalloc/Makefile.am new file mode 100644 index 00000000..1deecde3 --- /dev/null +++ b/varnish-cache/lib/libjemalloc/Makefile.am @@ -0,0 +1,27 @@ +# See source code comments to avoid memory leaks when enabling MALLOC_MAG. +#CPPFLAGS := -DMALLOC_PRODUCTION -DMALLOC_MAG +AM_CPPFLAGS := -DMALLOC_PRODUCTION + +#all: libjemalloc.so.0 libjemalloc_mt.so.0 + +noinst_LTLIBRARIES = libjemalloc_mt.la + +libjemalloc_mt_la_LIBADD = ${PTHREAD_LIBS} +libjemalloc_mt_la_LDFLAGS = -version-info 0:0:0 -static +libjemalloc_mt_la_CFLAGS = -D__isthreaded=true + +libjemalloc_mt_la_SOURCES = jemalloc_linux.c + +#jemalloc_linux.o: jemalloc_linux.c +# gcc $(CFLAGS) -c -DPIC -fPIC $(CPPFLAGS) -D__isthreaded=false -o $@ $+ + +#libjemalloc_mt.so.0: jemalloc_linux_mt.o +# gcc -shared -lpthread -o $@ $+ +# ln -sf $@ libjemalloc_mt.so + +#libjemalloc.so.0: jemalloc_linux.o +# gcc -shared -lpthread -o $@ $+ +# ln -sf $@ libjemalloc.so + +#clean: +# rm -f *.o *.so.0 *.so -- 2.39.5