@@ -412,6 +412,28 @@ void CGroupMemoryController::setMemoryControllerPath(CString memoryControllerPat
412412 m_cgroupMemoryMemswUsageInBytesFile = getCgroupFile (" memory" , memoryControllerPath, CString (" memory.memsw.usage_in_bytes" ));
413413 m_cgroupMemoryLimitInBytesFile = getCgroupFile (" memory" , memoryControllerPath, CString (" memory.limit_in_bytes" ));
414414 m_cgroupMemoryUsageInBytesFile = getCgroupFile (" memory" , memoryControllerPath, CString (" memory.usage_in_bytes" ));
415+
416+ // when ran within (e.g. docker) container, it's possible that <controller_path> will be specified in /proc/self/cgroup
417+ // and yet the paths like /sys/fs/cgroup/memory/<controller_path>/ will be unavailable
418+ // therefore it's worth falling back to default files so that memory pressure monitor would still work as expected in such cases
419+ const bool shouldFallbackToEmptyPath = isActive ()
420+ && m_cgroupMemoryControllerPath != " /"
421+ && !m_cgroupV2MemoryCurrentFile
422+ && !m_cgroupV2MemoryMemswMaxFile
423+ && !m_cgroupV2MemoryMaxFile
424+ && !m_cgroupV2MemoryHighFile
425+ && !m_cgroupMemoryMemswLimitInBytesFile
426+ && !m_cgroupMemoryLimitInBytesFile
427+ && !m_cgroupMemoryUsageInBytesFile;
428+ if (shouldFallbackToEmptyPath) {
429+ m_cgroupV2MemoryCurrentFile = getCgroupFile (" /" , " " , CString (" memory.current" ));
430+ m_cgroupV2MemoryMemswMaxFile = getCgroupFile (" /" , " " , CString (" memory.memsw.max" ));
431+ m_cgroupV2MemoryMaxFile = getCgroupFile (" /" , " " , CString (" memory.max" ));
432+ m_cgroupV2MemoryHighFile = getCgroupFile (" /" , " " , CString (" memory.high" ));
433+ m_cgroupMemoryMemswLimitInBytesFile = getCgroupFile (" memory" , " " , CString (" memory.memsw.limit_in_bytes" ));
434+ m_cgroupMemoryLimitInBytesFile = getCgroupFile (" memory" , " " , CString (" memory.limit_in_bytes" ));
435+ m_cgroupMemoryUsageInBytesFile = getCgroupFile (" memory" , " " , CString (" memory.usage_in_bytes" ));
436+ }
415437}
416438
417439void CGroupMemoryController::disposeMemoryController ()
0 commit comments