OOMScoreAdjust corresponds to a per-process parameter, not a cgroup
parameter (it is set through /proc/PID/oom_score_adj and inherited by child
processes).

When creating a .service, systemd is always in charge of creating
(forking/exec'ing) the process, but when creating a .scope, systemd only
receives the PID of an already-running process (directly spawned by
systemd-run in your shell) which it merely moves into the new cgroup.

As far as I can see, there's currently no handling for adjusting things
like OOM score or rlimits of existing processes even if they're technically
adjustable from outside – systemd only knows how to set oom_score_adj
through /proc/self (i.e. when it forks → adjusts limits → execs the service
binary) but not for a given PID.

Set the shell's (or subshell's) oom_score_adj before calling systemd-run,
then it will be inherited by the process you're about to move into the
scope.

    # (echo 500 > /proc/self/oom_score_adj; systemd-run --scope foo)

Systemd-oomd (userspace OOM handling) doesn't seem to care about oom_score,
only looking at per-cgroup memory "pressure" statistics if I understand it
correctly.

On Sun, Nov 2, 2025 at 11:53 PM Daniel Hast <[email protected]>
wrote:

> Hello,
>
> I'm trying to use systemd to manage memory limits for a group of
> processes. I can create a scope unit with memory limits, enable cgroup
> delegation, and move the processes into a sub-cgroup of the scope unit;
> that works fine. However, I'd also like to make the cgroup a preferred
> target for the OOM killer, and I'm having trouble figuring out how to do
> that.
>
> The documentation at systemd.scope(5)
> <https://www.freedesktop.org/software/systemd/man/latest/systemd.scope.html>
>  says:
>
> Use the OOMScoreAdjust= setting to configure whether processes of the
> unit shall be considered preferred or less preferred candidates for process
> termination by the Linux OOM killer logic.
>
> However, if I try to set OOMScoreAdjust for the scope unit (either using
> --property=OOMScoreAdjust=​ as an argument to systemd-run​ or passing it
> as a property in a call to StartTransientUnit​ via dbus), it gives an
> error indicating it's not a valid property.
>
> Is there a way to set the default OOM score adjustment for a cgroup
> associated with a scope unit? Or do I have to adjust the OOM score for each
> process in the cgroup individually?
>
> Thanks,
> Daniel Hast
>

Reply via email to