2

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.

Shuangistan
  • 1,053
  • 8
  • 20

1 Answers1

0

If you are trying to change the cpu shares before systemd reaches its default.target you need to use StartupCPUShares=.

Umut
  • 2,317
  • 1
  • 17
  • 19
  • This option `StartupCPUShares=` is introduced later than `systemd 211`. And my question is more on generally changing the cgroup settings with systemd. I checked even after systemd reaches `default.target`, if I change the setting via dbus or shell, I still need to restart the unit to active the setting in `/sys/fs/cgroup`. And as I described in the question, the change should be triggered, which means not at the time point of the `default.target`. Thanks very much for your help. – Shuangistan Mar 03 '16 at 13:04
  • 1
    It could very well be a bug in systemd in this area. You seem like you have tried everything. You don't have privilege problem, you even get the properties changed signal. However you will not get help from upstream for a relatively old systemd version. Your best bet is probably upgrading to latest systemd. – Umut Mar 04 '16 at 07:19
  • You're right, at least it works on my Ubuntu machine with `systemd 225`. Thanks for your comment. – Shuangistan Mar 16 '16 at 23:18