What causes systemctl to show or hide memory or CPU usage of services?
Today morning:
# systemctl status udev
? systemd-udevd.service - udev Kernel Device Manager
Loaded: loaded (/lib/systemd/system/systemd-udevd.service; static; vendor preset: enabled)
Active: active (running) since Sat 2021-03-13 12:08:58 CET; 5 days ago
Docs: man:systemd-udevd.service(8)
man:udev(7)
Main PID: 451 (systemd-udevd)
Status: "Processing..."
Tasks: 1
Memory: 4.5M
CPU: 6.038s
CGroup: /system.slice/systemd-udevd.service
└─451 /lib/systemd/systemd-udevd
Just now (same system - VM with Ubuntu16LTS):
# systemctl status udev
? systemd-udevd.service - udev Kernel Device Manager
Loaded: loaded (/lib/systemd/system/systemd-udevd.service; static; vendor preset: enabled)
Active: active (running) since Sat 2021-03-13 12:08:58 CET; 5 days ago
Docs: man:systemd-udevd.service(8)
man:udev(7)
Main PID: 451 (systemd-udevd)
Status: "Processing..."
CGroup: /system.slice/systemd-udevd.service
└─451 /lib/systemd/systemd-udevd
Notice the omission of the Tasks:
, Memory:
and CPU:
lines.
What has changed here ? (I did not change anything intentionally ...)
Edit: ps
output looks unobtrusively:
# ps l 451
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
4 0 451 1 20 0 45672 4732 ep_pol Ss ? 0:01 /lib/systemd/systemd-udevd
I think it has nothing to do with udev
but rather with systemd
because I can see the same effect (missing CPU etc.) with other services, too.
Edit #2: systemctl --version
reports 229.
# systemctl show udev | grep Accounting
CPUAccounting=no
BlockIOAccounting=no
MemoryAccounting=no
TasksAccounting=no
# cgmanager
The program 'cgmanager' is currently not installed.
Extract of findmnt
output:
/sys/fs/cgroup
├─/sys/fs/cgroup/systemd
├─/sys/fs/cgroup/memory
├─/sys/fs/cgroup/blkio
├─/sys/fs/cgroup/cpu,cpuacct
├─/sys/fs/cgroup/pids
├─/sys/fs/cgroup/net_cls,net_prio
├─/sys/fs/cgroup/freezer
├─/sys/fs/cgroup/devices
├─/sys/fs/cgroup/cpuset
├─/sys/fs/cgroup/hugetlb
└─/sys/fs/cgroup/perf_event
Edit #3: After a reboot of the VM in question, I'm getting the measurements again while accounting is still disabled:
# systemctl show udev | grep Accounting
CPUAccounting=no
BlockIOAccounting=no
MemoryAccounting=no
TasksAccounting=no
# systemctl status udev
...
Main PID: 444 (systemd-udevd)
Status: "Processing..."
Tasks: 1
Memory: 18.9M
CPU: 4.211s
CGroup: /system.slice/systemd-udevd.service
└─444 /lib/systemd/systemd-udevd
So it doesn't look like those values are generated by the Accounting settings.
Even the global defaults are off:
# systemctl show | grep Accounting
DefaultCPUAccounting=no
DefaultBlockIOAccounting=no
DefaultMemoryAccounting=no
DefaultTasksAccounting=no
Memory usage is reported with the MemoryAccounting=
option, which is enabled by default starting with v238 (unless the distro chooses otherwise) and of course can be enabled by individual units which need to set memory limits. This option uses the "memory" cgroup controller, and appears to work with both v1 and v2 hierarchies.
CPU usage is reported by default starting with v240 on kernel v4.15 and later, if the "unified" (v2-only) cgroup hierarchy is being used. In older versions, it can be enabled using CPUAccounting=
per unit but has greater impact, as the "CPU" cgroup controller was necessary to obtain this information pre 4.15.
The number of tasks, too, is reported with the TasksAccounting=
option using the "pids" cgroup controller.
All three functions can be enabled globally (in systemd/system.conf) or per unit. They can be changed on the fly for running services as well. They will of course stop working if other processes (such as cgmanager) meddle with cgroup controller assignments, or if those controllers suddenly disappear from /sys (check findmnt
), or if pid1 is denied access to them by LSMs (bad idea).