mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #30574 from pmed/issue_25662_cgroup_memory_limit
WIP: use cgroup memory limit in getMemoryAmountOrZero
This commit is contained in:
commit
a487ee6f25
@ -1,4 +1,5 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <fstream>
|
||||||
#include <base/getMemoryAmount.h>
|
#include <base/getMemoryAmount.h>
|
||||||
#include <base/getPageSize.h>
|
#include <base/getPageSize.h>
|
||||||
|
|
||||||
@ -15,6 +16,17 @@
|
|||||||
*/
|
*/
|
||||||
uint64_t getMemoryAmountOrZero()
|
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_t amount = 0; // in case of read error
|
||||||
|
cgroup_limit >> amount;
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int64_t num_pages = sysconf(_SC_PHYS_PAGES);
|
int64_t num_pages = sysconf(_SC_PHYS_PAGES);
|
||||||
if (num_pages <= 0)
|
if (num_pages <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user