]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/core/service.c
core: rework how we track service and scope PIDs
authorLennart Poettering <lennart@poettering.net>
Thu, 31 May 2018 13:41:59 +0000 (15:41 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Jun 2018 20:06:48 +0000 (22:06 +0200)
commit50be4f4a4655ac76b893dbe9da82a1710ac7ed0d
treeb9afda92b532bcf1d9da666e476b0309385be5f1
parent19a691a9fd0825cfb506ae0ce733c42cbd9ae3c9
core: rework how we track service and scope PIDs

This reworks how systemd tracks processes on cgroupv1 systems where
cgroup notification is not reliable. Previously, whenever we had reason
to believe that new processes showed up or got removed we'd scan the
cgroup of the scope or service unit for new processes, and would tidy up
the list of PIDs previously watched. This scanning is relatively slow,
and does not scale well. With this change behaviour is changed: instead
of scanning for new/removed processes right away we do this work in a
per-unit deferred event loop job. This event source is scheduled at a
very low priority, so that it is executed when we have time but does not
starve other event sources. This has two benefits: this expensive work is
coalesced, if events happen in quick succession, and we won't delay
SIGCHLD handling for too long.

This patch basically replaces all direct invocation of
unit_watch_all_pids() in scope.c and service.c with invocations of the
new unit_enqueue_rewatch_pids() call which just enqueues a request of
watching/tidying up the PID sets (with one exception: in
scope_enter_signal() and service_enter_signal() we'll still do
unit_watch_all_pids() synchronously first, since we really want to know
all processes we are about to kill so that we can track them properly.

Moreover, all direct invocations of unit_tidy_watch_pids() and
unit_synthesize_cgroup_empty_event() are removed too, when the
unit_enqueue_rewatch_pids() call is invoked, as the queued job will run
those operations too.

All of this is done on cgroupsv1 systems only, and is disabled on
cgroupsv2 systems as cgroup-empty notifications are reliable there, and
we do not need SIGCHLD events to track processes there.

Fixes: #9138
src/core/scope.c
src/core/service.c
src/core/unit.c
src/core/unit.h