From 713227791ab28c5e09073acb7b2c3c83ca0f0d6a Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Mon, 16 Mar 2015 00:13:38 +0100 Subject: [PATCH] Conditional-compile against minimal tcmalloc. Certain older systems (SLE11 in this case) do not provide the full tcmalloc functionality, due to e.g. incomplete libunwind pieces. Use --with-tcmalloc-minimal to enable the cut-down version. Here's how the various mem allocator switches interact now: --with-jemalloc: overrides --with-tcmalloc & --with-tcmalloc-minimal --with-tcmalloc-minimal: overrides --with-tcmalloc --with-tcmalloc: the default. use --without-tcmalloc to disable Signed-off-by: Thorsten Behrens (cherry picked from commit c6f1c07113ca19547fdac10cd9b817a60142aee2) --- configure.ac | 21 +++++++++++++++++++++ src/Makefile-env.am | 4 ++++ src/perfglue/Makefile.am | 7 +++++++ src/perfglue/heap_profiler.cc | 15 ++++++++++++++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3d86ecd208bf7..cbed5a553d3d1 100644 --- a/configure.ac +++ b/configure.ac @@ -500,6 +500,26 @@ AS_IF([test "x$with_jemalloc" = xyes], [no jemalloc found (do not use --with-jemalloc)])])]) AM_CONDITIONAL(WITH_JEMALLOC, [test "$HAVE_LIBJEMALLOC" = "1"]) +# tcmalloc-minimal? +AC_ARG_WITH([tcmalloc-minimal], + [AS_HELP_STRING([--with-tcmalloc-minimal], [enable minimal tcmalloc support for memory allocations])], + [], + [with_tcmalloc_minimal=no]) + +AS_IF([test "x$with_jemalloc" = "xyes"],[with_tcmalloc_minimal=no],[]) + +TCMALLOC_MINIMAL= +AS_IF([test "x$with_tcmalloc_minimal" != xno], + [AC_CHECK_LIB([tcmalloc_minimal], [malloc], + [AC_SUBST([LIBTCMALLOC], ["-ltcmalloc_minimal"]) + AC_DEFINE([HAVE_LIBTCMALLOC_MINIMAL], [1], + [Define if you have tcmalloc]) + HAVE_LIBTCMALLOC_MINIMAL=1 + ], + [AC_MSG_FAILURE( + [no tcmalloc found (do not use --with-tcmalloc-minimal)])])]) +AM_CONDITIONAL(WITH_TCMALLOC_MINIMAL, [test "$HAVE_LIBTCMALLOC_MINIMAL" = "1"]) + # tcmalloc? AC_ARG_WITH([tcmalloc], [AS_HELP_STRING([--without-tcmalloc], [disable tcmalloc for memory allocations])], @@ -507,6 +527,7 @@ AC_ARG_WITH([tcmalloc], [with_tcmalloc=yes]) AS_IF([test "x$with_jemalloc" = "xyes"],[with_tcmalloc=no],[]) +AS_IF([test "x$with_tcmalloc_minimal" = "xyes"],[with_tcmalloc=no],[]) TCMALLOC= AS_IF([test "x$with_tcmalloc" != xno], diff --git a/src/Makefile-env.am b/src/Makefile-env.am index e5fda78d5ff78..b9374ad50f3d3 100644 --- a/src/Makefile-env.am +++ b/src/Makefile-env.am @@ -178,6 +178,10 @@ if WITH_LIBROCKSDB LIBOS += libos_rocksdb.la endif # WITH_LIBROCKSDB +if WITH_TCMALLOC_MINIMAL +LIBPERFGLUE += -ltcmalloc_minimal +endif # WITH_TCMALLOC_MINIMAL + if WITH_TCMALLOC LIBPERFGLUE += -ltcmalloc endif # WITH_TCMALLOC diff --git a/src/perfglue/Makefile.am b/src/perfglue/Makefile.am index 9228b219a5708..77c3085e6d0f1 100644 --- a/src/perfglue/Makefile.am +++ b/src/perfglue/Makefile.am @@ -6,7 +6,14 @@ libperfglue_la_LIBADD = -ltcmalloc AM_CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free AM_CXXFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free else +if WITH_TCMALLOC_MINIMAL +libperfglue_la_SOURCES += perfglue/heap_profiler.cc +libperfglue_la_LIBADD = -ltcmalloc_minimal +AM_CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free +AM_CXXFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free +else libperfglue_la_SOURCES += perfglue/disabled_heap_profiler.cc +endif # WITH_TCMALLOC_MINIMAL endif # WITH_TCMALLOC if WITH_PROFILER diff --git a/src/perfglue/heap_profiler.cc b/src/perfglue/heap_profiler.cc index 0fe1f9a43db7d..a0307ca204d95 100644 --- a/src/perfglue/heap_profiler.cc +++ b/src/perfglue/heap_profiler.cc @@ -61,7 +61,11 @@ void ceph_heap_release_free_memory() bool ceph_heap_profiler_running() { +#ifdef HAVE_LIBTCMALLOC return IsHeapProfilerRunning(); +#else + return false; +#endif } static void get_profile_name(char *profile_name, int profile_name_len) @@ -83,21 +87,27 @@ static void get_profile_name(char *profile_name, int profile_name_len) void ceph_heap_profiler_start() { +#ifdef HAVE_LIBTCMALLOC char profile_name[PATH_MAX]; get_profile_name(profile_name, sizeof(profile_name)); generic_dout(0) << "turning on heap profiler with prefix " << profile_name << dendl; HeapProfilerStart(profile_name); +#endif } void ceph_heap_profiler_stop() { +#ifdef HAVE_LIBTCMALLOC HeapProfilerStop(); +#endif } void ceph_heap_profiler_dump(const char *reason) { +#ifdef HAVE_LIBTCMALLOC HeapProfilerDump(reason); +#endif } #define HEAP_PROFILER_STATS_SIZE 2048 @@ -105,6 +115,7 @@ void ceph_heap_profiler_dump(const char *reason) void ceph_heap_profiler_handle_command(const std::vector& cmd, ostream& out) { +#ifdef HAVE_LIBTCMALLOC if (cmd.size() == 1 && cmd[0] == "dump") { if (!ceph_heap_profiler_running()) { out << "heap profiler not running; can't dump"; @@ -124,7 +135,9 @@ void ceph_heap_profiler_handle_command(const std::vector& cmd, } else if (cmd.size() == 1 && cmd[0] == "release") { ceph_heap_release_free_memory(); out << g_conf->name << " releasing free RAM back to system."; - } else if (cmd.size() == 1 && cmd[0] == "stats") { + } else +#endif + if (cmd.size() == 1 && cmd[0] == "stats") { char heap_stats[HEAP_PROFILER_STATS_SIZE]; ceph_heap_profiler_stats(heap_stats, sizeof(heap_stats)); out << g_conf->name << " tcmalloc heap stats:" -- 2.39.5