[systemd-devel] MemoryLimit and MemorySoftLimit

Lennart Poettering lennart at poettering.net
Mon Mar 26 07:46:17 PDT 2012


On Mon, 26.03.12 11:06, Albert Strasheim (fullung at gmail.com) wrote:

> Hello all
> 
> We want to limit the memory a service can use using MemoryLimit= and
> MemorySoftLimit= described in systemd.exec.
> 
> As I understand it, LimitAS= and LimitRSS= aren't particularly useful.
> Linux doesn't even implement LimitRSS?

LimitXXX act per-process, not per-service, the way MemoryLimit= does.

And yeah, not all LimiXXX actually make a lot of sense on Linux.

See http://www.kernel.org/doc/Documentation/cgroups/memory.txt for more
information how MemoryLimit= and MemorySoftLimit= work.

> Is there a way for an application to detect when it has hit its
> MemorySoftLimit=? We would like to log a warning at this point.

I am not aware that we had any infrastructure for notification of
userspace on memory suppression situations.

> Also, is there some standard way for the app[M#O7lication to determine if a
> MemoryLimit= is configured? We might want to automatically size some
> buffers based on this limit.

You can read /proc/self/cgroup. Find the line with ":memory:" there,
then extract the path after the second ":". Then use that path under
/sys/fs/cgroup/memory and read the "memory.soft_limit_in_bytes" file in
it.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list