[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170727161420.2552-1-guro@fb.com>
Date: Thu, 27 Jul 2017 17:14:20 +0100
From: Roman Gushchin <guro@...com>
To: <cgroups@...r.kernel.org>
CC: Roman Gushchin <guro@...com>, Tejun Heo <tj@...nel.org>,
Zefan Li <lizefan@...wei.com>,
Waiman Long <longman@...hat.com>,
Johannes Weiner <hannes@...xchg.org>, <kernel-team@...com>,
<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] cgroup: add cgroup.stat interface with basic hierarchy stats
Add a cgroup.stat interface to the base cgroup control files
with the following metrics:
nr_descendants total number of descendant cgroups
nr_dying_descendants total number of dying descendant cgroups
max_descendant_depth maximum descent depth below the current cgroup
Signed-off-by: Roman Gushchin <guro@...com>
Cc: Tejun Heo <tj@...nel.org>
Cc: Zefan Li <lizefan@...wei.com>
Cc: Waiman Long <longman@...hat.com>
Cc: Johannes Weiner <hannes@...xchg.org>
Cc: kernel-team@...com
Cc: cgroups@...r.kernel.org
Cc: linux-doc@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
---
Documentation/cgroup-v2.txt | 12 ++++++++++++
kernel/cgroup/cgroup.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/Documentation/cgroup-v2.txt b/Documentation/cgroup-v2.txt
index dec5afdaa36d..ae9cc0d917b3 100644
--- a/Documentation/cgroup-v2.txt
+++ b/Documentation/cgroup-v2.txt
@@ -854,6 +854,18 @@ All cgroup core files are prefixed with "cgroup."
1 if the cgroup or its descendants contains any live
processes; otherwise, 0.
+ cgroup.stat
+ A read-only flat-keyed file with the following entries:
+
+ nr_descendants
+ Total number of descendant cgroups.
+
+ nr_dying_descendants
+ Total number of dying descendant cgroups.
+
+ max_descendant_depth
+ Maximum descent depth below the current cgroup.
+
Controllers
===========
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 85f6a112344b..b7af1745d46c 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3216,6 +3216,33 @@ static int cgroup_events_show(struct seq_file *seq, void *v)
return 0;
}
+static int cgroup_stats_show(struct seq_file *seq, void *v)
+{
+ struct cgroup_subsys_state *css;
+ unsigned long total = 0;
+ unsigned long offline = 0;
+ int max_level = 0;
+
+ rcu_read_lock();
+ css_for_each_descendant_pre(css, seq_css(seq)) {
+ if (css == seq_css(seq))
+ continue;
+ ++total;
+ if (!(css->flags & CSS_ONLINE))
+ ++offline;
+ if (css->cgroup->level > max_level)
+ max_level = css->cgroup->level;
+ }
+ rcu_read_unlock();
+
+ seq_printf(seq, "nr_descendants %lu\n", total);
+ seq_printf(seq, "nr_dying_descendants %lu\n", offline);
+ seq_printf(seq, "max_descendant_depth %d\n",
+ max_level - seq_css(seq)->cgroup->level);
+
+ return 0;
+}
+
static int cgroup_file_open(struct kernfs_open_file *of)
{
struct cftype *cft = of->kn->priv;
@@ -4309,6 +4336,10 @@ static struct cftype cgroup_base_files[] = {
.file_offset = offsetof(struct cgroup, events_file),
.seq_show = cgroup_events_show,
},
+ {
+ .name = "cgroup.stat",
+ .seq_show = cgroup_stats_show,
+ },
{ } /* terminate */
};
--
2.13.3
Powered by blists - more mailing lists