MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / getCgroupsV2MemoryLimit

Function getCgroupsV2MemoryLimit

base/base/getMemoryAmount.cpp:16–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14{
15
16std::optional<uint64_t> getCgroupsV2MemoryLimit()
17{
18#if defined(OS_LINUX)
19 if (!cgroupsV2Enabled())
20 return {};
21
22 std::filesystem::path current_cgroup = cgroupV2PathOfProcess();
23 if (current_cgroup.empty())
24 return {};
25
26 /// Open the bottom-most nested memory limit setting file. If there is no such file at the current
27 /// level, try again at the parent level as memory settings are inherited.
28 while (current_cgroup != default_cgroups_mount.parent_path())
29 {
30 std::ifstream setting_file(current_cgroup / "memory.max");
31 if (setting_file.is_open())
32 {
33 uint64_t value = {};
34 if (setting_file >> value)
35 return {value};
36 return {}; /// e.g. the cgroups default "max"
37 }
38 current_cgroup = current_cgroup.parent_path();
39 }
40
41 return {};
42#else
43 return {};
44#endif
45}
46
47}
48

Callers 1

getMemoryAmountOrZeroFunction · 0.85

Calls 4

cgroupsV2EnabledFunction · 0.85
cgroupV2PathOfProcessFunction · 0.85
parent_pathMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected