Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build/jemalloc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ AC_ARG_WITH([jemalloc], [AS_HELP_STRING([--with-jemalloc=DIR],[use a specific je
if test "x${has_tcmalloc}" = "xyes"; then
AC_MSG_ERROR([Cannot compile with both jemalloc and tcmalloc])
fi
if test "x${has_mimalloc}" = "xyes"; then
AC_MSG_ERROR([Cannot compile with both jemalloc and mimalloc])
fi
has_jemalloc=yes
jemalloc_base_dir="$withval"
case "$withval" in
Expand Down
95 changes: 95 additions & 0 deletions build/mimalloc.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
dnl -------------------------------------------------------- -*- autoconf -*-
dnl Licensed to the Apache Software Foundation (ASF) under one or more
dnl contributor license agreements. See the NOTICE file distributed with
dnl this work for additional information regarding copyright ownership.
dnl The ASF licenses this file to You under the Apache License, Version 2.0
dnl (the "License"); you may not use this file except in compliance with
dnl the License. You may obtain a copy of the License at
dnl
dnl http://www.apache.org/licenses/LICENSE-2.0
dnl
dnl Unless required by applicable law or agreed to in writing, software
dnl distributed under the License is distributed on an "AS IS" BASIS,
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dnl See the License for the specific language governing permissions and
dnl limitations under the License.

dnl
dnl mimalloc.m4: Trafficserver's mimalloc autoconf macros
dnl

AC_DEFUN([TS_CHECK_MIMALLOC], [
has_mimalloc=no
AC_ARG_WITH([mimalloc], [AS_HELP_STRING([--with-mimalloc=DIR],[use a specific mimalloc library])],
[
if test "$withval" != "no"; then
if test "x${has_tcmalloc}" = "xyes"; then
AC_MSG_ERROR([Cannot compile with both mimalloc and tcmalloc])
fi
if test "x${has_jemalloc}" = "xyes"; then
AC_MSG_ERROR([Cannot compile with both mimalloc and jemalloc])
fi
has_mimalloc=yes
mimalloc_base_dir="$withval"
case "$withval" in
yes)
mimalloc_base_dir="/usr"
AC_MSG_NOTICE(checking for mimalloc includes and libs in standard directories)
;;
*":"*)
mimalloc_include="`echo $withval | sed -e 's/:.*$//'`"
mimalloc_ldflags="`echo $withval | sed -e 's/^.*://'`"
AC_MSG_NOTICE(checking for mimalloc includes in $mimalloc_include and libs in $mimalloc_ldflags)
;;
*)
mimalloc_include="$withval/include"
mimalloc_ldflags="$withval/lib"
mimalloc_ldflags64="$withval/lib64"
AC_MSG_NOTICE(checking for mimalloc includes in $mimalloc_include and libs in $mimalloc_ldflags or $mimalloc_ldflags64)
;;
esac
fi
])

mimalloch=0
if test "$has_mimalloc" != "no"; then
saved_ldflags=$LDFLAGS
saved_cppflags=$CPPFLAGS
mimalloc_has_headers=0
mimalloc_has_libs=0
AC_CHECK_FILE([mimalloc_ldflags], [], [mimalloc_ldflags=$mimalloc_ldflags64])
if test "$mimalloc_base_dir" != "/usr"; then
TS_ADDTO(CPPFLAGS, [-I${mimalloc_include}])
TS_ADDTO(LDFLAGS, [-L${mimalloc_ldflags}])
TS_ADDTO(LDFLAGS, [-Wl,--add-needed -L${mimalloc_ldflags} -Wl,-rpath,${mimalloc_ldflags} -Wl,--no-as-needed])
TS_ADDTO_RPATH(${mimalloc_ldflags})
fi
AC_SEARCH_LIBS([mi_malloc], [mimalloc], [mimalloc_has_libs=1])
if test "$mimalloc_has_libs" != "0"; then
AC_CHECK_HEADERS(mimalloc.h, [mimalloc_has_headers=1])
fi
if test "$mimalloc_has_headers" != "0"; then
AC_RUN_IFELSE([
AC_LANG_PROGRAM(
[#include <mimalloc.h>],
[
#ifndef MI_MALLOC_VERSION
exit(1);
#endif

#if (MI_MALLOC_VERSION == 0)
exit(1);
#endif
]
)],
[mimalloch=1],
[AC_MSG_ERROR(mimalloc has bogus version)]
)
else
AC_MSG_WARN([mimalloc not found])
CPPFLAGS=$saved_cppflags
LDFLAGS=$saved_ldflags
fi
fi
AC_SUBST(mimalloch)
])
3 changes: 3 additions & 0 deletions build/tcmalloc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ AC_ARG_WITH([tcmalloc], [AS_HELP_STRING([--with-tcmalloc=DIR],[use the tcmalloc
if test "x${has_jemalloc}" = "xyes"; then
AC_MSG_ERROR([Cannot compile with both tcmalloc and jemalloc])
fi
if test "x${has_mimalloc}" = "xyes"; then
AC_MSG_ERROR([Cannot compile with both tcmalloc and mimalloc])
fi
tcmalloc_have_libs=0
if test "x$withval" != "xyes" && test "x$withval" != "x"; then
tcmalloc_ldflags="$withval/lib"
Expand Down
5 changes: 3 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,10 @@ AC_SUBST(use_hrw_maxminddb)
AM_CONDITIONAL([BUILD_HEALTHCHECK_PLUGIN], [ test "$ac_cv_func_inotify_init" = "yes" ])

#
# Check for tcmalloc and jemalloc
TS_CHECK_JEMALLOC
# Check for tcmalloc, jemalloc and mimalloc
TS_CHECK_TCMALLOC
TS_CHECK_JEMALLOC
TS_CHECK_MIMALLOC

#
# Check for libreadline/libedit
Expand Down
1 change: 1 addition & 0 deletions doc/developer-guide/testing/blackbox-testing.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ Condition Testing
- TS_HAS_PIPE_BUFFER_SIZE_CONFIG
- TS_HAS_JEMALLOC
- TS_HAS_TCMALLOC
- TS_HAS_MIMALLOC
- TS_HAS_IN6_IS_ADDR_UNSPECIFIED
- TS_HAS_BACKTRACE
- TS_HAS_PROFILER
Expand Down
1 change: 1 addition & 0 deletions include/tscore/ink_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
/* Libraries */
#define TS_HAS_JEMALLOC @jemalloch@
#define TS_HAS_TCMALLOC @has_tcmalloc@
#define TS_HAS_MIMALLOC @mimalloch@

/* Features */
#define TS_HAS_IN6_IS_ADDR_UNSPECIFIED @has_in6_is_addr_unspecified@
Expand Down
6 changes: 3 additions & 3 deletions include/tscore/ink_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@

#if TS_HAS_JEMALLOC
#include <jemalloc/jemalloc.h>
#else
#if HAVE_MALLOC_H
#elif TS_HAS_MIMALLOC
#include <mimalloc.h>
#elif HAVE_MALLOC_H
#include <malloc.h>
#endif // ! HAVE_MALLOC_H
#endif // ! TS_HAS_JEMALLOC

#ifndef MADV_NORMAL
Expand Down
5 changes: 5 additions & 0 deletions src/tscore/ink_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
#include "tscore/Diags.h"
#include "tscore/ink_atomic.h"

#if TS_HAS_MIMALLOC
#include <mimalloc-new-delete.h>
#include <mimalloc-override.h>
#endif

#if !defined(kfreebsd) && defined(freebsd)
#include <malloc_np.h> // for malloc_usable_size
#endif
Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ ts.Disk.remap_config.AddLine(
* TS_HAS_PIPE_BUFFER_SIZE_CONFIG
* TS_HAS_JEMALLOC
* TS_HAS_TCMALLOC
* TS_HAS_MIMALLOC
* TS_HAS_IN6_IS_ADDR_UNSPECIFIED
* TS_HAS_BACKTRACE
* TS_HAS_PROFILER
Expand Down