Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
cgroup: cleanup blkio cfq/bfq cgroup weight setup
Browse files Browse the repository at this point in the history
Commit 606fed4a787ee79824ead71ae57123a3c6207195 upstream

Signed-off-by: Konstantin Khlebnikov <[email protected]>
Signed-off-by: Maxim Samoylov <[email protected]>
Link: https://st.yandex-team.ru/PORTO-495
Link: https://st.yandex-team.ru/PORTO-553
  • Loading branch information
koct9i authored and max7255 committed Jul 25, 2022
1 parent a29d090 commit 1ba8c6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
22 changes: 17 additions & 5 deletions src/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,12 @@ TError TBlkioSubsystem::SetIoWeight(TCgroup &cg, const std::string &policy,
double bfq_weight = weight;
TError error;

/*
* Cgroup v1 mess:
* CFQ: 10..1000 default 500
* BFQ: 1..1000 default 100
*/

if (policy == "rt" || policy == "high") {
weight *= 1000;
bfq_weight *= 1000;
Expand All @@ -1113,13 +1119,19 @@ TError TBlkioSubsystem::SetIoWeight(TCgroup &cg, const std::string &policy,
} else
return TError(EError::InvalidValue, "unknown policy: " + policy);

if (HasWeight)
error = cg.SetUint64("blkio.weight", std::min(std::max(weight, 10.), 1000.));
if (cg.Has(CFQ_WEIGHT)) {
error = cg.SetUint64(CFQ_WEIGHT, std::min(std::max(weight, 10.), 1000.));
if (error)
return error;
}

if (!error && HasBfqWeight)
error = cg.SetUint64("blkio.bfq.weight", std::min(std::max(bfq_weight, 1.), 1000.));
if (cg.Has(BFQ_WEIGHT)) {
error = cg.SetUint64(BFQ_WEIGHT, std::min(std::max(bfq_weight, 1.), 1000.));
if (error)
return error;
}

return error;
return OK;
}

// Devices
Expand Down
7 changes: 3 additions & 4 deletions src/cgroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,18 @@ class TNetclsSubsystem : public TSubsystem {

class TBlkioSubsystem : public TSubsystem {
public:
bool HasWeight = false;
const std::string CFQ_WEIGHT = "blkio.weight";
const std::string BFQ_WEIGHT = "blkio.bfq.weight";

bool HasThrottler = false;
bool HasSaneBehavior = false;
bool HasBfqWeight = false;
TBlkioSubsystem() : TSubsystem(CGROUP_BLKIO, "blkio") {}
bool IsDisabled() override { return !config().container().enable_blkio(); }
bool IsOptional() override { return true; }
TError InitializeSubsystem() override {
HasWeight = RootCgroup().Has("blkio.weight");
HasThrottler = RootCgroup().Has("blkio.throttle.read_bps_device");
if (RootCgroup().GetBool("cgroup.sane_behavior", HasSaneBehavior))
HasSaneBehavior = false;
HasBfqWeight = RootCgroup().Has("blkio.bfq.io_serviced");
return OK;
}
enum IoStat {
Expand Down
3 changes: 0 additions & 3 deletions src/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,6 @@ class TIoWeight : public TProperty {
IsDynamic = true;
RequireControllers = CGROUP_BLKIO;
}
void Init(void) {
IsSupported = BlkioSubsystem.HasWeight;
}
TError Get(std::string &value) {
value = StringFormat("%lg", CT->IoWeight);
return OK;
Expand Down

0 comments on commit 1ba8c6b

Please sign in to comment.