Skip to contentSkip to conversation

cgroup: add cpu.stat file to root cgroup

PATCH Superseded Boris Burkov 3 participants 5 messages May 26, 2020 – May 28, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup: add cpu.stat file to root cgroup

Currently, the root cgroup does not have a cpu.stat file. Add one which is consistent with /proc/stat to capture global cpu statistics that might not fall under cgroup accounting.

We haven't done this in the past because the data are already presented in /proc/stat and we didn't want to add overhead from collecting root cgroup stats when cgroups are configured, but no cgroups have been created.

By keeping the data consistent with /proc/stat, I think we avoid the first problem, while improving the usability of cgroups stats. We avoid the second problem by computing the contents of cpu.stat from existing data collected for /proc/stat anyway.

---
 kernel/cgroup/cgroup.c |  1 -
 kernel/cgroup/rstat.c  | 60 ++++++++++++++++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 9 deletions(-)
kernel/cgroup/cgroup.c +0 -1
index 557a9b9d2244..b8a75169c3e4 100644
@@ -4881,7 +4881,6 @@ static struct cftype cgroup_base_files[] = {
 	},
 	{
 		.name = "cpu.stat",
-		.flags = CFTYPE_NOT_ON_ROOT,
 		.seq_show = cpu_stat_show,
 	},
 #ifdef CONFIG_PSI
kernel/cgroup/rstat.c +52 -8

70 lines not on this page · raw message

Signature · 1 line
2.24.1
maintainer
#1 lore raw

Hello,

Quoted 9 lines · Boris Burkov

Currently, the root cgroup does not have a cpu.stat file. Add one which is consistent with /proc/stat to capture global cpu statistics that might not fall under cgroup accounting.

We haven't done this in the past because the data are already presented in /proc/stat and we didn't want to add overhead from collecting root cgroup stats when cgroups are configured, but no cgroups have been created.

Quoted 7 lines

By keeping the data consistent with /proc/stat, I think we avoid the first problem, while improving the usability of cgroups stats. We avoid the second problem by computing the contents of cpu.stat from existing data collected for /proc/stat anyway.

If there are any objections, please holler. I'll wait a few days and route it through the cgroup tree.

Thanks.

Signature · 1 line
tejun
maintainer
#2 lore raw
In reply to Boris Burkov
Quoted 9 lines · Boris Burkov

Currently, the root cgroup does not have a cpu.stat file. Add one which is consistent with /proc/stat to capture global cpu statistics that might not fall under cgroup accounting.

We haven't done this in the past because the data are already presented in /proc/stat and we didn't want to add overhead from collecting root cgroup stats when cgroups are configured, but no cgroups have been created.

Quoted 7 lines

By keeping the data consistent with /proc/stat, I think we avoid the first problem, while improving the usability of cgroups stats. We avoid the second problem by computing the contents of cpu.stat from existing data collected for /proc/stat anyway.

Looks good to me, but Boris can you please update Documentation/admin-guide/cgroup-v2.rst as well in this patch?

cpu.stat
A read-only flat-keyed file which exists on non-root cgroups.

Thanks!

#3 lore raw

PATCH v2 1/1 cgroup: add cpu.stat file to root cgroup

Currently, the root cgroup does not have a cpu.stat file. Add one which is consistent with /proc/stat to capture global cpu statistics that might not fall under cgroup accounting.

We haven't done this in the past because the data are already presented in /proc/stat and we didn't want to add overhead from collecting root cgroup stats when cgroups are configured, but no cgroups have been created.

By keeping the data consistent with /proc/stat, I think we avoid the first problem, while improving the usability of cgroups stats. We avoid the second problem by computing the contents of cpu.stat from existing data collected for /proc/stat anyway.

---
 Documentation/admin-guide/cgroup-v2.rst |  6 +--
 kernel/cgroup/cgroup.c                  |  1 -
 kernel/cgroup/rstat.c                   | 60 +++++++++++++++++++++----
 3 files changed, 54 insertions(+), 13 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +2 -4
index fed4e1d2a343..fec2f13fe065 100644
@@ -714,9 +714,7 @@ Conventions
 - Settings for a single feature should be contained in a single file.
 
 - The root cgroup should be exempt from resource control and thus
-  shouldn't have resource control interface files.  Also,
-  informational files on the root cgroup which end up showing global
-  information available elsewhere shouldn't exist.
+  shouldn't have resource control interface files.
 
 - The default time unit is microseconds.  If a different unit is ever
   used, an explicit unit suffix must be present.
@@ -985,7 +983,7 @@ CPU Interface Files
 All time durations are in microseconds.
 
   cpu.stat
-	A read-only flat-keyed file which exists on non-root cgroups.
+	A read-only flat-keyed file.
 	This file exists whether the controller is enabled or not.
 
 	It always reports the following three stats:
kernel/cgroup/cgroup.c +0 -1
index 557a9b9d2244..b8a75169c3e4 100644
@@ -4881,7 +4881,6 @@ static struct cftype cgroup_base_files[] = {
 	},
 	{
 		.name = "cpu.stat",
-		.flags = CFTYPE_NOT_ON_ROOT,
 		.seq_show = cpu_stat_show,
 	},
 #ifdef CONFIG_PSI
kernel/cgroup/rstat.c +52 -8

70 lines not on this page · raw message

Signature · 1 line
2.24.1
maintainer Applied
#4 lore raw
Quoted 9 lines · Boris Burkov

Currently, the root cgroup does not have a cpu.stat file. Add one which is consistent with /proc/stat to capture global cpu statistics that might not fall under cgroup accounting.

We haven't done this in the past because the data are already presented in /proc/stat and we didn't want to add overhead from collecting root cgroup stats when cgroups are configured, but no cgroups have been created.

Quoted 7 lines

By keeping the data consistent with /proc/stat, I think we avoid the first problem, while improving the usability of cgroups stats. We avoid the second problem by computing the contents of cpu.stat from existing data collected for /proc/stat anyway.

Applied to cgroup/for-5.8.

Thanks.

Signature · 1 line
tejun