]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/core/execute.c
core: add systemd-executor binary
authorLuca Boccassi <bluca@debian.org>
Thu, 1 Jun 2023 18:51:42 +0000 (19:51 +0100)
committerLuca Boccassi <bluca@debian.org>
Thu, 12 Oct 2023 14:01:51 +0000 (15:01 +0100)
commitbb5232b6a3b8af075ee06cc87416e5f49a6170d3
tree967d66d16e88216b234a6d62ec5dfb719f756c61
parent56df7a461f05b39851e9f95581cd6f6c66dc3b22
core: add systemd-executor binary

Currently we spawn services by forking a child process, doing a bunch
of work, and then exec'ing the service executable.

There are some advantages to this approach:

- quick: we immediately have access to all the enourmous amount of
  state simply by virtue of sharing the memory with the parent
- easy to refactor and add features
- part of the same binary, will never be out of sync

There are however significant drawbacks:

- doing work after fork and before exec is against glibc's supported
  case for several APIs we call
- copy-on-write trap: anytime any memory is touched in either parent
  or child, a copy of that page will be triggered
- memory footprint of the child process will be memory footprint of
  PID1, but using the cgroup memory limits of the unit

The last issue is especially problematic on resource constrained
systems where hard memory caps are enforced and swap is not allowed.
As soon as PID1 is under load, with no page out due to no swap, and a
service with a low MemoryMax= tries to start, hilarity ensues.

Add a new systemd-executor binary, that is able to receive all the
required state via memfd, deserialize it, prepare the appropriate
data structures and call exec_child.

Use posix_spawn which uses CLONE_VM + CLONE_VFORK, to ensure there is
no copy-on-write (same address space will be used, and parent process
will be frozen, until exec).
The sd-executor binary is pinned by FD on startup, so that we can
guarantee there will be no incompatibilities during upgrades.
15 files changed:
docs/ARCHITECTURE.md
meson.build
src/basic/cgroup-util.h
src/core/dynamic-user.c
src/core/dynamic-user.h
src/core/execute.c
src/core/execute.h
src/core/executor.c [new file with mode: 0644]
src/core/fuzz-manager-serialize.c
src/core/fuzz-unit-file.c
src/core/manager.c
src/core/manager.h
src/core/meson.build
src/core/unit.c
test/units/testsuite-55.sh