[systemd-devel] Systemd, cgroups and short-lived processes

Lennart Poettering lennart at poettering.net
Wed May 3 20:54:14 UTC 2017


On Wed, 03.05.17 18:02, Boris Dolgov (boris at dolgov.name) wrote:

> Hello!
> 
> I am using systemd and repeatedly need to do the following:
> - Start a process with memory limit and cpu affinity;
> - Be notified when it and all its children are finished (typically in
> 0.01-1 second);
> - Get cpu and memory usage statistics.
> 
> Cgroups look perfect for me, but what is the best way of managing them?
> 
> As far as I understand, ControlGroupInterface article advises to
> create a transient scope unit for each process I run, but I need to
> preserve cpu accounting information, so scope units will not work.

They will. Just make sure to use a recent systemd version that
provides you with the Ref/Unref() bus calls, which permits you to ref
specific units, so that you can read statistics off them.

> Alternatively, I could create service units, but I am concerned with
> performance issues and would like to create processes by myself.
> 
> Are any lower-level APIs available and advised to use?
> For example, I'd be happy to create a slice using systemd, create its
> subtrees manually and manage them myself, but the aforementioned
> article does not recommend it.

It should be sufficient to use scopes with Ref/Unref and the CPUShares
setting.

However, the cpuset controller is still not exposed in systemd, for
the reason that its semantics are really really broken, still. We'll
add support as soon as that is cleaned up in the kernel.

However, given that the per-process CPU affinitty stuff exposed by
libc is usually enough this should not be a big limitation.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list