Bug 1257897

Summary: systemd-cgtop shows memory usage for services with MemoryAccounting=no
Product: Red Hat Enterprise Linux 7 Reporter: Branislav Blaškovič <bblaskov>
Component: systemdAssignee: systemd-maint
Status: CLOSED CANTFIX QA Contact: qe-baseos-daemons
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.2CC: lnykryn, systemd-maint-list
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-08-28 11:28:12 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Branislav Blaškovič 2015-08-28 11:01:42 UTC
Version-Release number of selected component (if applicable):
systemd-219-11.el7.x86_64

Description of problem:
If I take a look at systemd-cgtop I can see that we are not counting memory consuption for any slice:

Path                                                                            Tasks   %CPU   Memory  Input/s Output/s
/                                                                                  89    0.7   212.2M        -        -
/system.slice/ModemManager.service                                                  1      -        -        -        -
/system.slice/NetworkManager.service                                                2      -        -        -        -
/system.slice/auditd.service                                                        1      -        -        -        -
/system.slice/avahi-daemon.service                                                  2      -        -        -        -
/system.slice/crond.service                                                         1      -        -        -        -
/system.slice/dbus.service                                                          1      -        -        -        -
/system.slice/gssproxy.service                                                      1      -        -        -        -
/system.slice/lvm2-lvmetad.service                                                  1      -        -        -        -
/system.slice/polkit.service                                                        1      -        -        -        -
/system.slice/postfix.service                                                       3      -        -        -        -
/system.slice/rhnsd.service                                                         1      -        -        -        -
/system.slice/rhsmcertd.service                                                     1      -        -        -        -
/system.slice/rpc-statd.service                                                     1      -        -        -        -
/system.slice/rpcbind.service                                                       1      -        -        -        -
/system.slice/rsyslog.service                                                       1      -        -        -        -
/system.slice/sshd.service                                                          1      -        -        -        -
/system.slice/system-getty.slice/getty                                 1      -        -        -        -
/system.slice/system-serial\x2dgetty.slice/serial-getty               1      -        -        -        -
/system.slice/systemd-journald.service                                              1      -        -        -        -
/system.slice/systemd-logind.service                                                1      -        -        -        -
/system.slice/systemd-udevd.service                                                 1      -        -        -        -
/system.slice/tuned.service                                                         1      -        -        -        -
/system.slice/wpa_supplicant.service                                                1      -        -        -        -
/user.slice/user-0.slice/session-3.scope                                            1      -        -        -        -
/user.slice/user-0.slice/session-4.scope                                            4      -        -        -        -

Then I set MemoryAccounting for sshd in its service file, restart it and run systemd-cgtop again:

Path                                                                            Tasks   %CPU   Memory  Input/s Output/s
/                                                                                  90    1.3   217.6M        -        -
/system.slice                                                                       -      -   948.0K        -        -
/system.slice/ModemManager.service                                                  1      -        -        -        -
/system.slice/NetworkManager.service                                                2      -     4.0K        -        -
/system.slice/auditd.service                                                        1      -     4.0K        -        -
/system.slice/avahi-daemon.service                                                  2      -        -        -        -
/system.slice/crond.service                                                         1      -        -        -        -
/system.slice/dbus.service                                                          1      -        -        -        -
/system.slice/gssproxy.service                                                      1      -        -        -        -
/system.slice/lvm2-lvmetad.service                                                  1      -        -        -        -
/system.slice/polkit.service                                                        1      -        -        -        -
/system.slice/postfix.service                                                       3      -        -        -        -
/system.slice/rhnsd.service                                                         1      -        -        -        -
/system.slice/rhsmcertd.service                                                     1      -        -        -        -
/system.slice/rpc-statd.service                                                     1      -        -        -        -
/system.slice/rpcbind.service                                                       1      -        -        -        -
/system.slice/rsyslog.service                                                       1      -     4.0K        -        -
/system.slice/sshd.service                                                          1      -   856.0K        -        -
/system.slice/system-getty.slice/getty                                 1      -        -        -        -
/system.slice/system-serial\x2dgetty.slice/serial-getty               1      -        -        -        -
/system.slice/systemd-journald.service                                              1      -    80.0K        -        -
/system.slice/systemd-logind.service                                                1      -        -        -        -
/system.slice/systemd-udevd.service                                                 1      -        -        -        -
/system.slice/tuned.service                                                         1      -        -        -        -
/system.slice/wpa_supplicant.service                                                1      -        -        -        -
/user.slice/user-0.slice/session-3.scope                                            1      -        -        -        -
/user.slice/user-0.slice/session-4.scope                                            4      -        -        -        -

This is weird, because it's counting memory for auditd, NetworkManager and others. But they don't have MemoryAccounting:

# systemctl show auditd.service | grep MemoryAccounting
MemoryAccounting=no
# systemctl show NetworkManager.service | grep MemoryAccounting
MemoryAccounting=no

In systemd-cgtop man page [1] is:
    unless "CPUAccounting=1", "MemoryAccounting=1" and "BlockIOAccounting=1" are enabled for the services in question, no resource accounting will be available for system services and the data shown by systemd-cgtop will be incomplete

[1] http://www.freedesktop.org/software/systemd/man/systemd-cgtop.html

Comment 2 Lukáš Nykrýn 2015-08-28 11:28:12 UTC
This is basically expected, if you turn on memory accounting for one service, whole slice will have memory accounting due to cgroup implementation.
http://www.freedesktop.org/software/systemd/man/systemd.resource-control.html#MemoryAccounting=

Then every new proccess in such slice will have memory accounting (try to restart crond).