Skip to content

Commit

Permalink
agent: correct CPUShares and CPUWeight value
Browse files Browse the repository at this point in the history
If cgroup driver is systemd, CPUShares, for cgroup v1, should be at
least 2 [1] and CPUWeight for cgroup v2, should be at least 1 [2].

Fixes: #8340
Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>

[1] https://github.com/systemd/systemd/blob/d19434fbf81db04d03c8cffa87821f754a86635b/src/basic/cgroup-util.h#L122
[2] https://github.com/systemd/systemd/blob/d19434fbf81db04d03c8cffa87821f754a86635b/src/basic/cgroup-util.h#L91
  • Loading branch information
jongwu committed Oct 31, 2023
1 parent 148c565 commit 284715f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/agent/rustjail/src/cgroups/systemd/subsystem/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ impl Cpu {
systemd_version: &str,
) -> Result<()> {
if let Some(shares) = cpu_resources.shares {
properties.push(("CPUShares", Value::U64(shares)));
// Minimum value of CPUShares should be 2, see https://github.com/systemd/systemd/blob/d19434fbf81db04d03c8cffa87821f754a86635b/src/basic/cgroup-util.h#L122
if shares >= 2 {
properties.push(("CPUShares", Value::U64(shares)));
}
}

if let Some(period) = cpu_resources.period {
Expand Down Expand Up @@ -81,7 +84,9 @@ impl Cpu {
) -> Result<()> {
if let Some(shares) = cpu_resources.shares {
let weight = shares_to_weight(shares);
properties.push(("CPUWeight", Value::U64(weight)));
if weight != 0 {
properties.push(("CPUWeight", Value::U64(weight)));
}
}

if let Some(period) = cpu_resources.period {
Expand Down

0 comments on commit 284715f

Please sign in to comment.