-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Internal Code
-
Server Programmability
-
ALL
-
Dev Tools 2020-02-24, Service Arch 2022-05-30
-
None
-
None
-
None
-
None
-
None
-
None
-
None
We read "/sys/fs/cgroup/memory/memory.limit_in_bytes".
Someone can check me on this, but I believe this is incorrect. This file is the resources of the entire system, and not the controller managing the mongod process.
I think you have to read "/proc/self/cgroup" to find out which group our "memory" controller is bound to, and read the stats files under the
/sys/fs/cgroup/memory/{group}/
subdir instead.
e.g.:
$ cat /proc/self/cgroup
12:perf_event:/
11:devices:/user.slice
10:blkio:/user.slice
9:memory:/user.slice // <== memory is bound to group /user.slice
8:rdma:/
7:pids:/user.slice/user-1000.slice/session-796.scope
6:cpu,cpuacct:/user.slice
5:cpuset:/
4:net_cls,net_prio:/
3:freezer:/
2:hugetlb:/
1:name=systemd:/user.slice/user-1000.slice/session-796.scope
0::/user.slice/user-1000.slice/session-796.scope
src/mongo/util/processinfo_linux.cpp:
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);
}
return systemMemBytes;
}