I have a systemd foo.slice
with cgroup setting CPUShares
.
My idea is to change the setting at certain point during the system startup, which will be triggered by a systemd service.
I do some test work to check how to change the setting at runtime.
In the foo.slice
I defined CPUShares=256
. Which will cause cat /sys/fs/cgroup/cpu/foo.slice/cpu.shares 256
.
And will get the following lines by gdbus introspect
:
interface org.freedesktop.systemd1.Slice {
methods:
signals:
properties:
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s Slice = '-.slice';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ControlGroup = '/foo.slice';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly b CPUAccounting = false;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly t CPUShares = 256;
I try to change the CPUShares
by invoking the method:
@org.freedesktop.systemd1.Privileged("true")
SetProperties(in b arg_0,
in a(sv) arg_1);
using:
gdbus call --system --dest org.freedesktop.systemd1 --object-path /org/freedesktop/systemd/unit/foo_2eslice --method org.freedesktop.systemd1.Unit.SetProperties true "[('CPUShares', <@t 2048>)]"
And I will get
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly t CPUShares = 2048;
But I still get cat /sys/fs/cgroup/cpu/foo.slice/cpu.shares 256
.
After I restart the slice:
gdbus call --system --dest org.freedesktop.systemd1 --object-path /org/freedesktop/systemd1/unit/foo_2eslice --method org.freedesktop.systemd1.Unit.Restart 'replace'
I will get
cat /sys/fs/cgroup/cpu/foo.slice/cpu.shares 2048
I use systemd 211
.
I wish to know more detail about this behavior or if there are better solutions, i.e. wish to get some hint to change the CPUShares
at runtime with systemd.
If you are trying to change the cpu shares before systemd reaches its default.target you need to use StartupCPUShares=
.