Merge pull request #6710 from Jordan9500/cherry-pick-cgroupv2-fix

rustjail: Use CPUWeight with systemd and CgroupsV2
This commit is contained in:
Steve Horsman
2023-04-25 15:28:29 +01:00
committed by GitHub

View File

@@ -71,7 +71,7 @@ impl Cpu {
}
// v2:
// cpu.shares <-> CPUShares
// cpu.shares <-> CPUWeight
// cpu.period <-> CPUQuotaPeriodUSec
// cpu.period & cpu.quota <-> CPUQuotaPerSecUSec
fn unified_apply(
@@ -80,8 +80,8 @@ impl Cpu {
systemd_version: &str,
) -> Result<()> {
if let Some(shares) = cpu_resources.shares {
let unified_shares = get_unified_cpushares(shares);
properties.push(("CPUShares", Value::U64(unified_shares)));
let weight = shares_to_weight(shares);
properties.push(("CPUWeight", Value::U64(weight)));
}
if let Some(period) = cpu_resources.period {
@@ -104,7 +104,7 @@ impl Cpu {
// ref: https://github.com/containers/crun/blob/main/crun.1.md#cgroup-v2
// [2-262144] to [1-10000]
fn get_unified_cpushares(shares: u64) -> u64 {
fn shares_to_weight(shares: u64) -> u64 {
if shares == 0 {
return 100;
}