diff options
author | Amirsaman Memaripour <amirsaman.memaripour@mongodb.com> | 2022-01-18 20:09:46 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-07 16:46:31 +0000 |
commit | 2c7c06c4defd5f56d9b71225917f28397766aa12 (patch) | |
tree | b35138ff629a5764aa37999b41c858fddba6b3c4 | |
parent | 762d02f441876037b799bbcdcb250fe13ee6f2a4 (diff) | |
download | mongo-2c7c06c4defd5f56d9b71225917f28397766aa12.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.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/mongo/util/processinfo_linux.cpp b/src/mongo/util/processinfo_linux.cpp index fd2b1378a84..d9b97174c18 100644 --- a/src/mongo/util/processinfo_linux.cpp +++ b/src/mongo/util/processinfo_linux.cpp @@ -56,6 +56,7 @@ #include <fmt/format.h> #include <pcrecpp.h> +#include "mongo/base/parse_number.h" #include "mongo/util/file.h" #include "mongo/util/log.h" #include "mongo/util/static_immortal.h" @@ -557,12 +558,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::parseNumberFromString(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() && parseNumberFromString(groupLimit, &groupMemBytes).isOK()) { + return std::min(systemMemBytes, groupMemBytes); + } } return systemMemBytes; } |