Systemd vs Nice Level – Understanding CPUShares Property

cgroupsnicesystemd

As I understand it (please correct me if I'm wrong),

systemctl set-property ... CPUShares=some_value

limits the cpu time for an entire cgroup unit. If we instead want to limit cpu time for a process within that unit, we can run the process with

systemd-run ... nice=some_value

I'm wondering if there's some intrinsic difference between the concepts of the nice-value of a process and the CPUShares-value of a group of processes? Can we limit CPUShares of a process, or set the nice-value of a cgroup unit? When would we want to do one or the other?

Best Answer

From reading man systemd-run, it will create a service and thus a cgroup on the fly. From reading systemd.exec, the Nice= directive will apply to all executed processes, so the way that systmd handles the concepts of Nice= and CPUShares= are very similar.

My understanding of the relationship is that it has to do with history. nice has existed for a listed a couple of decades and always applied to specific processes.

On the other hand, the concept of cgroups and the idea of applying CPUShares= to a process group is much a newer concept but accomplishes the same goal.

I expect systemd supports Nice= for historical compatibility.

I would use whichever one you are comfortable with, but not both to avoid confusion. If you have no preference, I would use the newer CPUShares= concept.

Related Question