diff --git a/CGroups.cpp b/CGroups.cpp index e1f76fa..eefea0d 100644 --- a/CGroups.cpp +++ b/CGroups.cpp @@ -88,6 +88,10 @@ void CGroupCPU::SetShares(uint64_t val) { AppendUint64(_dir + CGROUP_CPU_SHARES_FILE, val); } +bool CGroupCPU::HasCFSQuotaUS() { + return PathExists(_dir + CGROUP_CPU_PERIOD_US_FILE); +} + uint64_t CGroupCPU::GetCFSPeriodUS() { return ReadUint64(_dir + CGROUP_CPU_PERIOD_US_FILE); } diff --git a/CGroups.h b/CGroups.h index ec3ff27..f950c2b 100644 --- a/CGroups.h +++ b/CGroups.h @@ -37,6 +37,7 @@ public: uint64_t GetCFSPeriodUS(); void SetCFSPeriodUS(uint64_t val); + bool HasCFSQuotaUS(); uint64_t GetCFSQuotaUS(); void SetCFSQuotaUS(uint64_t val); diff --git a/CPULimits.cpp b/CPULimits.cpp index 1014224..9c2365e 100644 --- a/CPULimits.cpp +++ b/CPULimits.cpp @@ -50,7 +50,7 @@ std::shared_ptr CPULimits::CGFromConfig(const Config& config, const s auto cg = CGroups::OpenCPU(cg_name); - if (hard_limit < MAX_PCT) { + if (hard_limit < MAX_PCT && cg->HasCFSQuotaUS()) { uint64_t period = cg->GetCFSPeriodUS(); uint64_t quota = static_cast(static_cast(period)*(hard_limit/100)); cg->SetCFSQuotaUS(quota);