summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/util/processinfo_linux.cpp17
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;
}