allow linking with jemalloc or tcmalloc
Costa Tsaousis (ktsaou) committed
Oct 1, 2016 at 14:12 UTC
94a39cdfe202460a722988cbc1a578d3b84b72ce
5 files changed
+171
-3
configure.ac
+8
-2
@@ -84,13 +84,19 @@ LIBS="${PTHREAD_LIBS} ${LIBS}"
84
CFLAGS="${CFLAGS} ${PTHREAD_CFLAGS}"
85
CC="${PTHREAD_CC}"
86
87
+TS_CHECK_JEMALLOC
88
+if test "$has_jemalloc" = "0"; then
89
+ TS_CHECK_TCMALLOC
90
+fi
91
+if test "$has_jemalloc$has_tcmalloc" = "00"; then
92
+ AC_C_MALLOPT
93
+ AC_C_MALLINFO
94
+fi
95
AC_TYPE_UINT8_T
96
AC_TYPE_UINT16_T
97
AC_TYPE_UINT32_T
98
AC_C_INLINE
99
AC_FUNC_STRERROR_R
92
-AC_C_MALLOPT
93
-AC_C_MALLINFO
100
AC_C__GENERIC
101
AC_C___ATOMIC
102
AC_CHECK_SIZEOF([void *])
m4/jemalloc.m4
new
+88
@@ -0,0 +1,88 @@
1
+dnl -------------------------------------------------------- -*- autoconf -*-
2
+dnl Licensed to the Apache Software Foundation (ASF) under one or more
3
+dnl contributor license agreements. See the NOTICE file distributed with
4
+dnl this work for additional information regarding copyright ownership.
5
+dnl The ASF licenses this file to You under the Apache License, Version 2.0
6
+dnl (the "License"); you may not use this file except in compliance with
7
+dnl the License. You may obtain a copy of the License at
8
+dnl
9
+dnl http://www.apache.org/licenses/LICENSE-2.0
10
+dnl
11
+dnl Unless required by applicable law or agreed to in writing, software
12
+dnl distributed under the License is distributed on an "AS IS" BASIS,
13
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+dnl See the License for the specific language governing permissions and
15
+dnl limitations under the License.
16
+
17
+dnl
18
+dnl jemalloc.m4: Trafficserver's jemalloc autoconf macros
19
+dnl modified to skip other TS_ helpers
20
+dnl
21
+
22
+AC_DEFUN([TS_CHECK_JEMALLOC], [
23
+AC_ARG_WITH([jemalloc-prefix],
24
+ [AS_HELP_STRING([--with-jemalloc-prefix=PREFIX],[Specify the jemalloc prefix [default=""]])],
25
+ [
26
+ jemalloc_prefix="$withval"
27
+ ],[
28
+ if test "`uname -s`" = "Darwin"; then
29
+ jemalloc_prefix="je_"
30
+ else
31
+ jemalloc_prefix=""
32
+ fi
33
+ ]
34
+)
35
+AC_DEFINE_UNQUOTED([prefix_jemalloc], [${jemalloc_prefix}], [jemalloc prefix])
36
+
37
+enable_jemalloc=no
38
+AC_ARG_WITH([jemalloc], [AS_HELP_STRING([--with-jemalloc=DIR], [use a specific jemalloc library])],
39
+[
40
+ if test "$withval" != "no"; then
41
+ if test "x${enable_tcmalloc}" = "xyes"; then
42
+ AC_MSG_ERROR([Cannot compile with both jemalloc and tcmalloc])
43
+ fi
44
+ enable_jemalloc=yes
45
+ jemalloc_base_dir="$withval"
46
+ case "$withval" in
47
+ yes)
48
+ jemalloc_base_dir="/usr"
49
+ AC_MSG_CHECKING(checking for jemalloc includes standard directories)
50
+ ;;
51
+ *":"*)
52
+ jemalloc_include="`echo $withval |sed -e 's/:.*$//'`"
53
+ jemalloc_ldflags="`echo $withval |sed -e 's/^.*://'`"
54
+ AC_MSG_CHECKING(checking for jemalloc includes in $jemalloc_include libs in $jemalloc_ldflags)
55
+ ;;
56
+ *)
57
+ jemalloc_include="$withval/include"
58
+ jemalloc_ldflags="$withval/lib"
59
+ AC_MSG_CHECKING(checking for jemalloc includes in $withval)
60
+ ;;
61
+ esac
62
+ fi
63
+])
64
+
65
+has_jemalloc=0
66
+if test "$enable_jemalloc" != "no"; then
67
+ jemalloc_have_headers=0
68
+ jemalloc_have_libs=0
69
+ if test "$jemalloc_base_dir" != "/usr"; then
70
+ CFLAGS="${CFLAGS} -I${jemalloc_include}"
71
+ LDFLAGS="${LDFLAGS} -L${jemalloc_ldflags}"
72
+ LIBTOOL_LINK_FLAGS="${LIBTOOL_LINK_FLAGS} -R${jemalloc_ldflags}"
73
+ fi
74
+ func="${jemalloc_prefix}malloc_stats_print"
75
+ AC_CHECK_LIB(jemalloc, ${func}, [jemalloc_have_libs=1])
76
+ if test "$jemalloc_have_libs" != "0"; then
77
+ AC_CHECK_HEADERS([jemalloc/jemalloc.h], [jemalloc_have_headers=1])
78
+ fi
79
+ if test "$jemalloc_have_headers" != "0"; then
80
+ has_jemalloc=1
81
+ LIBS="${LIBS} -ljemalloc"
82
+ AC_DEFINE(has_jemalloc, [1], [Link/compile against jemalloc])
83
+ else
84
+ AC_MSG_ERROR([Couldn't find a jemalloc installation])
85
+ fi
86
+fi
87
+AC_SUBST(has_jemalloc)
88
+])
m4/tcmalloc.m4
new
+58
@@ -0,0 +1,58 @@
1
+dnl -------------------------------------------------------- -*- autoconf -*-
2
+dnl Licensed to the Apache Software Foundation (ASF) under one or more
3
+dnl contributor license agreements. See the NOTICE file distributed with
4
+dnl this work for additional information regarding copyright ownership.
5
+dnl The ASF licenses this file to You under the Apache License, Version 2.0
6
+dnl (the "License"); you may not use this file except in compliance with
7
+dnl the License. You may obtain a copy of the License at
8
+dnl
9
+dnl http://www.apache.org/licenses/LICENSE-2.0
10
+dnl
11
+dnl Unless required by applicable law or agreed to in writing, software
12
+dnl distributed under the License is distributed on an "AS IS" BASIS,
13
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+dnl See the License for the specific language governing permissions and
15
+dnl limitations under the License.
16
+
17
+dnl
18
+dnl tcmalloc.m4: Trafficserver's tcmalloc autoconf macros
19
+dnl modified to skip other TS_ helpers
20
+dnl
21
+
22
+dnl This is kinda fugly, but need a way to both specify a directory and which
23
+dnl of the many tcmalloc libraries to use ...
24
+AC_DEFUN([TS_CHECK_TCMALLOC], [
25
+AC_ARG_WITH([tcmalloc-lib],
26
+ [AS_HELP_STRING([--with-tcmalloc-lib],[specify the tcmalloc library to use [default=tcmalloc]])],
27
+ [
28
+ with_tcmalloc_lib="$withval"
29
+ ],[
30
+ with_tcmalloc_lib="tcmalloc"
31
+ ]
32
+)
33
+
34
+has_tcmalloc=0
35
+AC_ARG_WITH([tcmalloc], [AS_HELP_STRING([--with-tcmalloc=DIR], [use the tcmalloc library])],
36
+[
37
+ if test "$withval" != "no"; then
38
+ if test "x${enable_jemalloc}" = "xyes"; then
39
+ AC_MSG_ERROR([Cannot compile with both tcmalloc and jemalloc])
40
+ fi
41
+ tcmalloc_have_lib=0
42
+ if test "x$withval" != "xyes" && test "x$withval" != "x"; then
43
+ tcmalloc_ldflags="$withval/lib"
44
+ LDFLAGS="${LDFLAGS} -L${tcmalloc_ldflags}"
45
+ LIBTOOL_LINK_FLAGS="${LIBTOOL_LINK_FLAGS} -rpath ${tcmalloc_ldflags}"
46
+ fi
47
+ AC_CHECK_LIB(${with_tcmalloc_lib}, tc_cfree, [tcmalloc_have_lib=1])
48
+ if test "$tcmalloc_have_lib" != "0"; then
49
+ LIBS="${LIBS} -l${with_tcmalloc_lib}"
50
+ has_tcmalloc=1
51
+ AC_DEFINE(has_tcmalloc, [1], [Link/compile against tcmalloc])
52
+ else
53
+ AC_MSG_ERROR([Couldn't find a tcmalloc installation])
54
+ fi
55
+ fi
56
+])
57
+AC_SUBST(has_tcmalloc)
58
+])
src/common.h
+13
-1
@@ -5,6 +5,18 @@
5
#include <config.h>
6
#endif
7
8
+#ifdef has_jemalloc
9
+#include <jemalloc/jemalloc.h>
10
+#undef HAVE_C_MALLOPT
11
+#undef HAVE_C_MALLINFO
12
+#elif has_tcmalloc
13
+#include <google/tcmalloc.h>
14
+#undef HAVE_C_MALLOPT
15
+#undef HAVE_C_MALLINFO
16
+#else
17
+#include <malloc.h>
18
+#endif
19
+
20
#include <pthread.h>
21
#include <errno.h>
22
@@ -27,7 +39,7 @@
39
#include <grp.h>
40
#include <pwd.h>
41
#include <locale.h>
30
-#include <malloc.h>
42
+
43
#include <netdb.h>
44
#include <poll.h>
45
#include <signal.h>
src/web_server.c
+4
@@ -37,6 +37,10 @@ static void log_allocations(void)
37
#else /* ! HAVE_C_MALLINFO */
38
;
39
#endif /* ! HAVE_C_MALLINFO */
40
+
41
+#ifdef has_jemalloc
42
+ malloc_stats_print(NULL, NULL, NULL);
43
+#endif
44
}
45
#endif /* NETDATA_INTERNAL_CHECKS */
46