summaryrefslogtreecommitdiff
path: root/src/mongo/util/tcmalloc_set_parameter.cpp
diff options
context:
space:
mode:
authorVincent Do <vincent.do@10gen.com>2016-04-27 10:29:27 -0400
committerVincent Do <vincent.do@10gen.com>2016-05-03 12:01:56 -0400
commit9fac819a2b924cc2b7b1da76d24ecb09e6295d5e (patch)
treebbbe15f822db47a51c2e2cabb060f6da7108b25d /src/mongo/util/tcmalloc_set_parameter.cpp
parent3e94fa7903c88c9ff90cd72b5b4c09d01ecf00bf (diff)
downloadmongo-9fac819a2b924cc2b7b1da76d24ecb09e6295d5e.tar.gz
SERVER-23538 Set tcmalloc cache size based on system memory size
Diffstat (limited to 'src/mongo/util/tcmalloc_set_parameter.cpp')
-rw-r--r--src/mongo/util/tcmalloc_set_parameter.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/mongo/util/tcmalloc_set_parameter.cpp b/src/mongo/util/tcmalloc_set_parameter.cpp
index 649815612bf..951086ae4c1 100644
--- a/src/mongo/util/tcmalloc_set_parameter.cpp
+++ b/src/mongo/util/tcmalloc_set_parameter.cpp
@@ -32,7 +32,8 @@
#include "mongo/platform/basic.h"
-#include "gperftools/malloc_extension.h"
+#include <algorithm>
+#include <gperftools/malloc_extension.h>
#include <valgrind/valgrind.h>
#include "mongo/base/disallow_copying.h"
@@ -42,6 +43,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/server_parameters.h"
#include "mongo/util/mongoutils/str.h"
+#include "mongo/util/processinfo.h"
namespace mongo {
namespace {
@@ -125,14 +127,22 @@ TcmallocNumericPropertyServerParameter tcmallocAggressiveMemoryDecommit(
"tcmallocAggressiveMemoryDecommit", "tcmalloc.aggressive_memory_decommit");
MONGO_INITIALIZER_GENERAL(TcmallocConfigurationDefaults,
- MONGO_NO_PREREQUISITES,
+ ("SystemInfo"),
("BeginStartupOptionHandling"))(InitializerContext*) {
// Before processing the command line options, if the user has not specified a value in via
// the environment, set tcmalloc.max_total_thread_cache_bytes to its default value.
if (getenv("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES")) {
return Status::OK();
}
- return tcmallocMaxTotalThreadCacheBytesParameter.setFromString("0x40000000" /* 1024MB */);
+
+ ProcessInfo pi;
+ size_t systemMemorySizeMB = pi.getMemSizeMB();
+ size_t defaultTcMallocCacheSize = 1024 * 1024 * 1024; // 1024MB in bytes
+ size_t derivedTcMallocCacheSize =
+ (systemMemorySizeMB / 8) * 1024 * 1024; // 1/8 of system memory in bytes
+ size_t cacheSize = std::min(defaultTcMallocCacheSize, derivedTcMallocCacheSize);
+
+ return tcmallocMaxTotalThreadCacheBytesParameter.setFromString(std::to_string(cacheSize));
}
} // namespace