[systemd-devel] Moving a service from one systemd slice to another..

Lennart Poettering lennart at poettering.net
Wed May 6 21:53:14 UTC 2020


On Mi, 06.05.20 22:05, Tomasz Torcz (tomek at pipebreaker.pl) wrote:

> On Wed, May 06, 2020 at 05:18:34PM +0200, Lennart Poettering wrote:
> > On Mo, 04.05.20 08:31, Tomasz Torcz (tomek at pipebreaker.pl) wrote:
> >
> > > On Mon, May 04, 2020 at 11:52:37AM +0530, nitish nagesh wrote:
> > > > Hello,
> > > >
> > > >    We have this odd want to move a daemon between different systemd slices.
> > > > Not sure if that's even a valid thing to do, but here is the requirement.
> > >
> > >   You can use low-level cgroup access to move it. Something like:
> > > systemctl show --property MainPID --value your.service >
> > > /sys/fs/cgroup/NEW.slice/cgroup.procs
> >
> > You void your warranty if you do that. Moreover, on cgroupvs2 this
> > doesn't work really, since inner cgroups cannot have processes and
> > slices are by definition inner cgroups.
>
>   Doesn't work? I beg to differ, the following is on Fedora 31:
>
> Control group /:
> -.slice
> ├─kodi.slice
> │ └─2872766 /usr/lib64/kodi/kodi-wayland      ← here it has process

Sure, if you have an empty slice (i.e. with no unit associated) then
you can attach processes instead, because it is a leaf node too.

The cgroupsv2 rule is: only leaf cgroups may contain processes. You
cannot have populated child cgroups and processes on the same level.

>  Is there an API in systemd to move specific program to a dedicated
>  slice?

Use Slice= in the service file.

> I know recent gnome-shell starts every application in dedicate scope,
> but it's under *user* instance. Which means:
> – no ability to increase priority of program in such scope
> - still fights over resources with other user scopes, and other users in
>   general.

Yeah, it's a model of strict resource delegation: of the resources PID
1 has it passes a subset to a specific user. The user then can
distribute it further among its services and so on. But under no
circumstances could a user's service gain more resources than what the
user as a whole gets assigned.

>   In my usecase, I've created a top-level .slice for Kodi player. I want
> it to have priority over everything on my machine - over other users'
> processes, over virtual machines, over everything in system.slice.
> I achieve it by having this top-level slice with CPUShares, CPUWeight,
> BlockIOWeight, IOWeight much higher and IODeviceLatencyTargetSec
> much lower than rest of the slices.  Seems to work.

I presume you you mean a top-level slice in the system manager? If so
you need to run kodi as a system service too.

If you want to run kodi as user service, then assign your user the
resources you want to assign to kodi, and then distribute them from
there to kodi, and reduce it for the rest.

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list