use cgroup memory limit in getMemoryAmountOrZero

Try to read the memory amount from /sys/fs/cgroup/memory/memory.limit_in_bytes

See issue #
This commit is contained in:
Pavel Medvedev 2021-10-23 02:54:58 +02:00
parent 75c16b8f89
commit eaca39ba05

View File

@ -1,4 +1,5 @@
#include <stdexcept>
#include <fstream>
#include <base/getMemoryAmount.h>
#include <base/getPageSize.h>
@ -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;