diff --git a/base/base/getMemoryAmount.cpp b/base/base/getMemoryAmount.cpp index 59ad10335ed..52a06389432 100644 --- a/base/base/getMemoryAmount.cpp +++ b/base/base/getMemoryAmount.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -15,6 +16,17 @@ */ uint64_t getMemoryAmountOrZero() { +#if defined(OS_LINUX) + // Try to lookup at the Cgroup limit + std::ifstream cgroup_limit("/sys/fs/cgroup/memory/memory.limit_in_bytes"); + if (cgroup_limit.is_open()) + { + uint64 amount = 0; // in case of read error + cgroup_limit >> amount; + return amount; + } +#endif + int64_t num_pages = sysconf(_SC_PHYS_PAGES); if (num_pages <= 0) return 0;