diff --git a/build/jemalloc.m4 b/build/jemalloc.m4 index 8306a83b765..6c43e2341c3 100644 --- a/build/jemalloc.m4 +++ b/build/jemalloc.m4 @@ -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 diff --git a/build/mimalloc.m4 b/build/mimalloc.m4 new file mode 100644 index 00000000000..5e6c1485c84 --- /dev/null +++ b/build/mimalloc.m4 @@ -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 ], + [ + #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) +]) diff --git a/build/tcmalloc.m4 b/build/tcmalloc.m4 index fe9d538fcc3..d8027ad7aeb 100644 --- a/build/tcmalloc.m4 +++ b/build/tcmalloc.m4 @@ -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" diff --git a/configure.ac b/configure.ac index 27aa527beeb..8f504fdeec2 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/doc/developer-guide/testing/blackbox-testing.en.rst b/doc/developer-guide/testing/blackbox-testing.en.rst index 3b4a5c27011..25af57aec31 100644 --- a/doc/developer-guide/testing/blackbox-testing.en.rst +++ b/doc/developer-guide/testing/blackbox-testing.en.rst @@ -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 diff --git a/include/tscore/ink_config.h.in b/include/tscore/ink_config.h.in index d66e509d687..5b297efe7bf 100644 --- a/include/tscore/ink_config.h.in +++ b/include/tscore/ink_config.h.in @@ -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@ diff --git a/include/tscore/ink_memory.h b/include/tscore/ink_memory.h index e1fc3e289e1..ae5dd3303e6 100644 --- a/include/tscore/ink_memory.h +++ b/include/tscore/ink_memory.h @@ -50,10 +50,10 @@ #if TS_HAS_JEMALLOC #include -#else -#if HAVE_MALLOC_H +#elif TS_HAS_MIMALLOC +#include +#elif HAVE_MALLOC_H #include -#endif // ! HAVE_MALLOC_H #endif // ! TS_HAS_JEMALLOC #ifndef MADV_NORMAL diff --git a/src/tscore/ink_memory.cc b/src/tscore/ink_memory.cc index f8b9b86e465..1d8dbaf90e8 100644 --- a/src/tscore/ink_memory.cc +++ b/src/tscore/ink_memory.cc @@ -27,6 +27,11 @@ #include "tscore/Diags.h" #include "tscore/ink_atomic.h" +#if TS_HAS_MIMALLOC +#include +#include +#endif + #if !defined(kfreebsd) && defined(freebsd) #include // for malloc_usable_size #endif diff --git a/tests/README.md b/tests/README.md index 898c38463e9..e28a6b90751 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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