Skip to content

Commit 29da53d

Browse files
committed
core: always enable CPU accounting
Our baseline is v5.4 and cgroup v2 is enforced now, which means CPU accounting is cheap everywhere without requiring any controller, hence just remove the directive.
1 parent 7d71b23 commit 29da53d

26 files changed

+64
-201
lines changed

man/org.freedesktop.systemd1.xml

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,6 @@ node /org/freedesktop/systemd1 {
469469
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
470470
readonly u DefaultStartLimitBurst = ...;
471471
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
472-
readonly b DefaultCPUAccounting = ...;
473-
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
474472
readonly b DefaultIOAccounting = ...;
475473
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
476474
readonly b DefaultIPAccounting = ...;
@@ -707,8 +705,6 @@ node /org/freedesktop/systemd1 {
707705

708706
<!--property DefaultStartLimitBurst is not documented!-->
709707

710-
<!--property DefaultCPUAccounting is not documented!-->
711-
712708
<!--property DefaultIOAccounting is not documented!-->
713709

714710
<!--property DefaultIPAccounting is not documented!-->
@@ -1151,8 +1147,6 @@ node /org/freedesktop/systemd1 {
11511147

11521148
<variablelist class="dbus-property" generated="True" extra-ref="DefaultStartLimitBurst"/>
11531149

1154-
<variablelist class="dbus-property" generated="True" extra-ref="DefaultCPUAccounting"/>
1155-
11561150
<variablelist class="dbus-property" generated="True" extra-ref="DefaultIOAccounting"/>
11571151

11581152
<variablelist class="dbus-property" generated="True" extra-ref="DefaultIPAccounting"/>
@@ -2884,8 +2878,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
28842878
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
28852879
readonly s DelegateSubgroup = '...';
28862880
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
2887-
readonly b CPUAccounting = ...;
2888-
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
28892881
readonly t CPUWeight = ...;
28902882
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
28912883
readonly t StartupCPUWeight = ...;
@@ -3525,8 +3517,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
35253517

35263518
<!--property DelegateControllers is not documented!-->
35273519

3528-
<!--property CPUAccounting is not documented!-->
3529-
35303520
<!--property CPUWeight is not documented!-->
35313521

35323522
<!--property StartupCPUWeight is not documented!-->
@@ -4179,8 +4169,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
41794169

41804170
<variablelist class="dbus-property" generated="True" extra-ref="DelegateSubgroup"/>
41814171

4182-
<variablelist class="dbus-property" generated="True" extra-ref="CPUAccounting"/>
4183-
41844172
<variablelist class="dbus-property" generated="True" extra-ref="CPUWeight"/>
41854173

41864174
<variablelist class="dbus-property" generated="True" extra-ref="StartupCPUWeight"/>
@@ -5037,8 +5025,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket {
50375025
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
50385026
readonly s DelegateSubgroup = '...';
50395027
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
5040-
readonly b CPUAccounting = ...;
5041-
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
50425028
readonly t CPUWeight = ...;
50435029
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
50445030
readonly t StartupCPUWeight = ...;
@@ -5690,8 +5676,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket {
56905676

56915677
<!--property DelegateControllers is not documented!-->
56925678

5693-
<!--property CPUAccounting is not documented!-->
5694-
56955679
<!--property CPUWeight is not documented!-->
56965680

56975681
<!--property StartupCPUWeight is not documented!-->
@@ -6316,8 +6300,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket {
63166300

63176301
<variablelist class="dbus-property" generated="True" extra-ref="DelegateSubgroup"/>
63186302

6319-
<variablelist class="dbus-property" generated="True" extra-ref="CPUAccounting"/>
6320-
63216303
<variablelist class="dbus-property" generated="True" extra-ref="CPUWeight"/>
63226304

63236305
<variablelist class="dbus-property" generated="True" extra-ref="StartupCPUWeight"/>
@@ -7006,8 +6988,6 @@ node /org/freedesktop/systemd1/unit/home_2emount {
70066988
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
70076989
readonly s DelegateSubgroup = '...';
70086990
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
7009-
readonly b CPUAccounting = ...;
7010-
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
70116991
readonly t CPUWeight = ...;
70126992
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
70136993
readonly t StartupCPUWeight = ...;
@@ -7589,8 +7569,6 @@ node /org/freedesktop/systemd1/unit/home_2emount {
75897569

75907570
<!--property DelegateControllers is not documented!-->
75917571

7592-
<!--property CPUAccounting is not documented!-->
7593-
75947572
<!--property CPUWeight is not documented!-->
75957573

75967574
<!--property StartupCPUWeight is not documented!-->
@@ -8131,8 +8109,6 @@ node /org/freedesktop/systemd1/unit/home_2emount {
81318109

81328110
<variablelist class="dbus-property" generated="True" extra-ref="DelegateSubgroup"/>
81338111

8134-
<variablelist class="dbus-property" generated="True" extra-ref="CPUAccounting"/>
8135-
81368112
<variablelist class="dbus-property" generated="True" extra-ref="CPUWeight"/>
81378113

81388114
<variablelist class="dbus-property" generated="True" extra-ref="StartupCPUWeight"/>
@@ -8948,8 +8924,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap {
89488924
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
89498925
readonly s DelegateSubgroup = '...';
89508926
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
8951-
readonly b CPUAccounting = ...;
8952-
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
89538927
readonly t CPUWeight = ...;
89548928
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
89558929
readonly t StartupCPUWeight = ...;
@@ -9513,8 +9487,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap {
95139487

95149488
<!--property DelegateControllers is not documented!-->
95159489

9516-
<!--property CPUAccounting is not documented!-->
9517-
95189490
<!--property CPUWeight is not documented!-->
95199491

95209492
<!--property StartupCPUWeight is not documented!-->
@@ -10037,8 +10009,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap {
1003710009

1003810010
<variablelist class="dbus-property" generated="True" extra-ref="DelegateSubgroup"/>
1003910011

10040-
<variablelist class="dbus-property" generated="True" extra-ref="CPUAccounting"/>
10041-
1004210012
<variablelist class="dbus-property" generated="True" extra-ref="CPUWeight"/>
1004310013

1004410014
<variablelist class="dbus-property" generated="True" extra-ref="StartupCPUWeight"/>
@@ -10713,8 +10683,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice {
1071310683
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
1071410684
readonly s DelegateSubgroup = '...';
1071510685
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
10716-
readonly b CPUAccounting = ...;
10717-
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
1071810686
readonly t CPUWeight = ...;
1071910687
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
1072010688
readonly t StartupCPUWeight = ...;
@@ -10894,8 +10862,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice {
1089410862

1089510863
<!--property DelegateControllers is not documented!-->
1089610864

10897-
<!--property CPUAccounting is not documented!-->
10898-
1089910865
<!--property CPUWeight is not documented!-->
1090010866

1090110867
<!--property StartupCPUWeight is not documented!-->
@@ -11082,8 +11048,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice {
1108211048

1108311049
<variablelist class="dbus-property" generated="True" extra-ref="DelegateSubgroup"/>
1108411050

11085-
<variablelist class="dbus-property" generated="True" extra-ref="CPUAccounting"/>
11086-
1108711051
<variablelist class="dbus-property" generated="True" extra-ref="CPUWeight"/>
1108811052

1108911053
<variablelist class="dbus-property" generated="True" extra-ref="StartupCPUWeight"/>
@@ -11295,8 +11259,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
1129511259
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
1129611260
readonly s DelegateSubgroup = '...';
1129711261
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
11298-
readonly b CPUAccounting = ...;
11299-
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
1130011262
readonly t CPUWeight = ...;
1130111263
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
1130211264
readonly t StartupCPUWeight = ...;
@@ -11490,8 +11452,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
1149011452

1149111453
<!--property DelegateControllers is not documented!-->
1149211454

11493-
<!--property CPUAccounting is not documented!-->
11494-
1149511455
<!--property CPUWeight is not documented!-->
1149611456

1149711457
<!--property StartupCPUWeight is not documented!-->
@@ -11702,8 +11662,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
1170211662

1170311663
<variablelist class="dbus-property" generated="True" extra-ref="DelegateSubgroup"/>
1170411664

11705-
<variablelist class="dbus-property" generated="True" extra-ref="CPUAccounting"/>
11706-
1170711665
<variablelist class="dbus-property" generated="True" extra-ref="CPUWeight"/>
1170811666

1170911667
<variablelist class="dbus-property" generated="True" extra-ref="StartupCPUWeight"/>

man/systemd-cgtop.xml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@
4646
given, is honored. This mode is suitable for scripting.</para>
4747

4848
<para>Resource usage is only accounted for control groups with the appropriate controllers turned on:
49-
<literal>cpu</literal> controller for CPU usage, <literal>memory</literal> controller for memory usage,
50-
and <literal>io</literal> controller for disk I/O consumption. If resource monitoring for these resources
51-
is required, it is recommended to add the <varname>CPUAccounting=1</varname>,
52-
<varname>MemoryAccounting=1</varname> and <varname>IOAccounting=1</varname> settings in the unit files in
53-
question. See
49+
<literal>memory</literal> controller for memory usage and <literal>io</literal> controller for disk I/O consumption.
50+
If resource monitoring for these resources is required, it is recommended to add the <varname>MemoryAccounting=1</varname>
51+
and <varname>IOAccounting=1</varname> settings in the unit files in question. See
5452
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
5553
for details.</para>
5654

@@ -59,10 +57,9 @@
5957
the CPU load value is going to be between 0% and 800%. The number of
6058
processors can be found in <literal>/proc/cpuinfo</literal>.</para>
6159

62-
<para>To emphasize: unless <literal>CPUAccounting=1</literal>, <literal>MemoryAccounting=1</literal>, and
63-
<literal>IOAccounting=1</literal> are enabled for the services in question, no resource accounting will
64-
be available for system services and the data shown by <command>systemd-cgtop</command> will be
65-
incomplete.</para>
60+
<para>To emphasize: unless <literal>MemoryAccounting=1</literal> and <literal>IOAccounting=1</literal>
61+
are enabled for the services in question, no resource accounting will be available for system services
62+
and the data shown by <command>systemd-cgtop</command> will be incomplete.</para>
6663
</refsect1>
6764

6865
<refsect1>

man/systemd-system.conf.xml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,19 @@
201201
</varlistentry>
202202

203203
<varlistentry>
204-
<term><varname>DefaultCPUAccounting=</varname></term>
205204
<term><varname>DefaultMemoryAccounting=</varname></term>
206205
<term><varname>DefaultTasksAccounting=</varname></term>
207206
<term><varname>DefaultIOAccounting=</varname></term>
208207
<term><varname>DefaultIPAccounting=</varname></term>
209208

210209
<listitem>
211210
<para>Configure the default resource accounting settings, as configured per-unit by
212-
<varname>CPUAccounting=</varname>, <varname>MemoryAccounting=</varname>,
213-
<varname>TasksAccounting=</varname>, <varname>IOAccounting=</varname> and
214-
<varname>IPAccounting=</varname>. See
211+
<varname>MemoryAccounting=</varname>, <varname>TasksAccounting=</varname>, <varname>IOAccounting=</varname>,
212+
and <varname>IPAccounting=</varname>. See
215213
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
216214
for details on the per-unit settings.</para>
217215

218-
<para><varname>DefaultCPUAccounting=</varname> defaults to yes when running on kernel ≥4.15, and no on older versions.
219-
<varname>DefaultMemoryAccounting=</varname> defaults to &MEMORY_ACCOUNTING_DEFAULT;.
216+
<para><varname>DefaultMemoryAccounting=</varname> defaults to &MEMORY_ACCOUNTING_DEFAULT;.
220217
<varname>DefaultTasksAccounting=</varname> defaults to yes.
221218
The other settings default to no.</para>
222219

@@ -759,6 +756,15 @@
759756
to the unified cgroup hierarchy.</para></listitem>
760757
</varlistentry>
761758
</variablelist>
759+
760+
<variablelist>
761+
<varlistentry>
762+
<term>systemd 258</term>
763+
764+
<listitem><para><varname>DefaultCPUAccounting=</varname> setting is deprecated, because CPU accounting
765+
is always available on the unified cgroup hierarchy and such setting has no effect.</para></listitem>
766+
</varlistentry>
767+
</variablelist>
762768
</refsect1>
763769

764770
<refsect1>

man/systemd.resource-control.xml

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,10 @@ CPUWeight=20 DisableControllers=cpu / \
179179

180180
<para>Units of the types listed above can have settings for resource control configuration:</para>
181181

182-
<refsect2><title>CPU Accounting and Control</title>
182+
<refsect2><title>CPU Control</title>
183183

184184
<variablelist class='unit-directives'>
185185

186-
<varlistentry>
187-
<term><varname>CPUAccounting=</varname></term>
188-
189-
<listitem>
190-
<para>Turn on CPU usage accounting for this unit. Takes a
191-
boolean argument. Note that turning on CPU accounting for
192-
one unit will also implicitly turn it on for all units
193-
contained in the same slice and for all its parent slices
194-
and the units contained therein. The system default for this
195-
setting may be controlled with
196-
<varname>DefaultCPUAccounting=</varname> in
197-
<citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
198-
199-
<para>Under the unified cgroup hierarchy, CPU accounting is available for all units and this
200-
setting has no effect.</para>
201-
202-
<xi:include href="version-info.xml" xpointer="v208"/>
203-
</listitem>
204-
</varlistentry>
205-
206186
<varlistentry>
207187
<term><varname>CPUWeight=<replaceable>weight</replaceable></varname></term>
208188
<term><varname>StartupCPUWeight=<replaceable>weight</replaceable></varname></term>
@@ -1707,6 +1687,15 @@ DeviceAllow=/dev/loop-control
17071687
Please switch to the unified cgroup hierarchy.</para></listitem>
17081688
</varlistentry>
17091689
</variablelist>
1690+
1691+
<variablelist>
1692+
<varlistentry>
1693+
<term>systemd 258</term>
1694+
1695+
<listitem><para><varname>CPUAccounting=</varname> setting is deprecated, because it is always available
1696+
on the unified cgroup hierarchy and such setting has no effect.</para></listitem>
1697+
</varlistentry>
1698+
</variablelist>
17101699
</refsect1>
17111700

17121701
<refsect1>

src/basic/cgroup-util.c

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,57 +2181,6 @@ static const char *const cgroup_controller_table[_CGROUP_CONTROLLER_MAX] = {
21812181

21822182
DEFINE_STRING_TABLE_LOOKUP(cgroup_controller, CGroupController);
21832183

2184-
CGroupMask get_cpu_accounting_mask(void) {
2185-
static CGroupMask needed_mask = (CGroupMask) -1;
2186-
2187-
/* On kernel ≥4.15 with unified hierarchy, cpu.stat's usage_usec is
2188-
* provided externally from the CPU controller, which means we don't
2189-
* need to enable the CPU controller just to get metrics. This is good,
2190-
* because enabling the CPU controller comes at a minor performance
2191-
* hit, especially when it's propagated deep into large hierarchies.
2192-
* There's also no separate CPU accounting controller available within
2193-
* a unified hierarchy.
2194-
*
2195-
* This combination of factors results in the desired cgroup mask to
2196-
* enable for CPU accounting varying as follows:
2197-
*
2198-
* ╔═════════════════════╤═════════════════════╗
2199-
* ║ Linux ≥4.15 │ Linux <4.15 ║
2200-
* ╔═══════════════╬═════════════════════╪═════════════════════╣
2201-
* ║ Unified ║ nothing │ CGROUP_MASK_CPU ║
2202-
* ╟───────────────╫─────────────────────┼─────────────────────╢
2203-
* ║ Hybrid/Legacy ║ CGROUP_MASK_CPUACCT │ CGROUP_MASK_CPUACCT ║
2204-
* ╚═══════════════╩═════════════════════╧═════════════════════╝
2205-
*
2206-
* We check kernel version here instead of manually checking whether
2207-
* cpu.stat is present for every cgroup, as that check in itself would
2208-
* already be fairly expensive.
2209-
*
2210-
* Kernels where this patch has been backported will therefore have the
2211-
* CPU controller enabled unnecessarily. This is more expensive than
2212-
* necessary, but harmless. ☺️
2213-
*/
2214-
2215-
if (needed_mask == (CGroupMask) -1) {
2216-
if (cg_all_unified()) {
2217-
struct utsname u;
2218-
assert_se(uname(&u) >= 0);
2219-
2220-
if (strverscmp_improved(u.release, "4.15") < 0)
2221-
needed_mask = CGROUP_MASK_CPU;
2222-
else
2223-
needed_mask = 0;
2224-
} else
2225-
needed_mask = CGROUP_MASK_CPUACCT;
2226-
}
2227-
2228-
return needed_mask;
2229-
}
2230-
2231-
bool cpu_accounting_is_cheap(void) {
2232-
return get_cpu_accounting_mask() == 0;
2233-
}
2234-
22352184
static const char* const managed_oom_mode_table[_MANAGED_OOM_MODE_MAX] = {
22362185
[MANAGED_OOM_AUTO] = "auto",
22372186
[MANAGED_OOM_KILL] = "kill",

src/basic/cgroup-util.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ static inline CGroupMask CGROUP_MASK_EXTEND_JOINED(CGroupMask mask) {
8686
return mask;
8787
}
8888

89-
CGroupMask get_cpu_accounting_mask(void);
90-
bool cpu_accounting_is_cheap(void);
91-
9289
/* Special values for all weight knobs on unified hierarchy */
9390
#define CGROUP_WEIGHT_INVALID UINT64_MAX
9491
#define CGROUP_WEIGHT_IDLE UINT64_C(0)

0 commit comments

Comments
 (0)