| 14 | { |
| 15 | |
| 16 | std::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 |
no test coverage detected