mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
chrore: parse cgroup v2 (#3857)
* chrore: parse cgroup v2 * small parsing logic
This commit is contained in:
parent
1e429c8e59
commit
0cea5fe2ff
1 changed files with 20 additions and 6 deletions
|
@ -462,20 +462,29 @@ bool UpdateResourceLimitsIfInsideContainer(io::MemInfoData* mdata, size_t* max_t
|
|||
/* Update memory limits */
|
||||
|
||||
// Start by reading global memory limits
|
||||
constexpr auto base_mem = "/sys/fs/cgroup/memory"sv;
|
||||
read_mem(StrCat(base_mem, "/memory.limit_in_bytes"), &mdata->mem_total);
|
||||
read_mem(StrCat(base_mem, "/memory.max"), &mdata->mem_total);
|
||||
auto parse_limits = [&](std::string_view base_mem) {
|
||||
read_mem(StrCat(base_mem, "/memory.limit_in_bytes"), &mdata->mem_total);
|
||||
read_mem(StrCat(base_mem, "/memory.max"), &mdata->mem_total);
|
||||
};
|
||||
|
||||
// For v1
|
||||
constexpr auto base_mem_v1 = "/sys/fs/cgroup/memory"sv;
|
||||
parse_limits(base_mem_v1);
|
||||
// For v2 if the previous failed
|
||||
constexpr auto base_mem_v2 = "/sys/fs/cgroup"sv;
|
||||
parse_limits(base_mem_v2);
|
||||
// For v2 under /user.slice
|
||||
constexpr auto base_mem_v2_slice = "/sys/fs/cgroup/user.slice"sv;
|
||||
parse_limits(base_mem_v2_slice);
|
||||
|
||||
// Read cgroup-specific limits
|
||||
read_mem(StrCat(mem_path, "/memory.limit_in_bytes"), &mdata->mem_total);
|
||||
read_mem(StrCat(mem_path, "/memory.max"), &mdata->mem_total);
|
||||
read_mem(StrCat(mem_path, "/memory.high"), &mdata->mem_avail);
|
||||
|
||||
mdata->mem_avail = min(mdata->mem_avail, mdata->mem_total);
|
||||
|
||||
/* Update thread limits */
|
||||
|
||||
constexpr auto base_cpu = "/sys/fs/cgroup/cpu"sv;
|
||||
auto read_cpu = [&read_something](string_view path, size_t* output) {
|
||||
double count{0}, timeshare{1};
|
||||
|
||||
|
@ -534,8 +543,13 @@ bool UpdateResourceLimitsIfInsideContainer(io::MemInfoData* mdata, size_t* max_t
|
|||
}
|
||||
};
|
||||
|
||||
constexpr auto base_cpu = "/sys/fs/cgroup/cpu"sv;
|
||||
read_cpu(base_cpu, max_threads); // global cpu limits
|
||||
read_cpu(cpu_path, max_threads); // cgroup-specific limits
|
||||
constexpr auto base_cpu_v2 = "/sys/fs/cgroup"sv;
|
||||
read_cpu(base_cpu_v2, max_threads); // global cpu limits
|
||||
constexpr auto base_cpu_v2_slice = "/sys/fs/cgroup/user.slice"sv;
|
||||
read_cpu(base_cpu_v2_slice, max_threads); // global cpu limits
|
||||
read_cpu(cpu_path, max_threads); // cgroup-specific limits
|
||||
|
||||
if (!read_something) {
|
||||
LOG(ERROR) << "Failed in deducing any cgroup limits with paths " << mem_path << " and "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue