Commit Graph
86361 Commits
Author SHA1 Message Date
Chris Down 31620807e1 oomd: Fix unnecessary delays during OOM kills with pending kills present
Let's say a user has two services with ManagedOOMMemoryPressure=kill,
perhaps a web server under system.slice and a batch job under
user.slice. Both exceed their pressure limits. On the previous timer
tick, oomd has already queued the web server's candidate for killing,
but the prekill hook has not yet responded, so the kill is still
pending.

In the code, monitor_memory_pressure_contexts_handler() iterates over
all pressure targets that have exceeded their limits. When it reaches
the web server target and calls oomd_cgroup_kill_mark(), which returns 0
because that cgroup is already queued. The code treats this the same as
a successful new kill: it resets the 15 second delay timer and returns
from the function, exiting the loop.

This loop is handled by SET_FOREACH and the iteration order is
hash-dependent. As such, if the web server target happens coincidentally
to be visited first, oomd never evaluates the batch job target at all.

The effect is twofold:

1. oomd stalls for 15 seconds despite not having initiated any new kill.
   That can unnecessarily delay further action to stem increases in
   memory pressure. The delay exists to let stale pressure counters
   settle after a kill, but no kill has happened here.
2. It non-deterministically skips pressure targets that may have
   unqueued candidates, dangerously allowing memory pressure to persist
   for longer than it should.

Fix this by skipping cgroups that are already queued so the loop
proceeds to try other pressure targets. We should only delay when a new
kill mark is actually created.
2026-02-17 18:26:04 +09:00
Chris Down 4fb8cc53b3 oomd: Fix silent failure to find bad cgroups when another cgroup dies
Consider a workload slice with several sibling cgroups. Imagine that one
of those cgroups is removed between the moment oomd enumerates the
directory and the moment it reads memory.oom.group. This is actually
relatively plausible under the high memory pressure conditions where
oomd is most needed.

In this case, the failed read prompts us to `return 0`, which exits the
entire enumeration loop in recursively_get_cgroup_context(). As a
result, all remaining sibling cgroups are silently dropped from the
candidate list for that monitoring cycle.

The effect is that oomd can fail to identify and kill the actual
offending cgroup, allowing memory pressure to persist until a subsequent
cycle where the race doesn't occur.

Fix this by instead proceeding to evaluate further sibling cgroups.
2026-02-17 17:32:26 +09:00
Chris Down e757e791b2 oomd: Fix silent, non-deterministic dropped OOM kills
Let's say a user has two services with ManagedOOMMemoryPressure=kill,
one for a web server under system.slice, and one for a batch job under
user.slice. The batch job is causing severe memory pressure, whereas the
web server's cgroup has no processes with significant pgscan activity.

In the code, monitor_memory_pressure_contexts_handler() iterates over
all pressure targets that have exceeded their limits. When
oomd_select_by_pgscan_rate() returns 0 (that is, no candidates) for a
target, we return from the entire SET_FOREACH loop instead of moving to
the next target. Since SET_FOREACH iteration order is hash-dependent, if
the web server target happens to be visited first, oomd will find no
kill candidates for it and exit the loop. The batch job target that is
actually slamming the machine will never even be evaluated, and can
continue to wreak havoc without any intervention.

The effect is that oomd non-deterministically and silently fails to kill
cgroups that it should actually kill, allowing memory pressure to
persist and dangerously build up on the machine.

The fix is simple, keep evaluating remaining targets when one does not
match.
2026-02-17 17:31:39 +09:00
Mike Yuan fad273450a socket-util: remove unused {send,receive}_many_fds*()
These were introduced as part of the effort of sd-executor
worker pool (#29566), which never landed due to unsignificant
performance improvement. Let's just remove the unused
helpers. If that work ever gets resurrected they can be
restored from this commit pretty easily.
2026-02-17 14:56:00 +09:00
Yu Watanabe d9e078fe68 oomd: Fix Killed signal reason being lost (#40689)
Emitting "oom" doesn't mesh with the org.freedesktop.oom1.Manager
Killed() API contract, which defines "memory-used" and "memory-pressure"
as possible reasons. Consumers that key off reason thus will either lose
policy attribution or may reject the unknown value completely.

Plumb the reason through so it is visible to consumers.
2026-02-17 14:53:46 +09:00
Chris Down b10e5a60aa oomd: Add regression tests to check Killed notification gives a reason 2026-02-17 14:50:21 +09:00
Chris Down 936d864b0b oomd: Fix Killed signal reason being lost
Emitting "oom" doesn't mesh with the org.freedesktop.oom1.Manager
Killed() API contract, which defines "memory-used" and "memory-pressure"
as possible reasons. Consumers that key off reason thus will either lose
policy attribution or may reject the unknown value completely.

Plumb the reason through so it is visible to consumers.
2026-02-17 14:50:17 +09:00
Daan De Meyer 48c84fe730 nspawn-mount: Use setns() in wipe_fully_visible_api_fs()
namespace_enter() now does a is_our_namespace() check, which requires
/proc on older kernels, which is not available anymore after we call
do_wipe_fully_visible_api_fs() in wipe_fully_visible_api_fs().

Let's just call setns() instead as namespace_enter() is overkill to
enter a single namespace anyway.
2026-02-17 04:55:24 +01:00
Yu Watanabe 710742270b report: enforce metric prefix (#40647)
Addressing
> we should enforce that metrics ids begin with the varlink service name

from #40633
2026-02-17 06:47:50 +09:00
Daan De Meyer 0ad6108c8e mkosi: Set CacheOnly=metadata for test images (#40699)
The default behavior is to sync repository metadata for every image
that does not have a cache and we recently changed behavior to
invalidate
all cached images whenever we decide the repository metadata needs to
be resynced.

In systemd we have two images that are not cached because they use
BaseTrees=
hence set CacheOnly=metadata to explicitly indicate these two images
should never cause a repository metadata if resync even though they are
not cached.
2026-02-16 15:42:35 +01:00
Ivan Kruglov cc14f78c02 report: validate metric name by socket 2026-02-16 05:46:24 -08:00
nikstur 5b193a8e23 meson: read more progs from PATH
Find more progs on PATH instead of hardcoding them.
2026-02-16 14:32:38 +01:00
Daan De Meyer 2a08e31cbd mkosi: Set CacheOnly=metadata for test images
The default behavior is to sync repository metadata for every image
that does not have a cache and we recently changed behavior to invalidate
all cached images whenever we decide the repository metadata needs to
be resynced.

In systemd we have two images that are not cached because they use BaseTrees=
hence set CacheOnly=metadata to explicitly indicate these two images
should never cause a repository metadata if resync even though they are
not cached.
2026-02-16 13:28:22 +01:00
Daan De Meyer 64ccae2a25 mkosi: update mkosi ref to 66d51024b7149f40be4702e84275c936373ace97
* 66d51024b7 man: Update caching section
* 4eac60f168 Remove all cached images if repository metadata will be synced
* 025c6c0150 Move Incremental= to inherited settings in docs
* 427970d8fd Make MakeScriptsExecutable= a multiversal setting
* 53bd2da6fe Look at all CacheOnly= settings to determine if we need to sync metadata
* 114ae558ef config / qemu: add Console=headless
2026-02-16 13:28:13 +01:00
Yu Watanabe 5e0c1f2e1b backlight: also change clamp percentage on ID_BACKLIGHT_CLAMP/ID_LEDS_CLAMP=yes
Follow-up for 4ed1e2ea17.
2026-02-16 21:24:55 +09:00
Yu Watanabe ad3e4af9a7 networkctl: use varlink method to bring up/down interfaces (#40693)
Closes #38538.
Closes #40017.
2026-02-16 20:35:29 +09:00
Yu Watanabe ed6a2eaa31 ask-password-api: several modernizations for ask_password_agent(); use CLEANUP_TMPFILE_AT more (#40631) 2026-02-16 20:07:32 +09:00
Ivan Kruglov b465e848f3 report: rearrange handling connection drop when skipping metrics 2026-02-16 02:34:11 -08:00
Daan De Meyer 4e40c2a515 namespace-util: Merge namespace_enter_delegated() into namespace_enter() (#40669)
There's no need to pass in a boolean to decide whether we use
namespace_enter_delegated() or not. Instead, we can just check if we
have CAP_SYS_ADMIN in our own user namespace. If we don't, then we have
to insist on a child user namespace being passed in and we have to enter
it first to get CAP_SYS_ADMIN as without CAP_SYS_ADMIN we wouldn't be
able
to call setns() in the first place. If we do have CAP_SYS_ADMIN, we can
always enter the other namespaces first before entering the user
namespace.

Additionally, we don't fail anymore if we can't reset the UID/GID since
a
root user might not always be available in every user namespace we might
enter.
2026-02-16 11:26:41 +01:00
r-vdp e271497d97 dns-delegates: add support for setting a firewall mark
This makes it possible to have DNS requests for certain domains routed
differently than normal requests, which is for instance useful when
using policy routing to route traffic over a VPN but DNS requests for
the VPN endpoint itself, should be routed differently.

It doesn't make much sense to configure a firewall mark at the level of
a network interface, but at the level of a DNS delegate it can be very
useful.
2026-02-16 11:09:48 +01:00
Daan De Meyer a5ceab95ab Varlink fixlets and several other follow-ups (#40687) 2026-02-16 11:02:08 +01:00
Daan De Meyer d1e0b59843 oomd: Fix bug where we drop queued kill state on duplicate cgroup (#40690) 2026-02-16 10:52:49 +01:00
Yu Watanabe 067758a3be networkctl: use varlink methods to bring up/down interfaces
Then,
- polkit authentication can be used,
- dynamic configuration engine can be safely stopped before bringing
  down interfaces.

Fixes #38538.
2026-02-16 18:37:17 +09:00
Yu Watanabe 314f93d9d3 networkctl: merge three functions for calling D-Bus methods 2026-02-16 18:37:17 +09:00
Yu Watanabe 63fd8c9b9e networkctl: use parse_interfaces() at one more place 2026-02-16 18:37:17 +09:00
Yu Watanabe 4610a4dc4c networkctl: split out parse_interfaces()
Also, this makes interfaces stored in OrderedSet rather than Set,
so interfaces becomes up/down in the specified order.

This also makes when multiple interfaces are specified, networkctl tries
to up/down all specfied interfaces even if some of them are failed.

Fixes #40017.
2026-02-16 18:37:17 +09:00
Daan De Meyer 211c3c9d41 namespace-util: Merge namespace_enter_delegated() into namespace_enter()
There's no need to pass in a boolean to decide whether we use
namespace_enter_delegated() or not. Instead, we can just check if we
have CAP_SYS_ADMIN in our own user namespace. If we don't, then we have
to insist on a child user namespace being passed in and we have to enter
it first to get CAP_SYS_ADMIN as without CAP_SYS_ADMIN we wouldn't be able
to call setns() in the first place. If we do have CAP_SYS_ADMIN, we can
always enter the other namespaces first before entering the user namespace.

Additionally, we don't fail anymore if we can't reset the UID/GID since a
root user might not always be available in every user namespace we might
enter.
2026-02-16 10:27:02 +01:00
Zbigniew Jędrzejewski-Szmek dae5af119b timesync: fix parsing FallbackNTP= (#40692)
Follow-up for 3745770ae4.
Fixes #40621.
2026-02-16 10:16:21 +01:00
Mike Yuan 389cd296ec core: serialize metrics varlink server as well 2026-02-16 09:44:58 +01:00
Mike Yuan 5561623ef4 core/manager-serialize: discern daemon-reload/reexec via objective 2026-02-16 09:44:58 +01:00
Mike Yuan b166461f82 varlink-serialize: deserialize to correct event priority 2026-02-16 09:44:58 +01:00
Mike Yuan 9676845efa core/varlink: several cleanups for metrics varlink server
Follow-up for bb1ef2edf7

The commit introduced a new "metrics" varlink server, but for
user scope stuff it is not bound anywhere. The copy-pasted
"fresh" handling for deserialization is also essentially
meaningless as metrics_setup_varlink_server() doesn't even report
whether the varlink server is fresh (let alone that no serialization
is being done at all right now). Moreover, currently the event
priority is hardcoded, while event loop and associated priority
assignment ought to be subject to each daemon.

While fixing the mentioned issues I took the chance to restructure
the existing code a bit for readability. Note that serialization
for the metrics server is still missing - it will be tackled
in subsequent commits.
2026-02-16 09:44:58 +01:00
Yu Watanabe ba08fa3230 shared/metrics: add two more assertions 2026-02-16 09:44:58 +01:00
Mike Yuan 702db03034 shared/metrics: name the sd_varlink_server in our usual fashion
This is used for internal reference, in debug logging and such,
hence let's do nothing fancy but instead make it identifiable.
2026-02-16 09:44:57 +01:00
Mike Yuan ba5bd88db3 core/varlink-metrics: suffix metrics methods with _metrics
This is not even the prominent "Describe" method in pid1,
as typically one would be looking for _describe_manager().
2026-02-16 09:44:57 +01:00
Mike Yuan 3cfd35eef9 core/varlink-metrics: include core-forward.h 2026-02-16 09:44:57 +01:00
Mike Yuan fe48347ce6 core/varlink-cgroup: add BindNetworkInterface to varlink CGContext
Follow-up for c1c787651b
2026-02-16 09:44:57 +01:00
Mike Yuan eeead6e177 sd-varlink: fail if a method call wasn't replied to and the callback didn't store it 2026-02-16 09:44:56 +01:00
Mike Yuan 1f9ba6ba73 sd-varlink: take output queue into account in sd_varlink_flush() 2026-02-16 09:44:56 +01:00
Mike Yuan 86ac1083c9 sd-varlink: _reset_fds() should reset fds for the reply being constructed
... (aka pushed_fds), not what's already enqueued to be sent out.
2026-02-16 09:44:56 +01:00
Mike Yuan 959f6923e5 sd-varlink: use free_and_replace at one more place 2026-02-16 09:44:56 +01:00
Mike Yuan 9257690859 sd-varlink: replace manual move_fd() with FORK_PACK_FDS + FORK_CLOEXEC_OFF
Note that this actually matters: we might otherwise clobber
the logging fds reopened when rearranging fd '3'.

While at it, avoid logging from library functions.
2026-02-16 09:44:56 +01:00
Mike Yuan 122bde2c45 sd-varlink: also validate peer ucred for SD_VARLINK_SERVER_MYSELF_ONLY 2026-02-16 09:44:55 +01:00
Mike Yuan 3482e4dd70 sd-varlink: log about client uid that hit connection limit 2026-02-16 09:44:55 +01:00
Mike Yuan e2fb041564 sd-varlink: shorten the code a bit 2026-02-16 09:44:55 +01:00
Mike Yuan 097243cc30 repart: io.systemd.Repart.ListCandidateDevices requires 'more' 2026-02-16 09:44:55 +01:00
Mike Yuan 03023fd12c resolve: io.systemd.Resolve.BrowseServices requires 'more' 2026-02-16 09:44:55 +01:00
Mike Yuan 41e675996d mute-console: io.systemd.MuteConsole requires 'more' 2026-02-16 09:44:54 +01:00
Mike Yuan 09388a6b9e tree-wide: drop redundant check for SD_VARLINK_METHOD_MORE flag
If the IDL declares the method requires 'more' yet the call doesn't
have it set, varlink_idl_validate_method_call() should have rejected
it and the callback shouldn't be reached.
2026-02-16 09:44:54 +01:00
Mike Yuan 42ed373294 varlink-io.systemd.Network: minor coding style cleanups
Follow-up for cf27c70d70
2026-02-16 09:44:54 +01:00