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

Tomasz Torcz tomek at pipebreaker.pl
Wed May 6 20:05:24 UTC 2020


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
├─user.slice
│ ├─user-1001.slice
│ ├─user-0.slice
│ └─user-1000.slice
│   ├─user at 1000.service
│   │ └─init.scope
│   │   ├─2914978 /usr/lib/systemd/systemd --user
│   │   └─2914990 (sd-pam)
│   ├─session-356.scope
│   │ └─2915060 /usr/libexec/openssh/sftp-server
│   └─session-354.scope
│     └─2915015 /usr/libexec/openssh/sftp-server
├─init.scope
│ └─1 /usr/lib/systemd/systemd --system --deserialize 214
├─system.slice
│ ├─rngd.service
│ ├─abrt-oops.service
[…]
│ └─smokeping.service
│   ├─5423 /usr/bin/perl /usr/sbin/smokeping --nodaemon
│   ├─7804 /usr/sbin/smokeping [FPing]
│   └─7805 /usr/sbin/smokeping [FPing6]
└─machine.slice
  ├─machine-qemu\x2d67\x2dkaitain.scope
  │ ├─2905751 /usr/bin/qemu-system-x86_64 -machine accel=kvm -name guest=kaitai…
  │ ├─vcpu0
  │ └─emulator
  ├─machine-qemu\x2d9\x2dnaib.scope
[…]

 (heavily trimmed, but shows the idea)

> There is supposed to be only one manager of the top-level cgroup
> tree. On systemd systems. If you muck with the cgroup tree anyway you
> are interfering with systemd#s management and things will fall apart
> sooner or later.
> if you want to muck around in the cgroup tree, acquire a delegated
> cgroup subtree, where you can do whatever you want.

 Is there an API in systemd to move specific program to a dedicated slice?
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.

  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.

-- 
Tomasz Torcz                                                       72->|   80->|
tomek at pipebreaker.pl                                               72->|   80->|



More information about the systemd-devel mailing list