[systemd-devel] Is it possible to set a default for MemoryMax?

Lennart Poettering mznyfn at 0pointer.de
Mon Jun 17 14:54:46 UTC 2019


On Do, 13.06.19 22:06, McKay, Sean (sean.mckay at hpe.com) wrote:

> Hi there,
>
> First off, forgive me if this is documented or discussed somewhere
> already. I couldn't find any reference to it in the man pages or in
> the mailing list archives, and I'm relatively new to this community
> so I could easily be missing something.
>
> Context that can be skipped if you only care about the technical
> part of the question: We're building a customized linux environment
> using systemd as the init system, and we've found that some of the
> daemons that we're including in said environment aren't particularly
> good citizens in regards to their resource consumption (admittedly
> most of those are the ones that have been written in house). As a
> result, while we try to track down and fix those bugs, we would like
> to limit the memory that processes are allowed to consume by default
> (with actual values in the .service files overriding that
> default). While we understand that this is the sort of thing that's
> probably best set individually per-daemon based on an understanding
> of how the daemon should behave, it would at least give us a
> starting point and would mean that a leaky process would be the one
> that crashed (when it hit the memory limit), rather than taking down
> the whole system or the OOM killer selecting a different process
> that's working correctly but still happens to be using more memory
> at the time.
>
> We've been trying to encourage our developers to use memory
> accounting and MemoryMax, since we're given to understand that's
> applied to the entire cgroup's memory usage for a given daemon's
> slice. The documentation, however, doesn't seem to indicate that a
> default value for any of the memory variables can be set in the
> system.conf file, and some quick experimental testing seems to
> indicate that's truly the case. There does seem to be support for
> setting the memory resource limit (limitas), but my understanding is
> that wouldn't apply to subprocesses that are spawned off by the
> parent daemon - they'd inherit the resource limit, but get their own
> instance of it (and I'm actually still trying to figure out if it
> would apply to threads, given the way I'm given to understand Linux
> treats threads. For memory, it would probably still cap things,
> since they're all in the same address space, but I'm unclear if that
> would be true of the other limits that can be applied).
>
> Am I missing something and this is possible to set? Or is it
> something that's come up and been rejected for some reason? Or has
> it come up and not been important relative to other development
> priorities? Or has it simply never come up because we're the first
> ones to want to do something so foolish?
>
> Any insight that you could provide would be greatly appreciated! Thanks.

See https://github.com/systemd/systemd/pull/12211

It adds this for MemoryLow=. I see no reason why we shouldn't add this
for MemoryMax= too. Please consider pinging @cdown about this, and
maybe prep a PR that adds this for you. It should be simple now, given
that the MemoryLow= case is very very similar.

Or maybe MemoryLow= is actually the knob you want to use and thus what
you are asking for already exists in current git?

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list