Skip to content

Commit 780f413

Browse files
committed
SERVER-119885 Fix handling of the "max" value in cgroup v2 "memory.max"
1 parent 325fae4 commit 780f413

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/mongo/util/processinfo_linux.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ class LinuxSysHelper {
496496
if (f != nullptr) {
497497
if (fgets(fstr, 1023, f) != nullptr)
498498
fstr[strlen(fstr) < 1 ? 0 : strlen(fstr) - 1] = '\0';
499+
else
500+
fstr[0] = '\0';
499501
fclose(f);
500502
}
501503
return fstr;

src/third_party/tcmalloc/dist/tcmalloc/cpu_cache.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ std::string parseLineFromFile(const char* fname) {
4343
if (f != nullptr) {
4444
if (fgets(fstr, 1023, f) != nullptr)
4545
fstr[strlen(fstr) < 1 ? 0 : strlen(fstr) - 1] = '\0';
46+
else
47+
fstr[0] = '\0';
4648
fclose(f);
4749
}
4850

@@ -69,7 +71,8 @@ unsigned long long getMemorySizeLimitInBytes() {
6971
unsigned long long groupMemBytes = 0;
7072
std::string groupLimit = parseLineFromFile(file);
7173

72-
if (!groupLimit.empty() ) {
74+
// The "max" value in cgroups v2 means no limit.
75+
if (!groupLimit.empty() && groupLimit != "max") {
7376
return std::min(systemMemBytes, (unsigned long long)atoll(groupLimit.c_str()));
7477
}
7578
}

0 commit comments

Comments
 (0)