From ea0a1df3a11a47a5a3eebc68e721986ba748bf11 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 3 Jul 2019 14:31:05 -0700 Subject: [PATCH] configure: Add options for third-party allocator selection/deselection and inclusion. --- configure.ac | 60 ++++++++++++++++++++++++++++++++++++++-- construct/Makefile.am | 3 ++ doc/BUILD.md | 11 ++++++++ include/ircd/Makefile.am | 1 + ircd/Makefile.am | 3 ++ 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ffadf8e2b..55925edb7 100644 --- a/configure.ac +++ b/configure.ac @@ -440,6 +440,22 @@ AM_COND_IF([UNTUNED], CXXFLAGS+="" ]) +dnl +dnl Disable third-party allocators +dnl + +AC_MSG_CHECKING(whether to prevent available third-party allocator libraries from being used) +AC_ARG_ENABLE(allocators, AC_HELP_STRING([--disable-alloc-libs], [Disable third-party dynamic memory libraries (jemalloc/tcmalloc/etc)]), +[ + use_alloc_libs="no" + AC_MSG_RESULT([yes]) +], [ + use_alloc_libs="yes" + AC_MSG_RESULT([no]) +]) + +AM_CONDITIONAL([ALLOC_LIBS], [[[[ "$use_alloc_libs" = "yes" ]]]]) + dnl !!! Experimental !!! dnl dnl Allows a signal handler to throw a C++ exception if the signal is from @@ -1665,9 +1681,48 @@ dnl RB_CHK_SYSHEADER(jemalloc/jemalloc.h, [JEMALLOC_H]) AC_CHECK_LIB(jemalloc, malloc, [ - jemalloc="yes" + have_jemalloc="yes" ], [ - jemalloc="no" + have_jemalloc="no" +]) + +AC_MSG_CHECKING(whether to enable use of jemalloc) +AC_ARG_ENABLE(jemalloc, AC_HELP_STRING([--enable-jemalloc], [Use jemalloc as third-party dynamic memory manager.]), +[ + use_jemalloc="yes" + AC_MSG_RESULT([yes]) +], [ + use_jemalloc="no" + AC_MSG_RESULT([no]) +]) + +AM_CONDITIONAL([JEMALLOC], [test "x$have_jemalloc" = "xyes" && test "x$use_jemalloc" = "xyes" ]) + +dnl +dnl +dnl Select a third-party allocator +dnl +dnl + +AC_SUBST(MALLOC_CPPFLAGS) +AC_SUBST(MALLOC_CXXFLAGS) +AC_SUBST(MALLOC_LDFLAGS) +AC_SUBST(MALLOC_LIBS) +alloc_lib="standard" + +dnl ALLOC_LIBS true unless --disable-alloc-libs configured +AM_COND_IF([ALLOC_LIBS], +[ + AM_COND_IF([JEMALLOC], + [ + alloc_lib="jemalloc" + MALLOC_LIBS+=" -ljemalloc" + AC_DEFINE(IRCD_ALLOCATOR_USE_JEMALLOC, 1, [Use jemalloc as the allocator]) + ], [ + AC_DEFINE(IRCD_ALLOCATOR_USE_DEFAULT, 1, [Use the default allocator]) + ]) +], [ + AC_DEFINE(IRCD_ALLOCATOR_USE_DEFAULT, 1, [Use the default allocator]) ]) dnl @@ -1839,6 +1894,7 @@ echo "Link-time optimized ............... $lto" echo "Optimization level ................ $optimize_level" echo "Generic binary .................... $enable_generic" echo "Untuned binary .................... $enable_untuned" +echo "Memory allocator .................. $alloc_lib" echo "Logging level ..................... $LOG_LEVEL" echo "Installing into ................... $prefix" echo diff --git a/construct/Makefile.am b/construct/Makefile.am index 213730591..434a8f276 100644 --- a/construct/Makefile.am +++ b/construct/Makefile.am @@ -17,6 +17,7 @@ AM_CPPFLAGS = \ @SNAPPY_CPPFLAGS@ \ @LZ4_CPPFLAGS@ \ @Z_CPPFLAGS@ \ + @MALLOC_CPPFLAGS@ \ @EXTRA_CPPFLAGS@ \ ### @@ -66,6 +67,7 @@ construct_LDFLAGS = \ @SNAPPY_LDFLAGS@ \ @LZ4_LDFLAGS@ \ @Z_LDFLAGS@ \ + @MALLOC_LDFLAGS@ \ ### construct_LDADD = \ @@ -80,6 +82,7 @@ construct_LDADD = \ @SNAPPY_LIBS@ \ @LZ4_LIBS@ \ @Z_LIBS@ \ + @MALLOC_LIBS@ \ @EXTRA_LIBS@ \ ### diff --git a/doc/BUILD.md b/doc/BUILD.md index 78061a6ac..2cc6632bb 100644 --- a/doc/BUILD.md +++ b/doc/BUILD.md @@ -111,6 +111,17 @@ This manually applies full release-mode optimizations even when using `--enable-debug`. Implied when not in debug mode. +##### Disable third-party dynamic allocator libraries + +``` +--disable-alloc-libs +``` +`./configure` will detect alternative `malloc()` implementations found in +libraries installed on the system (jemalloc/tcmalloc/etc). Construct developers +may enable these to be configured by default, if detected. To always prevent +any alternative to the default standard library allocator specify this option. + + ##### Logging level ``` diff --git a/include/ircd/Makefile.am b/include/ircd/Makefile.am index 9cdab8a14..f7540bd03 100644 --- a/include/ircd/Makefile.am +++ b/include/ircd/Makefile.am @@ -12,6 +12,7 @@ AM_CPPFLAGS = \ @SNAPPY_CPPFLAGS@ \ @LZ4_CPPFLAGS@ \ @Z_CPPFLAGS@ \ + @MALLOC_CPPFLAGS@ \ @EXTRA_CPPFLAGS@ \ ### diff --git a/ircd/Makefile.am b/ircd/Makefile.am index a7c05154b..2444357c3 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -27,6 +27,7 @@ AM_CPPFLAGS = \ @SNAPPY_CPPFLAGS@ \ @LZ4_CPPFLAGS@ \ @Z_CPPFLAGS@ \ + @MALLOC_CPPFLAGS@ \ -include ircd/ircd.pic.h \ @EXTRA_CPPFLAGS@ \ ### @@ -86,6 +87,7 @@ libircd_la_LDFLAGS = \ @SNAPPY_LDFLAGS@ \ @LZ4_LDFLAGS@ \ @Z_LDFLAGS@ \ + @MALLOC_LDFLAGS@ \ ### libircd_la_LIBADD = \ @@ -99,6 +101,7 @@ libircd_la_LIBADD = \ @SNAPPY_LIBS@ \ @LZ4_LIBS@ \ @Z_LIBS@ \ + @MALLOC_LIBS@ \ @EXTRA_LIBS@ \ ###