summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmirsaman Memaripour <amirsaman.memaripour@mongodb.com>2022-01-18 20:09:46 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-07 15:40:54 +0000
commitd719e12c3e8a0ae5744e3bd53c27bcffc8e575c4 (patch)
treeb614ca55cc9f82dd270bd408dee58e091ae9387d
parent9f5269c839f55f93b148bad392963efb89a5ab89 (diff)
downloadmongo-d719e12c3e8a0ae5744e3bd53c27bcffc8e575c4.tar.gz
SERVER-60412 Support using cgroups v2 to inquire about the memory limit
(cherry picked from commit 6bc31230f0cd0de66f02268c5ce0920c4f27effe)
-rw-r--r--src/mongo/util/processinfo_linux.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/mongo/util/processinfo_linux.cpp b/src/mongo/util/processinfo_linux.cpp
index eae0e9b7764..37e3d2ea3fc 100644
--- a/src/mongo/util/processinfo_linux.cpp
+++ b/src/mongo/util/processinfo_linux.cpp
@@ -57,6 +57,7 @@
#include <fmt/format.h>
#include <pcrecpp.h>
+#include "mongo/base/parse_number.h"
#include "mongo/logv2/log.h"
#include "mongo/util/ctype.h"
#include "mongo/util/file.h"
@@ -558,11 +559,16 @@ public:
* return the actual memory we'll have available to the process.
*/
static unsigned long long getMemorySizeLimit() {
- unsigned long long systemMemBytes = getSystemMemorySize();
- unsigned long long cgroupMemBytes = 0;
- std::string cgmemlimit = readLineFromFile("/sys/fs/cgroup/memory/memory.limit_in_bytes");
- if (!cgmemlimit.empty() && mongo::NumberParser{}(cgmemlimit, &cgroupMemBytes).isOK()) {
- return std::min(systemMemBytes, cgroupMemBytes);
+ const unsigned long long systemMemBytes = getSystemMemorySize();
+ for (const char* file : {
+ "/sys/fs/cgroup/memory.max", // cgroups v2
+ "/sys/fs/cgroup/memory/memory.limit_in_bytes" // cgroups v1
+ }) {
+ unsigned long long groupMemBytes = 0;
+ std::string groupLimit = readLineFromFile(file);
+ if (!groupLimit.empty() && NumberParser{}(groupLimit, &groupMemBytes).isOK()) {
+ return std::min(systemMemBytes, groupMemBytes);
+ }
}
return systemMemBytes;
}