diff options
author | Andy Schwerin <schwerin@10gen.com> | 2012-08-10 13:32:42 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-08-10 17:19:08 -0400 |
commit | eee3fe4ce66c7bbda9329a3c8bd8e3549b07437c (patch) | |
tree | 7539b815986392be5e98409ffbfb81b077b27f2e /src | |
parent | b49bac3c24d57d412a623545c9a3c367ca595b7e (diff) | |
download | mongo-eee3fe4ce66c7bbda9329a3c8bd8e3549b07437c.tar.gz |
SERVER-4683 Support the imported tcmalloc, ystem tcmalloc or the default system allocator library.
Pass --allocator=tcmalloc (default on Linux) or --allocator=system (default elsewhere)
to control which allocator is used, and --use-system-tcmalloc to use the system-
installed tcmalloc instead of the one in the mongo source tree if you use --allocator=tcmalloc.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/SConscript | 1 | ||||
-rw-r--r-- | src/third_party/SConscript | 7 | ||||
-rw-r--r-- | src/third_party/gperftools-2.0/SConscript | 60 | ||||
-rw-r--r-- | src/third_party/gperftools-2.0/src/config-10gen-linux.h | 3 | ||||
-rw-r--r-- | src/third_party/shim_allocator.cpp | 2 |
5 files changed, 70 insertions, 3 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 389a386aabe..181e89b3caf 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -31,6 +31,7 @@ env.StaticLibrary('foundation', 'util/time_support.cpp', ], LIBDEPS=['stacktrace', + '$BUILD_DIR/third_party/shim_allocator', '$BUILD_DIR/third_party/shim_boost']) env.StaticLibrary('stringutils', ['util/stringutils.cpp', 'util/base64.cpp',]) diff --git a/src/third_party/SConscript b/src/third_party/SConscript index 0b4bfb8455d..5a535710222 100644 --- a/src/third_party/SConscript +++ b/src/third_party/SConscript @@ -42,3 +42,10 @@ else: env.Append(CPPPATH='$BUILD_DIR/third_party/js-1.7') env.SConscript('js-1.7/SConscript') env.StaticLibrary('shim_spidermonkey', ['shim_spidermonkey.cpp'], LIBDEPS=['js-1.7/js']) + +if (GetOption("allocator") != "tcmalloc") or use_system_version_of_library("tcmalloc"): + env.StaticLibrary("shim_allocator", "shim_allocator.cpp") +else: + env.SConscript('gperftools-2.0/SConscript') + env.StaticLibrary('shim_allocator', 'shim_allocator.cpp', + LIBDEPS=['gperftools-2.0/tcmalloc_minimal']) diff --git a/src/third_party/gperftools-2.0/SConscript b/src/third_party/gperftools-2.0/SConscript new file mode 100644 index 00000000000..c599bae2b5f --- /dev/null +++ b/src/third_party/gperftools-2.0/SConscript @@ -0,0 +1,60 @@ +# -*- mode: python -*- + +Import("env") + +files = [ + 'src/base/dynamic_annotations.c', + 'src/base/spinlock_internal.cc', + 'src/base/logging.cc', + 'src/base/atomicops-internals-x86.cc', + 'src/base/sysinfo.cc', + 'src/base/spinlock.cc', + 'src/tcmalloc.cc', + 'src/malloc_hook.cc', + 'src/span.cc', + 'src/maybe_threads.cc', + 'src/internal_logging.cc', + 'src/symbolize.cc', + 'src/system-alloc.cc', + 'src/memfs_malloc.cc', + 'src/central_freelist.cc', + 'src/thread_cache.cc', + 'src/page_heap.cc', + 'src/common.cc', + 'src/static_vars.cc', + 'src/stack_trace_table.cc', + 'src/malloc_extension.cc', + 'src/sampler.cc', + 'src/stacktrace.cc' + ] + +__malloc_hook_fragment = ''' +#include <malloc.h> +void* (* volatile __malloc_hook)(size_t, const void*) = 0; +''' + +def __checkMallocHookVolatile(check_context): + check_context.Message("Checking if __malloc_hook is declared volatile... ") + is_malloc_hook_volatile = check_context.TryCompile(__malloc_hook_fragment, '.cc') + check_context.Result(is_malloc_hook_volatile) + check_context.env.Append(CPPDEFINES=dict( + MALLOC_HOOK_MAYBE_VOLATILE=(is_malloc_hook_volatile and "volatile" or ""))) + +conf = Configure(env.Clone(), custom_tests=dict(CheckMallocHookVolatile=__checkMallocHookVolatile)) +conf.CheckMallocHookVolatile() +env = conf.Finish() + + +env.Append( CPPDEFINES=["NO_TCMALLOC_SAMPLES","NO_TCMALLOC_SAMPLES","NO_HEAP_CHECK"] ) +env.Prepend( CPPPATH=["src/"] ) + +def removeIfPresent(lst, item): + try: + lst.remove(item) + except ValueError: + pass + +for to_remove in ['-Werror', "-Wsign-compare","-Wall"]: + removeIfPresent(env['CCFLAGS'], to_remove) + +env.StaticLibrary('tcmalloc_minimal', files) diff --git a/src/third_party/gperftools-2.0/src/config-10gen-linux.h b/src/third_party/gperftools-2.0/src/config-10gen-linux.h index d893b32d07c..100f86adc36 100644 --- a/src/third_party/gperftools-2.0/src/config-10gen-linux.h +++ b/src/third_party/gperftools-2.0/src/config-10gen-linux.h @@ -190,9 +190,6 @@ */ #define LT_OBJDIR ".libs/" -/* Define to 'volatile' if __malloc_hook is declared volatile */ -#define MALLOC_HOOK_MAYBE_VOLATILE volatile - /* Define to 1 if your C compiler doesn't accept -c and -o together. */ /* #undef NO_MINUS_C_MINUS_O */ diff --git a/src/third_party/shim_allocator.cpp b/src/third_party/shim_allocator.cpp new file mode 100644 index 00000000000..777ede8d4a0 --- /dev/null +++ b/src/third_party/shim_allocator.cpp @@ -0,0 +1,2 @@ +// This file intentionally blank. shim_allocator.cpp is part of the third_party/shim_allocator +// library, used to manage memory allocator selection (tcmalloc, libc, etc.). |