[systemd-devel] Setting Environment Configuration (Affinity) for Slices

Lennart Poettering lennart at poettering.net
Mon Oct 19 09:54:33 PDT 2015


On Mon, 19.10.15 11:58, Chris Bell (cwbell at narmos.org) wrote:

> Hi all,
> 
> Is there a way to set an affinity for an entire slice? 

No there is not. But it's definitely our intention to add this, and
expose the "cpuset" cgroup controller this way. Unfortunately the
"cpuset" controller of the kernel currently exposes really awful
behaviour, hence we have not exposed its functionality this way.

However, I just had a long chat with Tejun Heo about this, and we came
to the conclusion that's probably safe to expose a minimal subset of
cpuset now, and reuse the existing CPUAffinity= service setting for
that: right now, it only affects the main process of a service at fork
time (and all child processes forked off from that, recursively), by
using sched_setaffinity(). Our idea would be to propagate it into the
"cpuset.cpus" field too, so that the setting is first passed to
sched_setaffinity(), and then also written to the cpuset
hierarchy. This should be pretty safe, and allow us to make this
available in slices too. It would result in a slight change of
behaviour though, as making adjustments to cpuset would mean that
daemons cannot extend their affinity with sched_setaffinity() above
what was set with cpuset anymore. But I think this is OK.

> Say, for example, I have system-webhosted.slice, but I only want the
> services running within system-webhosted.slice to run on cores
> 5-8. I can set this individually per service (systemd.exec man
> page), but it does not indicate that I can do this for slices. Also,
> the systemd.slice man page says it only accepts resource control
> directives, not environment config directives. Is there any way I
> can set an environment config directive for an entire slice? Or do I
> need to do it per-service?

The latter. Slices are really about resource control, and an env var
really isn't a resource control knob.

> Alternatively, is there a way (and this sounds way too hacky) to
> hierarchically order a slice under a service? So, basically I can start some
> dummy service with environment configs, and the slice will be a child of
> that service and all units in that slice will inherit the environment
> configs from the parent of the slice?

Nope. Slices are the inner nodes of the resource control tree, and
services/scopes are the leaves. That's how they are defined.

> I've noticed that systemd-nspawn@<machine>.servce has a child 'system.slice'
> though I don't know if that setup can enforce what I'd like it to.

Well, thats because nspawn is a delegation unit that encapsulates a
completely new cgroup hierarchy of its own, managed by a new systemd
instance.

> Is there any way to do this with the current setup?

I am not sure I understand what you want to to do with the env vars
precisely? what kind of env vars do you intend to set? 

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list