summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Ingo <henrik.ingo@mongodb.com>2019-12-12 14:01:44 +0000
committerevergreen <evergreen@mongodb.com>2019-12-12 14:01:44 +0000
commit34e32dfd5562e00d416ca7a49e6a45d1e9fa2239 (patch)
tree4c72846d30be6ec0445401616556f18fa8e7f94c
parent0b5af52fd0fcbeb8f584a98db934e3b6a7a6b826 (diff)
downloadmongo-34e32dfd5562e00d416ca7a49e6a45d1e9fa2239.tar.gz
SERVER-42697 Add setParameter tcmallocReleaseRate
(Cherry picked from commit 97a3e24c6bb07ae3a108c0eeb1d00ba36332b7d6)
-rw-r--r--jstests/noPassthroughWithMongod/tcmalloc.js23
-rw-r--r--src/mongo/util/tcmalloc_server_status_section.cpp3
-rw-r--r--src/mongo/util/tcmalloc_set_parameter.cpp59
3 files changed, 85 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/tcmalloc.js b/jstests/noPassthroughWithMongod/tcmalloc.js
new file mode 100644
index 00000000000..44852893809
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/tcmalloc.js
@@ -0,0 +1,23 @@
+// Assert setting tcmalloc_release_rate with setParameter.
+
+(function() {
+ "use strict";
+
+ // Check that setParameter is available on this build. And whether tcmallocReleaseRate is.
+ function hasTcSetParameter() {
+ const commandResult = db.adminCommand({getParameter: 1, tcmallocReleaseRate: 1});
+ if (commandResult.ok)
+ return true;
+ else
+ return false;
+ }
+
+ if (hasTcSetParameter()) {
+ assert.commandWorked(db.adminCommand({setParameter: 1, tcmallocReleaseRate: 10}));
+ assert.commandWorked(db.adminCommand({setParameter: 1, tcmallocReleaseRate: 5.0}));
+ assert.commandWorked(db.adminCommand({setParameter: 1, tcmallocReleaseRate: 0.01}));
+ assert.commandWorked(db.adminCommand({setParameter: 1, tcmallocReleaseRate: 0}));
+ assert.commandFailed(db.adminCommand({setParameter: 1, tcmallocReleaseRate: -1.0}));
+ assert.commandFailed(db.adminCommand({setParameter: 1, tcmallocReleaseRate: "foo"}));
+ }
+}()); \ No newline at end of file
diff --git a/src/mongo/util/tcmalloc_server_status_section.cpp b/src/mongo/util/tcmalloc_server_status_section.cpp
index ba92712bdde..6fd97941812 100644
--- a/src/mongo/util/tcmalloc_server_status_section.cpp
+++ b/src/mongo/util/tcmalloc_server_status_section.cpp
@@ -185,6 +185,9 @@ public:
appendNumericPropertyIfAvailable(
sub, "spinlock_total_delay_ns", "tcmalloc.spinlock_total_delay_ns");
+ auto tcmallocReleaseRate = MallocExtension::instance()->GetMemoryReleaseRate();
+ sub.appendNumber("release_rate", tcmallocReleaseRate);
+
#if MONGO_HAVE_GPERFTOOLS_SIZE_CLASS_STATS
if (verbosity >= 2) {
// Size class information
diff --git a/src/mongo/util/tcmalloc_set_parameter.cpp b/src/mongo/util/tcmalloc_set_parameter.cpp
index 3e18bef2bcd..3c054940522 100644
--- a/src/mongo/util/tcmalloc_set_parameter.cpp
+++ b/src/mongo/util/tcmalloc_set_parameter.cpp
@@ -124,12 +124,70 @@ Status TcmallocNumericPropertyServerParameter::setFromString(const std::string&
return set(builder.done().firstElement());
}
+// setParameter for tcmalloc_release_rate
+class TcmallocReleaseRateServerParameter : public ServerParameter {
+ MONGO_DISALLOW_COPYING(TcmallocReleaseRateServerParameter);
+
+public:
+ explicit TcmallocReleaseRateServerParameter();
+
+ virtual void append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& name);
+ virtual Status set(const BSONElement& newValueElement);
+ virtual Status setFromString(const std::string& str);
+};
+
+TcmallocReleaseRateServerParameter::TcmallocReleaseRateServerParameter()
+ : ServerParameter(ServerParameterSet::getGlobal(), "tcmallocReleaseRate", true, true) {}
+
+void TcmallocReleaseRateServerParameter::append(OperationContext*,
+ BSONObjBuilder& builder,
+ const std::string& fieldName) {
+ auto value = MallocExtension::instance()->GetMemoryReleaseRate();
+ builder.append(fieldName, value);
+}
+
+Status TcmallocReleaseRateServerParameter::set(const BSONElement& newValueElement) {
+ if (!newValueElement.isNumber()) {
+ return Status(ErrorCodes::TypeMismatch,
+ str::stream() << "Expected server parameter " << newValueElement.fieldName()
+ << " to have numeric type, but found "
+ << newValueElement.toString(false)
+ << " of type "
+ << typeName(newValueElement.type()));
+ }
+ double value = newValueElement.numberDouble();
+ if (value < 0) {
+ return {ErrorCodes::BadValue,
+ str::stream() << "tcmallocReleaseRate cannot be negative: " << value};
+ }
+ MallocExtension::instance()->SetMemoryReleaseRate(value);
+ return Status::OK();
+}
+
+Status TcmallocReleaseRateServerParameter::setFromString(const std::string& tcmalloc_release_rate) {
+ double value;
+ Status status = parseNumberFromString(tcmalloc_release_rate, &value);
+ if (!status.isOK()) {
+ return status;
+ }
+ if (value < 0) {
+ return {ErrorCodes::BadValue,
+ str::stream() << "tcmallocReleaseRate cannot be negative: "
+ << tcmalloc_release_rate};
+ }
+
+ MallocExtension::instance()->SetMemoryReleaseRate(value);
+ return Status::OK();
+}
+
TcmallocNumericPropertyServerParameter tcmallocMaxTotalThreadCacheBytesParameter(
"tcmallocMaxTotalThreadCacheBytes", "tcmalloc.max_total_thread_cache_bytes");
TcmallocNumericPropertyServerParameter tcmallocAggressiveMemoryDecommit(
"tcmallocAggressiveMemoryDecommit", "tcmalloc.aggressive_memory_decommit");
+TcmallocReleaseRateServerParameter tcmallocReleaseRate();
+
MONGO_INITIALIZER_GENERAL(TcmallocConfigurationDefaults,
MONGO_NO_PREREQUISITES,
("BeginStartupOptionHandling"))
@@ -151,4 +209,5 @@ MONGO_INITIALIZER_GENERAL(TcmallocConfigurationDefaults,
}
} // namespace
+
} // namespace mongo