Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for CFS bandwith burst #834

Merged
merged 2 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions crates/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/libcgroups/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ nix = "0.23.1"
procfs = "0.12.0"
log = "0.4"
anyhow = "1.0"
oci-spec = "0.5.5"
oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "89376af" }
dbus = { version = "0.9.5", optional = true }
fixedbitset = "0.4.1"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -35,7 +35,7 @@ errno = { version = "0.2.8", optional = true }
libc = { version = "0.2.122", optional = true }

[dev-dependencies]
oci-spec = { version = "0.5.5", features = ["proptests"] }
oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "89376af", features = ["proptests"] }
quickcheck = "1"
mockall = { version = "0.11.0", features = [] }
clap = "3.1.8"
Expand Down
23 changes: 23 additions & 0 deletions crates/libcgroups/src/v1/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::Controller;
const CGROUP_CPU_SHARES: &str = "cpu.shares";
const CGROUP_CPU_QUOTA: &str = "cpu.cfs_quota_us";
const CGROUP_CPU_PERIOD: &str = "cpu.cfs_period_us";
const CGROUP_CPU_BURST: &str = "cpu.cfs_burst_us";
const CGROUP_CPU_RT_RUNTIME: &str = "cpu.rt_runtime_us";
const CGROUP_CPU_RT_PERIOD: &str = "cpu.rt_period_us";
const CGROUP_CPU_STAT: &str = "cpu.stat";
Expand Down Expand Up @@ -113,6 +114,10 @@ impl Cpu {
}
}

if let Some(cpu_burst) = cpu.burst() {
common::write_cgroup_file(root_path.join(CGROUP_CPU_BURST), cpu_burst)?;
}

if let Some(rt_runtime) = cpu.realtime_runtime() {
if rt_runtime != 0 {
common::write_cgroup_file(root_path.join(CGROUP_CPU_RT_RUNTIME), rt_runtime)?;
Expand Down Expand Up @@ -242,4 +247,22 @@ mod tests {
};
assert_eq!(actual, expected);
}

#[test]
fn test_set_burst() {
// arrange
let expected_burst: u64 = 100_000;
let (tmp, max) = setup("test_set_burst", CGROUP_CPU_BURST);
let cpu = LinuxCpuBuilder::default()
.burst(expected_burst)
.build()
.unwrap();

// act
Cpu::apply(&tmp, &cpu).expect("apply cpu");

// assert
let actual_burst = fs::read_to_string(max).expect("read burst");
assert_eq!(actual_burst, expected_burst.to_string());
}
}
17 changes: 17 additions & 0 deletions crates/libcgroups/src/v2/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use super::controller::Controller;

const CGROUP_CPU_WEIGHT: &str = "cpu.weight";
const CGROUP_CPU_MAX: &str = "cpu.max";
const CGROUP_CPU_BURST: &str = "cpu.max.burst";
const UNRESTRICTED_QUOTA: &str = "max";
const MAX_CPU_WEIGHT: u64 = 10000;

Expand Down Expand Up @@ -91,6 +92,10 @@ impl Cpu {
common::write_cgroup_file_str(&cpu_max_file, &cpu_max)?;
}

if let Some(burst) = cpu.burst() {
common::write_cgroup_file(path.join(CGROUP_CPU_BURST), burst)?;
}

Ok(())
}

Expand Down Expand Up @@ -274,4 +279,16 @@ mod tests {

assert_eq!(actual, expected);
}

#[test]
fn test_burst() {
let expected = 100000u64;
let (tmp, burst_file) = setup("test_burst", CGROUP_CPU_BURST);
let cpu = LinuxCpuBuilder::default().burst(expected).build().unwrap();

Cpu::apply(&tmp, &cpu).expect("apply cpu");

let actual = fs::read_to_string(burst_file).expect("read burst file");
assert_eq!(actual, expected.to_string());
}
}
4 changes: 2 additions & 2 deletions crates/libcontainer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ libc = "0.2.122"
log = "0.4"
mio = { version = "0.8.2", features = ["os-ext", "os-poll"] }
nix = "0.23.1"
oci-spec = "0.5.5"
oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "89376af" }
path-clean = "0.1.0"
procfs = "0.12.0"
prctl = "1.0.0"
Expand All @@ -43,7 +43,7 @@ wasmer = { version = "2.2.0", optional = true }
wasmer-wasi = { version = "2.2.0", optional = true }

[dev-dependencies]
oci-spec = { version = "0.5.5", features = ["proptests"] }
oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "89376af", features = ["proptests"] }
quickcheck = "1"
serial_test = "0.6.0"
rand = "0.8.5"
2 changes: 1 addition & 1 deletion crates/youki/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ libcontainer = { version = "0.0.3", path = "../libcontainer" }
liboci-cli = { version = "0.0.3", path = "../liboci-cli" }
log = { version = "0.4", features = ["std"]}
nix = "0.23.1"
oci-spec = "0.5.5"
oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "89376af" }
once_cell = "1.10.0"
pentacle = "1.0.0"
procfs = "0.12.0"
Expand Down