Repository navigation
Conversation
|
Thank you for PR. Could you add integration tests for this change under https://github.com/youki-dev/youki/tree/main/tests/contest/contest/src/tests/cgroups/systemd? |
|
Added integration tests for this in commit 1575797, as a new |
|
@ARMeeru |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the systemd I/O weight changes.
No open issues 🎉
What changed in this PR
Addresses #3897 by sending supported I/O weights through systemd’s IOWeight property, preserving them when systemd reapplies a container unit’s settings.
Changes:
- Adds BFQ-compatible weight conversion and validates structured weights, keeping zero as a no-op.
- Maps plain unified
io.bfq.weightvalues toIOWeight, while leaving other forms andio.weighton the existing cgroupfs path. - Adds unit and integration tests for conversion, property values, and persistence after unrelated property updates.
| File | Description |
|---|---|
| tests/contest/contest/src/tests/cgroups/systemd/mod.rs | Exposes the systemd I/O test module. |
| tests/contest/contest/src/tests/cgroups/systemd/io.rs | Tests weight application and persistence, with runtime and kernel capability checks. |
| tests/contest/contest/src/main.rs | Registers the systemd I/O test group. |
| crates/libcgroups/src/systemd/unified.rs | Maps plain unified BFQ weights to IOWeight and tests fallback behavior. |
| crates/libcgroups/src/systemd/io.rs | Adds weight validation, BFQ conversion, property emission, and unit tests. |
Review effort: Balanced
ARMeeru
left a comment
There was a problem hiding this comment.
I ran this at 1575797 on Fedora (systemd 262, kernel 7.3, aarch64, BFQ available), against main and runc 1.5.3.
- The new
cgroup_systemd_iogroup, as root: 4 ok on this PR, 4 not ok on main (IOWeight=[not set]), 4 skipped withRUNTIME_KIND=runc. Without the runc gate all 4 fail on runc, so the gate is needed.cgroup_systemd_unified,cgroup_v2_ioandcgroup_systemd_devicesstill pass with this PR. - Rootless with the io controller delegated:
blockIO.weight: 500gives io.bfq.weight 500, io.weight 4500 and IOWeight 4500, and all three stay after an unrelatedset-property. Weight 50 gives 50 for all three. cargo test -p libcgroups --all-features --lib(272), clippy and fmt pass.
One point I think needs a change, inline on bfq_weight_to_io_weight: the pre-image is only exact from systemd 250.
Two smaller ones on the description:
- It still offers the contest test as a follow-up. 1575797 adds it, so the Testing section could describe the new group instead.
- "matches what runc writes" holds for io.bfq.weight. io.weight is 4500 here, where runc leaves it at 100.
| /// The property is also what keeps the weight after systemd applies the unit again: a value | ||
| /// written to cgroupfs only is reset to the `IOWeight` systemd holds, or to the default when | ||
| /// the unit has no `IOWeight`. | ||
| pub fn bfq_weight_to_io_weight(weight: u16) -> u64 { |
There was a problem hiding this comment.
This inverse matches BFQ_WEIGHT(), which systemd has had since 250. Older versions derive io.bfq.weight from IOWeight differently (src/core/cgroup.c at the tags):
- 243 to 247 write IOWeight as is. The kernel rejects anything above 1000 (
echo 4500 > io.bfq.weightgivesNumerical result out of rangehere), so weight 500 would leave io.bfq.weight at 100. - 248 and 249 write
(weight + 9) / 10, so 500 gives 450 and 50 gives 5.
I couldn't measure these, since this host only has 262. Ubuntu 22.04 ships 249 and Debian 11 ships 247. Io::apply already receives the systemd version (the _: u32), so the map could take it: w up to 247, w * 10 for 248 and 249, and the current formula from 250. The unified tests that pass 245 would then need 250 or later. If you'd rather not support those versions, could the doc comment and the description state the 250 floor, with the contest group skipping below it, like the version checks in the contest's systemd/unified.rs?
There was a problem hiding this comment.
Thanks. I went with the floor: bfq_weight_to_io_weight now documents that the pre-image is exact from systemd 250, and the contest group skips below 250 (same version gate as the other systemd tests). Version-dependent mapping would only fit the older semantics, so I left it out; the PR description now states the floor too. Fixed in baa4806.
|
@ARMeeru Thanks for the measurements and the review. Updated in baa4806: the mapping declares the systemd 250 floor and the contest group skips older systemd, the Testing section now describes the new |
|
Thanks, all three look good to me in baa4806. I have nothing more from my side; the rest is up to the maintainers. |
With the systemd cgroup driver the io controller only read the throttle device lists, so resources.blockIO.weight never reached the unit: no IOWeight property was set for it, and nothing was written to cgroupfs either. A weight written to cgroupfs instead, such as a plain io.bfq.weight value in resources.unified, was reset to the default as soon as systemd applied the unit's cgroup properties again, which any set-property triggers, even for an unrelated property such as TasksMax. Send IOWeight for resources.blockIO.weight and for a plain io.bfq.weight value in resources.unified, as the pre-image of systemd's BFQ scaling (BFQ_WEIGHT() in src/basic/cgroup-util.h: identity up to 100, then 100 + (io_weight - 100) / 11, so the inverse is integer exact). systemd then writes exactly the spec weight to io.bfq.weight and the IOWeight value itself to io.weight, and the value survives further applies. The driver does not write either file for the structured weight, so systemd stays the single writer of the io controller weights. A weight of 0 stays a no-op, and weights outside [10, 1000] are rejected as in the cgroupfs driver instead of being dropped silently. A resources.unified io.weight is left as it is: a unified key applies verbatim to the file it names, and mapping it to IOWeight would also make systemd derive io.bfq.weight from the value. Signed-off-by: yjjnls <yjjnls@users.noreply.github.com>
Check that a weight under the systemd cgroup driver reaches the unit as the IOWeight property holding the pre-image of systemd's BFQ scaling, so systemd writes the spec weight itself to io.bfq.weight and the property value to io.weight. A structured weight above the default of 100 is sent as the BFQ pre-image, one up to it is sent as it is, and a plain io.bfq.weight value in resources.unified is a weight of the same scale, so it maps the same way. The weight also has to survive systemd applying the unit's cgroup settings again, which any set-property triggers, since that is what resets a weight that did not reach the unit as IOWeight. The systemd driver of runc 1.5.2 does not send IOWeight at all, so the tests are skipped when validating them on runc. Signed-off-by: yjjnls <yjjnls@users.noreply.github.com>
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>
baa4806 to
816415c
Compare
|
@nayuta723 Rebased onto main (816415c) and switched the systemd io group to the #3918 inventory registration: it now self-registers via |
Fixes #3897.
With
--systemd-cgroupthe io controller only reads the four throttle lists, soresources.blockIO.weightnever reaches the unit as anIOWeightproperty. A weight that iswritten to cgroupfs instead (a plain
io.bfq.weightinresources.unified, or a hand-writtenio.weight) does not survive: the next time systemd applies the unit's cgroup properties - anyset-property, including one for an unrelated property such asTasksMax- the weight is resetto the
IOWeightsystemd holds, or to the default when the unit has none. As noted in theissue, runc has the reset half of this too, because its systemd driver does not send
IOWeighteither.
This sends
IOWeightas the pre-image of systemd's BFQ scaling, so what systemd ends up writingto
io.bfq.weightis exactly the spec weight. The scaling inBFQ_WEIGHT()(
src/basic/cgroup-util.h) is identity up to 100 and100 + (io_weight - 100) * 900 / 9900above it, which is exactly
100 + (io_weight - 100) / 11; the inverse100 + (weight - 100) * 11is integer-exact for every weight in
[1, 1000], so nothing is rounded. ARMeeru confirmed theresulting values on systemd 262 for 10, 101, 500, 750 and 1000, including that they stay after an
unrelated
set-property; the round-trip is asserted over the whole range in a unit test here.Decisions worth pointing out:
resources.blockIO.weightis only sent asIOWeight; the driverdoes not also write
io.bfq.weightorio.weightitself for it. systemd writes both filesfrom
IOWeight(set_io_weight()), so they cannot disagree with each other and the valuesurvives further applies. On a BFQ host
io.bfq.weightat create time matches what runcwrites for it (and stays, where runc resets it);
io.weightdiffers, since this sets 4500for a weight of 500 where runc leaves it at 100. On a host without BFQ,
io.weightgets theIOWeightvalue (4500 for 500) instead of the cgroupfs driver's linear conversion(4950 for 500); both are valid values in
[1, 10000], the difference is the scale of thenon-BFQ proportional share.
io.bfq.weightfromIOWeightdifferently (243-247 write it as is, which the kernel rejectsabove 1000, and 248-249 write
(weight + 9) / 10), so the mapping is not meaningful below250; the contest group skips older systemd.
Io::applyalready receives the systemd version,so a version-dependent map could be added if it is ever wanted, but it would only fit those
broken older semantics.
resources.unified. A plainio.bfq.weightvalue maps through the same pre-image;anything else (
default 500, per-device lines, out of range, non-numeric) is left to thecgroupfs write as before.
io.weightis deliberately left alone: a unified key appliesverbatim to the file it names, and mapping it to
IOWeightwould additionally make systemdderive
io.bfq.weightfrom the value. It behaves as before, so a later systemd apply canstill reset it; mapping it would be a natural follow-up, but it changes what a verbatim key
means on BFQ hosts, so it is not part of this fix.
[10, 1000]are rejected with the same erroras the cgroupfs driver instead of being dropped silently. Per-device weights
(
weightDevice) remain unsupported on the systemd path, as before.Testing:
cargo test -p libcgroups --all-features --libpasses (272 tests), including the new cases.A full
cargo test --lib --bins --all --all-targets --all-featuresrun on this host onlyfails the two root-requiring
libcontainer --test as_siblingtests, which fail identically onthe base commit (
EPERMwithout root).through systemd's
BFQ_WEIGHT()for every weight in[1, 1000], the property and error casesfor
resources.blockIO.weight, and theio.bfq.weightunified key (plain value mapped, otherforms left to cgroupfs).
cgroup_systemd_iogroup(
tests/contest/contest/src/tests/cgroups/systemd/io.rs) cover the persistence half end toend: a weight from
resources.blockIO.weight(above and below the default of 100) and from aplain
io.bfq.weightunified key has to reach the unit asIOWeightwith the expectedpre-image, systemd has to write the expected
io.bfq.weight/io.weightvalues, and the weighthas to survive a
set-propertythat makes systemd reapply the unit. The group needs root, cgroupv2 with the io controller and systemd 250 or later, and skips on runc, whose systemd driver
does not send
IOWeight. ARMeeru ran it on Fedora (systemd 262): 4 ok on this PR, 4 failing onmain (
IOWeight=[not set]) and 4 skipped withRUNTIME_KIND=runc.cargo build -p contestandworkspace clippy pass locally.
driving the systemd manager directly:
blockIO.weight: 500setsIOWeight=4500as read backwith
systemctl show -p IOWeight, it stays 4500 after an unrelatedset-property TasksMax=500, and a unifiedio.bfq.weight: "750"setsIOWeight=7250. Thesame check on the base commit reports
IOWeightas not set forblockIO.weight: 500.kernel was built without BFQ, so the
io.weight/io.bfq.weightfile contents could not beread back here. That side is covered by the unit-test round-trip, by systemd's
set_io_weight()/BFQ_WEIGHT()(writesdefault <IOWeight>toio.weightandBFQ_WEIGHT(IOWeight)toio.bfq.weight), and by ARMeeru's measurements on systemd 262.