Skip to content

Commit 816415c

Browse files
committed
docs(systemd): state the 250 floor for the bfq weight pre-image
The pre-image of systemd's BFQ_WEIGHT() is only exact from systemd 250. Older releases derive io.bfq.weight from IOWeight differently: 243 to 247 write it as is, so the kernel rejects values above 1000, and 248 and 249 write (weight + 9) / 10. Document the floor on bfq_weight_to_io_weight and skip the contest io weight group below 250. Version-dependent mapping is left out because those older semantics are themselves broken. Signed-off-by: yjjnls <yjjnls@users.noreply.github.com>
1 parent 9371160 commit 816415c

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

  • crates/libcgroups/src/systemd
  • tests/contest/contest/src/tests/cgroups/systemd

‎crates/libcgroups/src/systemd/io.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub enum SystemdIoError {
3131
/// `100 + (io_weight - 100) / 11`. Sending the pre-image `100 + (weight - 100) * 11` above
3232
/// 100 therefore makes the scaled value equal the requested weight for every integer weight
3333
/// in [1, 1000] (the multiplication and division are exact, so no rounding is involved).
34+
///
35+
/// This pre-image is exact from systemd 250. Older releases derive `io.bfq.weight` from
36+
/// `IOWeight` differently: 243 to 247 write it as is (the kernel rejects values above 1000),
37+
/// and 248 and 249 write `(io_weight + 9) / 10`, so the mapping is not meaningful below 250.
38+
///
3439
/// The property is also what keeps the weight after systemd applies the unit again: a value
3540
/// written to cgroupfs only is reset to the `IOWeight` systemd holds, or to the default when
3641
/// the unit has no `IOWeight`.

‎tests/contest/contest/src/tests/cgroups/systemd/io.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use oci_spec::runtime::{
1919
};
2020
use test_framework::{ConditionalTest, TestGroup, TestResult, test_result};
2121

22-
use super::{SCOPE_PREFIX, can_run, show_property, unit_name};
22+
use super::{SCOPE_PREFIX, can_run, show_property, systemd_version, unit_name};
2323
use crate::utils::test_utils::{CGROUP_ROOT, CreateOptions, check_container_created};
2424
use crate::utils::{
2525
cgroup_has_file, is_cgroup_v2_with_controller, is_runtime_runc,
@@ -182,10 +182,15 @@ fn test_io_weight_survives_reapply() -> TestResult {
182182
})
183183
}
184184

185-
/// The systemd driver of runc 1.5.2 does not send IOWeight at all, so its weight is reset by
186-
/// systemd and there is nothing to check for it; these tests are about youki's driver.
185+
/// The mapping targets systemd's BFQ scaling since 250; older releases derive io.bfq.weight
186+
/// differently, so the expectations do not hold there. The systemd driver of runc 1.5.2 does
187+
/// not send IOWeight at all, so its weight is reset by systemd and there is nothing to check
188+
/// for it; these tests are about youki's driver.
187189
fn can_run_io_weight() -> bool {
188-
can_run() && is_cgroup_v2_with_controller(ControllerType::Io) && !is_runtime_runc()
190+
can_run()
191+
&& is_cgroup_v2_with_controller(ControllerType::Io)
192+
&& systemd_version().is_ok_and(|v| v >= 250)
193+
&& !is_runtime_runc()
189194
}
190195

191196
/// The io controller exposes io.bfq.weight in a cgroup once the BFQ scheduler is available.

0 commit comments

Comments
 (0)