Skip to content

core/manager: add dbus API to create auxiliary scope from running service - #28836

Merged
yuwata merged 2 commits into
systemd:mainfrom
msekletar:aux-scope
Jan 3, 2024
Merged

yuwata merged 2 commits into
systemd:mainfrom
msekletar:aux-scope

Conversation

@msekletar

@msekletar msekletar commented Aug 14, 2023 •

Copy link
Copy Markdown
Contributor

No description provided.

@msekletar

Copy link
Copy Markdown
Contributor Author

@poettering this is similar to what we discussed previously (sd-notify asynchronous API for creating "restart" scopes) but a bit more generic and exposed as a DBus API instead.

Comment thread src/core/service.c Resolved
Comment thread src/test/test-aux-scope.c Resolved
@bluca bluca added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Aug 15, 2023
@keszybz

keszybz commented Aug 16, 2023 •

Copy link
Copy Markdown
Member
diff --git man/org.freedesktop.systemd1.xml man/org.freedesktop.systemd1.xml
index 19e83f8f14..f01c529b5e 100644
--- man/org.freedesktop.systemd1.xml
+++ man/org.freedesktop.systemd1.xml
@@ -277,8 +277,8 @@ node /org/freedesktop/systemd1 {
       GetDynamicUsers(out a(us) users);
       DumpUnitFileDescriptorStore(in  s name,
                                   out a(suuutuusu) entries);
-      StartAuxiliaryScope(in s name,
-                          in ah pidfds,
+      StartAuxiliaryScope(in  s name,
+                          in  ah pidfds,
                           out o job);
     signals:
       UnitNew(s id,

It seems to be a whitespace issue.

@msekletar

Copy link
Copy Markdown
Contributor Author

It seems to be a whitespace issue.

Good catch. Thank you @keszybz!

@keszybz keszybz added please-review PR is ready for (re-)review by a maintainer and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels Aug 16, 2023
@msekletar
msekletar force-pushed the aux-scope branch 2 times, most recently from ab20005 to 8749111 Compare August 16, 2023 17:42
@bluca bluca added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed please-review PR is ready for (re-)review by a maintainer labels Aug 16, 2023
@msekletar

Copy link
Copy Markdown
Contributor Author

@bluca I think that build warning/error generated in Ubuntu CI is false positive? Can you double check and maybe drop the ci-fails label if appropriate.

@msekletar

Copy link
Copy Markdown
Contributor Author

As mentioned in the previous comment, I think that build warning causing build failure on Ubuntu CI is a false positive. Dropping the Draft status in order to (hopefully) solicit more feedback.

@msekletar
msekletar marked this pull request as ready for review August 23, 2023 11:57
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels Aug 23, 2023
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/test/test-aux-scope.c Resolved
Comment thread test/units/testsuite-83.sh Resolved
Comment thread src/core/service.c Resolved
Comment thread man/org.freedesktop.systemd1.xml Resolved
@poettering

Copy link
Copy Markdown
Member

I am sorry, the copying of cgroup settings is weird.

@bluca

bluca commented Nov 1, 2023

Copy link
Copy Markdown
Member

I am sorry, the copying of cgroup settings is weird.

---> #28836 (comment)

Comment thread src/core/cgroup.c Resolved
Comment thread src/core/cgroup.c Resolved
Comment thread src/core/cgroup.c Resolved
Comment thread src/core/cgroup.c Resolved
Comment thread src/core/cgroup.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/test/test-aux-scope.c Resolved
Comment thread src/test/test-aux-scope.c Resolved
@poettering

Copy link
Copy Markdown
Member

so i don't like the copying of the cgroup props, I'd not do it. But if everyone thinks this is great, i am oK with it, but please drop at the very least the delegation stuff. That's security relevant, and we shouldn't open up doors needlessly, in particular as it's highly unlikely the scope will need it.

@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed good-to-merge/with-minor-suggestions labels Nov 1, 2023
@bluca

bluca commented Nov 1, 2023

Copy link
Copy Markdown
Member

so i don't like the copying of the cgroup props, I'd not do it. But if everyone thinks this is great, i am oK with it, but please drop at the very least the delegation stuff. That's security relevant, and we shouldn't open up doors needlessly, in particular as it's highly unlikely the scope will need it.

Yes - the cgroup setup should just be about resource management/access, delegation and other bits should definitely not be duplicated

@bluca

bluca commented Nov 2, 2023

Copy link
Copy Markdown
Member

@msekletar ping - if this is to be merged for 255, then could it be prioritized to fix the review comments? It's a new interface so we need it before rc1

@bluca bluca removed the rc-blocker 🚧 PRs and Issues tagged this way are blocking the upcoming rc release! label Nov 4, 2023
@bluca bluca added this to the v256 milestone Nov 4, 2023
@bluca

bluca commented Nov 4, 2023

Copy link
Copy Markdown
Member

Punted to next milestone as discussed

@Werkov Werkov mentioned this pull request Nov 15, 2023
@github-actions

github-actions Bot commented Nov 15, 2023 •

Copy link
Copy Markdown

We had successfully released a new major release. We are no longer in a development freeze phase.
We will try our best to get back to your PR as soon as possible. Thank you for your patience.

@msekletar

Copy link
Copy Markdown
Contributor Author

@poettering Updated. PTAL. I plan to use newly added *_dup() functions in more places as you suggested and submit it in separate PR.

@Werkov

Werkov commented Nov 22, 2023

Copy link
Copy Markdown
Contributor

I think the pidfds scope specification should be generalized and brought into StartTransientUnit (accept PIDs nand pidfds entries in the properties argument).

I find that cgroup_context_copy is a band-aid that can lead into problems:

  • maintenance burden -- lots of code that must be kept in sync (illustrated with the number of *_dup functions),
  • unclear resource semantics -- cloning multiplies possible limits, I'm not sure what cloning of BPF programs means,
  • it is racy wrt hosting service CGroupContext updates -- changing attributes of the service while the service may decide to clone a scope asynchronously (for illustration: config cloning was used in kernel cgroup v1 and it caused lots of confusion, look for memory.swappiness).

The API is inviting for "fork-classify-exec" workflow violation when long-running processes are migrated across horizontal cgroups. (This is a shared critique with StartTransientUnit but here it is even suggested by the commit message.) When I'm thinking about it now, it may be cleaner to specify no pid(fd)s and migrate only the calling process. (So that any possible children are started after migration.))

Perhaps, in order to avoid the internal cloning of configuration, could there be some shared drop-ins between services and scopes that the scope would load upon start?

@msekletar

Copy link
Copy Markdown
Contributor Author

I think the pidfds scope specification should be generalized and brought into StartTransientUnit (accept PIDs nand pidfds entries in the properties argument).

This is exactly what I didn't want to do. StartTransientUnit() is generic and to use it correctly is somewhat involved. What I want to do is give people easy way how to partition their workload with systemd for overall better management and reliability. Provide simple API that does work in 95% of cases while StartTransientUnit() is available for other 5%.

Also adding this D-Bus API is fairly cheap because it is not introducing any new operational model or concept, it just creates scope unit that everyone is familiar with already. On the other hand, I don't want to rush merging this if there is opposition or discontent, however, staying with KillMode=none status quo is also not a viable solution.

@poettering @bluca any opinions?

@bluca

bluca commented Nov 23, 2023

Copy link
Copy Markdown
Member

This PR looks good to me, StartTransient could also be updated independently if there's a use case for it

@msekletar

Copy link
Copy Markdown
Contributor Author

@bluca seems to be OK with merging this...what about @poettering ?

@bluca

bluca commented Dec 22, 2023

Copy link
Copy Markdown
Member

This has been waiting for a long time, so unless there are more comments, I'll merge tomorrow - @poettering speak now or forever hold your peace

Comment thread man/org.freedesktop.systemd1.xml Resolved
Comment thread src/core/cgroup.c Resolved
Comment thread src/core/dbus-manager.c Resolved
Comment thread src/core/cgroup.h
Comment on lines +314 to +325
int cgroup_context_add_io_device_limit_dup(CGroupContext *c, CGroupIODeviceLimit *l);
int cgroup_context_add_io_device_weight_dup(CGroupContext *c, CGroupIODeviceWeight *w);
int cgroup_context_add_io_device_latency_dup(CGroupContext *c, CGroupIODeviceLatency *l);
int cgroup_context_add_block_io_device_weight_dup(CGroupContext *c, CGroupBlockIODeviceWeight *w);
int cgroup_context_add_block_io_device_bandwidth_dup(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
int cgroup_context_add_device_allow_dup(CGroupContext *c, CGroupDeviceAllow *a);
int cgroup_context_add_socket_bind_item_allow_dup(CGroupContext *c, CGroupSocketBindItem *i);
int cgroup_context_add_socket_bind_item_deny_dup(CGroupContext *c, CGroupSocketBindItem *i);

static inline int cgroup_context_add_bpf_foreign_program_dup(CGroupContext *c, CGroupBPFForeignProgram *p) {
return cgroup_context_add_bpf_foreign_program(c, p->attach_type, p->bpffs_path);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they can be static.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will use those functions from other modules in followup PR.

…vice

This commit introduces new D-Bus API, StartAuxiliaryScope(). It may be
used by services as part of the restart procedure. Service sends an
array of PID file descriptors corresponding to processes that are part
of the service and must continue running also after service restarts,
i.e. they haven't finished the job why they were spawned in the first
place (e.g. long running video transcoding job). Systemd creates new
scope unit for these processes and migrates them into it. Cgroup
properties of scope are copied from the service so it retains same
cgroup settings and limits as service had.
@msekletar

Copy link
Copy Markdown
Contributor Author

@yuwata updated, PTAL.

@poettering

Copy link
Copy Markdown
Member

I think the pidfds scope specification should be generalized and brought into StartTransientUnit (accept PIDs nand pidfds entries in the properties argument).

we already have that in place since a while. It's used by default in systemd-run, and logind and such.

I find that cgroup_context_copy is a band-aid that can lead into problems:

* maintenance burden -- lots of code that must be kept in sync (illustrated with the number of `*_dup` functions),

* unclear resource semantics -- cloning multiplies possible limits, I'm not sure what cloning of BPF programs means,

So I would acually agree with you on these too, but as mentioned above I was OK nonetheless if the others think this is important.

* it is racy wrt hosting service `CGroupContext` updates -- changing attributes of the service while the service may decide to clone a scope asynchronously (for illustration: config cloning was used in kernel cgroup v1 and it caused lots of confusion, look for `memory.swappiness`).

I think the assumption is that the scope is short-lived effectively, so I figure this is OK.

The API is inviting for "fork-classify-exec" workflow violation when long-running processes are migrated across horizontal cgroups. (This is a shared critique with StartTransientUnit but here it is even suggested by the commit message.) When I'm thinking about it now, it may be cleaner to specify no pid(fd)s and migrate only the calling process. (So that any possible children are started after migration.))

Yeah migration actually sucks. But we kinda dug our own grave here. scope units exist after all...

I think we might want to document this though, i.e. say that scopes (i.e. migrated processes) should only exist for a short time, or involve an execve() so that they are replaced.

Perhaps, in order to avoid the internal cloning of configuration, could there be some shared drop-ins between services and scopes that the scope would load upon start?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

RFE: Zero downtime restarts for services

8 participants