fix: ignore unexpected contents for /sys/fs/cgroup/cpu.max (#2394)

Fixes #2391

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-01-10 11:17:37 +02:00 committed by GitHub
parent b8af49cfe5
commit e9453e62e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -475,22 +475,23 @@ bool UpdateResourceLimitsIfInsideContainer(io::MemInfoData* mdata, size_t* max_t
if (auto cpu = ReadFileToString(StrCat(path, "/cpu.max")); cpu.has_value()) { if (auto cpu = ReadFileToString(StrCat(path, "/cpu.max")); cpu.has_value()) {
vector<string_view> res = absl::StrSplit(*cpu, ' '); vector<string_view> res = absl::StrSplit(*cpu, ' ');
CHECK_EQ(res.size(), 2u); // Some linux distributions do not have anything there.
if (res.size() == 2u) {
if (res[0] == "max")
*output = 0u;
else {
CHECK(absl::SimpleAtod(res[0], &count))
<< "Failed in parsing cgroupv2 cpu count, path = " << path << " (read: " << *cpu
<< ")";
CHECK(absl::SimpleAtod(res[1], &timeshare))
<< "Failed in parsing cgroupv2 cpu timeshare, path = " << path << " (read: " << *cpu
<< ")";
if (res[0] == "max") *output = static_cast<size_t>(ceil(count / timeshare));
*output = 0u; }
else {
CHECK(absl::SimpleAtod(res[0], &count))
<< "Failed in parsing cgroupv2 cpu count, path = " << path << " (read: " << *cpu << ")";
CHECK(absl::SimpleAtod(res[1], &timeshare))
<< "Failed in parsing cgroupv2 cpu timeshare, path = " << path << " (read: " << *cpu
<< ")";
*output = static_cast<size_t>(ceil(count / timeshare)); read_something = true;
} }
read_something = true;
} else if (auto quota = ReadFileToString(StrCat(path, "/cpu.cfs_quota_us")); } else if (auto quota = ReadFileToString(StrCat(path, "/cpu.cfs_quota_us"));
quota.has_value()) { quota.has_value()) {
auto period = ReadFileToString(StrCat(path, "/cpu.cfs_period_us")); auto period = ReadFileToString(StrCat(path, "/cpu.cfs_period_us"));