Skip to content

Implement Unit.SetProperties, add CPUWeight and other cgroup signatures - #137

Merged
aleivag merged 1 commit into
systemd:mainfrom
aleivag:unit-set-properties
Nov 19, 2026
Merged

aleivag merged 1 commit into
systemd:mainfrom
aleivag:unit-set-properties

Conversation

@aleivag

@aleivag aleivag commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Unit.SetProperties(runtime, properties) went through the generic method call, which refuses a(sv) arguments with NotImplementedError, so there was no way to do the equivalent of systemctl set-property on a Unit object (#122). Override it like Manager.SetUnitProperties: each property is sent with the type from KNOWN_UNIT_SIGNATURES. signature_array (and so both methods) now also takes a list of (name, value) pairs, the D-Bus a(sv) shape, besides a dict.

CPUWeight itself, the example in #122, was missing from KNOWN_UNIT_SIGNATURES, as were the other settable cgroup properties. Add them with the types systemd 259 exposes: CPUWeight, StartupCPUWeight, CPUQuotaPeriodUSec "t"; AllowedCPUs, StartupAllowedCPUs, AllowedMemoryNodes, StartupAllowedMemoryNodes "ay"; IOWeight, StartupIOWeight "t"; IODeviceWeight, IORead/WriteBandwidthMax, IORead/WriteIOPSMax, IODeviceLatencyTargetUSec "a(st)"; MemoryMin, MemoryZSwapMax "t"; MemoryZSwapWriteback "b"; MemoryPressureWatch "s", MemoryPressureThresholdUSec "t".

Tested on Fedora 44 (systemd 259): the #122 example, Unit("system.slice").Unit.SetProperties(True, [(b"CPUWeight", 200)]), sets system.slice/cpu.weight to 200. Each new property is accepted at unit creation (pystemd.run(extra=...)) and reads back the value set; all but MemoryPressureWatch and MemoryPressureThresholdUSec can also be changed at runtime with SetProperties (systemd only takes those two at creation). New e2e test for SetProperties; tests/ and e2e/ pass.

Unit.SetProperties(runtime, properties) went through the generic method
call, which refuses a(sv) arguments with NotImplementedError, so there was
no way to do the equivalent of `systemctl set-property` on a Unit object
(systemd#122). Override it like Manager.SetUnitProperties: each property is sent
with the type from KNOWN_UNIT_SIGNATURES. signature_array (and so both
methods) now also takes a list of (name, value) pairs, the D-Bus a(sv)
shape, besides a dict.

CPUWeight itself, the example in systemd#122, was missing from
KNOWN_UNIT_SIGNATURES, as were the other settable cgroup properties. Add
them with the types systemd 259 exposes: CPUWeight, StartupCPUWeight,
CPUQuotaPeriodUSec "t"; AllowedCPUs, StartupAllowedCPUs,
AllowedMemoryNodes, StartupAllowedMemoryNodes "ay"; IOWeight,
StartupIOWeight "t"; IODeviceWeight, IORead/WriteBandwidthMax,
IORead/WriteIOPSMax, IODeviceLatencyTargetUSec "a(st)"; MemoryMin,
MemoryZSwapMax "t"; MemoryZSwapWriteback "b"; MemoryPressureWatch "s",
MemoryPressureThresholdUSec "t".

Tested on Fedora 44 (systemd 259): the systemd#122 example,
Unit("system.slice").Unit.SetProperties(True, [(b"CPUWeight", 200)]),
sets system.slice/cpu.weight to 200. Each new property is accepted at
unit creation (pystemd.run(extra=...)) and reads back the value set; all
but MemoryPressureWatch and MemoryPressureThresholdUSec can also be
changed at runtime with SetProperties (systemd only takes those two at
creation). New e2e test for SetProperties; tests/ and e2e/ pass.
@aleivag
aleivag merged commit dd1cf4e into systemd:main Nov 19, 2026
49 checks passed
@aleivag
aleivag deleted the unit-set-properties branch November 19, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant