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

2020-05-07 Thread Lennart Poettering
On Do, 07.05.20 09:21, Tomasz Torcz (to...@pipebreaker.pl) wrote:

> On Thu, May 07, 2020 at 08:56:24AM +0200, Lennart Poettering wrote:
> > > > >  Is there an API in systemd to move specific program to a dedicated
> > > > >  slice?
> > > >
> > > > Use Slice= in the service file.
> > >
> > >   That would require having a service file.  I don't have it. I just have 
> > > a
> > > single process in session which I need to treat specially.  Thus I move
> > > it to separate slice.  I have /etc/systemd/system/kodi.slice to define
> > > this separate slice and resource controls for it.
> >
> > use "systemd-run --scope --slice=kodi.slice …" for that.
>
>   That's not moving, that's starting a new instance.

Yeah. Moving is not supported. As mentioned.

>
> > Really, if you muck around with the cgroup tree yourself you void all
> > warranty. I mean, it's Linux you can do whatever you want, but it's
> > certainly outside of how this is intended to be used, i.e. the
> > cgroupsv2 "single writer" concept.
> >
> > Please read up on this here:
> >
> > https://systemd.io/CGROUP_DELEGATION
> > It's documented in all length...
>
>   From quick glance, it talks about a bit different concepts.
> I'm not delegating, I'm using systemd to manage tree for me.
> There are no multiple writers - only systemd (no kubernetes and
> such).

Well, if you manually muck with the cgroup tree, then *you* are the
second writer.

Lennart

--
Lennart Poettering, Berlin
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-07 Thread Tomasz Torcz
On Thu, May 07, 2020 at 08:56:24AM +0200, Lennart Poettering wrote:
> > > >  Is there an API in systemd to move specific program to a dedicated
> > > >  slice?
> > >
> > > Use Slice= in the service file.
> >
> >   That would require having a service file.  I don't have it. I just have a
> > single process in session which I need to treat specially.  Thus I move
> > it to separate slice.  I have /etc/systemd/system/kodi.slice to define
> > this separate slice and resource controls for it.
> 
> use "systemd-run --scope --slice=kodi.slice …" for that.

  That's not moving, that's starting a new instance.

> Really, if you muck around with the cgroup tree yourself you void all
> warranty. I mean, it's Linux you can do whatever you want, but it's
> certainly outside of how this is intended to be used, i.e. the
> cgroupsv2 "single writer" concept.
> 
> Please read up on this here:
> 
> https://systemd.io/CGROUP_DELEGATION
> It's documented in all length...

  From quick glance, it talks about a bit different concepts.
I'm not delegating, I'm using systemd to manage tree for me.
There are no multiple writers - only systemd (no kubernetes and such).

  But let me read this webpage carefully first.

-- 
Tomasz Torcz   72->|   80->|
to...@pipebreaker.pl   72->|   80->|

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-07 Thread Lennart Poettering
On Do, 07.05.20 08:28, Tomasz Torcz (to...@pipebreaker.pl) wrote:

> On Wed, May 06, 2020 at 11:53:14PM +0200, Lennart Poettering wrote:
> > > > >
> > > > >   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
> >
> >
> > >  Is there an API in systemd to move specific program to a dedicated
> > >  slice?
> >
> > Use Slice= in the service file.
>
>   That would require having a service file.  I don't have it. I just have a
> single process in session which I need to treat specially.  Thus I move
> it to separate slice.  I have /etc/systemd/system/kodi.slice to define
> this separate slice and resource controls for it.

use "systemd-run --scope --slice=kodi.slice …" for that.

Really, if you muck around with the cgroup tree yourself you void all
warranty. I mean, it's Linux you can do whatever you want, but it's
certainly outside of how this is intended to be used, i.e. the
cgroupsv2 "single writer" concept.

> > 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.
>
>   This user has a bunch of other things running (compilation, emails,
> batch jobs, torrents). I want Kodi to be isolated from the interference.
> Slices/scopes (are they different? Manpage descriptions of them seem to say 
> the
> same things using slightly different words) should do the trick.

Slices are a way for hierarchially grouping services + scopes. They do
not directly contain processes, but only indirectly because services +
scopes contain them.

Services encapsulates processes systemd starts for you.

Scopes encapsulates processes you fork off yourself but want to manage
in a separate own unit. When instantiating a scope you specify a bunch
of processes which will be migrated to the new scope.

