public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Roman Gushchin <guro@fb.com>
To: <cgroups@vger.kernel.org>
Cc: Roman Gushchin <guro@fb.com>, Tejun Heo <tj@kernel.org>,
	Zefan Li <lizefan@huawei.com>, Waiman Long <longman@redhat.com>,
	Johannes Weiner <hannes@cmpxchg.org>, <kernel-team@fb.com>,
	<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] cgroup: add cgroup.stat interface with basic hierarchy stats
Date: Thu, 27 Jul 2017 17:14:20 +0100	[thread overview]
Message-ID: <20170727161420.2552-1-guro@fb.com> (raw)

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@fb.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: kernel-team@fb.com
Cc: cgroups@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.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

             reply	other threads:[~2017-07-27 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 16:14 Roman Gushchin [this message]
2017-07-27 16:22 ` [PATCH] cgroup: add cgroup.stat interface with basic hierarchy stats Tejun Heo
2017-07-28 13:01   ` Roman Gushchin
2017-07-28 15:09     ` Tejun Heo
2017-07-27 17:38 ` Waiman Long
2017-07-27 17:46   ` Roman Gushchin
2017-07-27 17:55     ` Waiman Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170727161420.2552-1-guro@fb.com \
    --to=guro@fb.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=longman@redhat.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox