Bug 78738

Summary: DOC: Setting MemoryLimit does not imply "MemoryAccounting=true"
Product: systemd Reporter: Andy Melnikov <andy.melnikov>
Component: generalAssignee: systemd-bugs
Status: RESOLVED FIXED QA Contact: systemd-bugs
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Andy Melnikov 2014-05-15 12:20:30 UTC
http://www.freedesktop.org/software/systemd/man/systemd.resource-control.html says that MemoryLimit implies "MemoryAccounting=true".

But it's not the case. If I don't put an explicit "MemoryAccounting=true" in the unit file below, service control groups under memory is not created and memory limit doesn't work.

----
[Unit]
Description=foo
After=network.target

[Service]
User=bar
WorkingDirectory=/home/bar
ExecStart=/usr/bin/foo
Restart=always
RestartSec=5min
MemoryLimit=256M

[Install]
WantedBy=multi-user.target
----

[root@quux ~]# systemctl show foo -p MemoryLimit
MemoryLimit=268435456
[root@quux ~]# systemctl show foo -p MemoryAccounting
MemoryAccounting=no
Comment 1 Lennart Poettering 2014-05-24 06:56:38 UTC
Note that setting MemoryLimit= effectively turns on MemoryAccounting= but it won't show it with "systemctl show", since that actually shows the original MemoryAccounting= setting.

Or in other words, there's a distinction between the MemoryAccounting= setting (which is unaffected by MemoryLimit=, as you experienced), and the actual memory accounting which is turned on in the kernel either by using MemoryAccounting= or by MemoryLimit=. If you follow wht I mean.

Anyway, this is actually intended behaviour, but certainly something we could document better. Hence renaming the bug accordingly.
Comment 2 Lennart Poettering 2018-07-20 14:46:43 UTC
We dropped the offending sentences now from the man page. Closing.

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

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.