Process generally are placed in services and scopes early on when they
are forked off. Migrating already long running processes into a
different scope or service is not something one wants to do because
accounting is fucked then.

Slices are the inner nodes of the cgroup tree basically, and scopes +
services the leaves.

Please read up on this here:

https://systemd.io/CGROUP_DELEGATION

It's documented in all length...

Lennart

--
Lennart Poettering, Berlin
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-07 Thread Tomasz Torcz
On Wed, May 06, 2020 at 11:53:14PM +0200, Lennart Poettering wrote:
> > > >
> > > >   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
> 
> 
> >  Is there an API in systemd to move specific program to a dedicated
> >  slice?
> 
> Use Slice= in the service file.
 
  That would require having a service file.  I don't have it. I just have a
single process in session which I need to treat specially.  Thus I move
it to separate slice.  I have /etc/systemd/system/kodi.slice to define
this separate slice and resource controls for it.


> >   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.

  That wouldn't work, Kodi is strictly tied to user session - file
permissions, configurations, access to screen and audio (Kodi is a media
player), interaction with other parts of user session.

> 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.

  This user has a bunch of other things running (compilation, emails,
batch jobs, torrents). I want Kodi to be isolated from the interference.
Slices/scopes (are they different? Manpage descriptions of them seem to say the
same things using slightly different words) should do the trick.

 P.S. I'm sorry for hijacking original poster's thread.

-- 
Tomasz Torcz   72->|   80->|
to...@pipebreaker.pl   72->|   80->|

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-06 Thread Lennart Poettering
On Mi, 06.05.20 22:05, Tomasz Torcz (to...@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 (to...@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
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-06 Thread Tomasz Torcz
On Wed, May 06, 2020 at 05:18:34PM +0200, Lennart Poettering wrote:
> On Mo, 04.05.20 08:31, Tomasz Torcz (to...@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@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->|
to...@pipebreaker.pl   72->|   80->|

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-06 Thread Lennart Poettering
On Mo, 04.05.20 08:31, Tomasz Torcz (to...@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.

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.

Lennart

--
Lennart Poettering, Berlin
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-06 Thread Lennart Poettering
On Mo, 04.05.20 11:52, nitish nagesh (nagesh.nit...@gmail.com) 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.

The Linux kernel gets a bit confused with accounting if you migrate
running processes between cgroups. One usually shouldn't do that
except when forking off/execing new stuff.

>The daemon while booting up belongs to a systemd slice (say X) which has
> parameters like startupCPUShares tuned to bring the system up faster.
> However for normal operations after bootup, it would be apt to make it
> belong to another slice (say Y) with different cgroup parameters
> configurations (ex: CPUShares). The set of daemons that belong to X and Y
> are totally different, except for this one daemon. Also the cgroup
> parameter that are set via slice Y are totally different than those set via
> slice X.

This is not supported. In systemd you can migrate services between
slices only by stopping them and starting them again.

>   A few basic questions:
> - Can a daemon be a part of 2 slices?

no.

> - If yes, going by the example above, if slice X loads first followed by
> slice Y, does it mean when slice X is in force this daemon will have
> startUpCPUShares set & when slice Y is loaded the CPUShares will be
> set?

I don't grok this, sorry.

>Please suggest if there are alternate ways in systemd to handle this
> requirement.

We don't support that. Slice assignments are sticky during service
runtime.

Lennart

--
Lennart Poettering, Berlin
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-04 Thread Tomasz Torcz
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

Process can only be in one cgroup at the time, so it will be moved.

-- 
Tomasz TorczOnce you've read the dictionary,
to...@pipebreaker.plevery other book is just a remix.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2020-05-04 Thread nitish nagesh
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.

   The daemon while booting up belongs to a systemd slice (say X) which has
parameters like startupCPUShares tuned to bring the system up faster.
However for normal operations after bootup, it would be apt to make it
belong to another slice (say Y) with different cgroup parameters
configurations (ex: CPUShares). The set of daemons that belong to X and Y
are totally different, except for this one daemon. Also the cgroup
parameter that are set via slice Y are totally different than those set via
slice X.

  A few basic questions:
- Can a daemon be a part of 2 slices?
- If yes, going by the example above, if slice X loads first followed by
slice Y, does it mean when slice X is in force this daemon will have
startUpCPUShares set & when slice Y is loaded the CPUShares will be set?

   Please suggest if there are alternate ways in systemd to handle this
requirement.

Thanks,
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel