linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Tejun Heo <tj@kernel.org>, Li Zefan <lizefan@huawei.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-mm@kvack.org,
	kernel-team@fb.com, pjt@google.com, luto@amacapital.net,
	efault@gmx.de, longman@redhat.com
Subject: [RFC PATCH v2 14/17] cgroup: Enable printing of v2 controllers' cgroup hierarchy
Date: Mon, 15 May 2017 09:34:13 -0400	[thread overview]
Message-ID: <1494855256-12558-15-git-send-email-longman@redhat.com> (raw)
In-Reply-To: <1494855256-12558-1-git-send-email-longman@redhat.com>

This patch add a new debug control file on the cgroup v2 root directory
to print out the cgroup hierarchy for each of the v2 controllers.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/cgroup/debug.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)

diff --git a/kernel/cgroup/debug.c b/kernel/cgroup/debug.c
index a2dbf77..3adb26a 100644
--- a/kernel/cgroup/debug.c
+++ b/kernel/cgroup/debug.c
@@ -268,6 +268,141 @@ static int cgroup_masks_read(struct seq_file *seq, void *v)
 	return 0;
 }
 
+/*
+ * Print out all the child cgroup names that doesn't have a css for the
+ * corresponding cgroup_subsys. If a child cgroup has a css, put that into
+ * the given cglist to be processed in the next iteration.
+ */
+#define CGLIST_MAX	16
+static void print_hierarchy(struct seq_file *seq,
+			    struct cgroup *cgrp,
+			    struct cgroup_subsys *ss,
+			    struct cgroup_subsys_state *css,
+			    struct cgroup **cglist,
+			    int *cgcnt)
+{
+	struct cgroup *child;
+	struct cgroup_subsys_state *child_css;
+	char cgname[64];
+
+	cgname[sizeof(cgname) - 1] = '\0';
+	/*
+	 * Iterate all live children of the given cgroup.
+	 */
+	list_for_each_entry(child, &cgrp->self.children, self.sibling) {
+		if (cgroup_is_dead(child))
+			continue;
+
+		child_css = rcu_dereference_check(child->subsys[ss->id], true);
+		if (child_css) {
+			WARN_ON(child_css->parent != css);
+			if (*cgcnt < CGLIST_MAX) {
+				cglist[*cgcnt] = child;
+				(*cgcnt)++;
+			}
+			continue;
+		}
+
+		/*
+		 * Skip resource domain cgroup
+		 */
+		if (test_bit(CGRP_RESOURCE_DOMAIN, &child->flags))
+			continue;
+
+		cgroup_name(child, cgname, sizeof(cgname)-1);
+		seq_putc(seq, ',');
+		seq_puts(seq, cgname);
+		print_hierarchy(seq, child, ss, css, cglist, cgcnt);
+	}
+}
+
+/*
+ * Print the hierachies with respect to each controller for the default
+ * hierarchy.
+ *
+ * Each child level is printed on a separate line. Set of cgroups that
+ * have the same css will be grouped together and separated by comma.
+ * Process in those cgroups will be in the same node (css) in the
+ * controller's hierarchy. There is an exception that for resource
+ * domain cgroup, the processes associated with its parent and its
+ * affiliates will be mapped to the css of that resource domain cgroup
+ * instead.
+ *
+ * If there are more than CGLIST_MAX sets of cgroups in each level,
+ * the extra ones will be skipped.
+ */
+static int controller_hierachies_read(struct seq_file *seq, void *v)
+{
+	struct cgroup *root = seq_css(seq)->cgroup;
+	struct cgroup_subsys *ss;
+	struct cgroup_subsys_state *css;
+	struct cgroup *cgrp;
+	struct cgroup *cglist[CGLIST_MAX];
+	struct cgroup *cg2list[CGLIST_MAX];
+	int i, idx, cgnum, cg2num;
+	char cgname[64];
+
+	cgname[sizeof(cgname) - 1] = '\0';
+	mutex_lock(&cgroup_mutex);
+	for_each_subsys(ss, i) {
+		if (!(root->root->subsys_mask & (1 << ss->id)))
+			continue;
+		seq_puts(seq, ss->name);
+		seq_puts(seq, ":\n");
+
+		cgnum = 1;
+		cg2num = 0;
+		cglist[0] = root;
+		idx = 0;
+		while (cgnum) {
+			if (idx)
+				seq_putc(seq, ' ');
+			cgrp = cglist[idx];
+			if (test_bit(CGRP_RESOURCE_DOMAIN, &cgrp->flags)) {
+				struct cgroup *parent;
+
+				parent = container_of(cgrp->self.parent,
+						      struct cgroup, self);
+				cgroup_name(parent, cgname, sizeof(cgname)-1);
+				seq_printf(seq, "%s.rd", cgname);
+			} else {
+				cgroup_name(cgrp, cgname, sizeof(cgname)-1);
+				seq_puts(seq, cgname);
+			}
+			css = rcu_dereference_check(cgrp->subsys[ss->id], true);
+			WARN_ON(!css);
+
+			if (cgrp == root)
+				seq_printf(seq, "[%d]", css->id);
+			else
+				seq_printf(seq, "[%d:P=%d]", css->id,
+					   css->parent->id);
+
+			/*
+			 * List all the cgroups that use the current
+			 * css.
+			 */
+			print_hierarchy(seq, cgrp, ss, css, cg2list, &cg2num);
+
+			if (++idx < cgnum)
+				continue;
+
+			/*
+			 * Move cg2list to cglist.
+			 */
+			cgnum = cg2num;
+			idx = cg2num = 0;
+			if (cgnum)
+				memcpy(cglist, cg2list,
+				       cgnum * sizeof(cglist[0]));
+			seq_putc(seq, '\n');
+		}
+		seq_putc(seq, '\n');
+	}
+	mutex_unlock(&cgroup_mutex);
+	return 0;
+}
+
 static u64 releasable_read(struct cgroup_subsys_state *css, struct cftype *cft)
 {
 	return (!cgroup_is_populated(css->cgroup) &&
@@ -314,6 +449,12 @@ static u64 releasable_read(struct cgroup_subsys_state *css, struct cftype *cft)
 	},
 
 	{
+		.name = "controller_hierachies",
+		.seq_show = controller_hierachies_read,
+		.flags = CFTYPE_ONLY_ON_ROOT|__CFTYPE_ONLY_ON_DFL,
+	},
+
+	{
 		.name = "releasable",
 		.read_u64 = releasable_read,
 	},
-- 
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2017-05-15 13:35 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-15 13:33 [RFC PATCH v2 00/17] cgroup: Major changes to cgroup v2 core Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 01/17] cgroup: reorganize cgroup.procs / task write path Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 02/17] cgroup: add @flags to css_task_iter_start() and implement CSS_TASK_ITER_PROCS Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 03/17] cgroup: introduce cgroup->proc_cgrp and threaded css_set handling Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 04/17] cgroup: implement CSS_TASK_ITER_THREADED Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 05/17] cgroup: implement cgroup v2 thread support Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 06/17] cgroup: Fix reference counting bug in cgroup_procs_write() Waiman Long
2017-05-17 19:20   ` Tejun Heo
2017-05-15 13:34 ` [RFC PATCH v2 07/17] cgroup: Prevent kill_css() from being called more than once Waiman Long
2017-05-17 19:23   ` Tejun Heo
2017-05-17 20:24     ` Waiman Long
2017-05-17 21:34       ` Tejun Heo
2017-05-15 13:34 ` [RFC PATCH v2 08/17] cgroup: Move debug cgroup to its own file Waiman Long
2017-05-17 21:36   ` Tejun Heo
2017-05-18 15:29     ` Waiman Long
2017-05-18 15:52     ` Waiman Long
2017-05-19 19:21       ` Tejun Heo
2017-05-19 19:33         ` Waiman Long
2017-05-19 20:28           ` Tejun Heo
2017-05-15 13:34 ` [RFC PATCH v2 09/17] cgroup: Keep accurate count of tasks in each css_set Waiman Long
2017-05-17 21:40   ` Tejun Heo
2017-05-18 15:56     ` Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 10/17] cgroup: Make debug cgroup support v2 and thread mode Waiman Long
2017-05-17 21:43   ` Tejun Heo
2017-05-18 15:58     ` Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 11/17] cgroup: Implement new thread mode semantics Waiman Long
2017-05-17 21:47   ` Tejun Heo
2017-05-18 17:21     ` Waiman Long
2017-05-19 20:26   ` Tejun Heo
2017-05-19 20:58     ` Tejun Heo
2017-05-22 17:13     ` Waiman Long
2017-05-22 17:32       ` Waiman Long
2017-05-24 20:36       ` Tejun Heo
2017-05-24 21:17         ` Waiman Long
2017-05-24 21:27           ` Tejun Heo
2017-06-01 14:50             ` Tejun Heo
2017-06-01 15:10               ` Peter Zijlstra
2017-06-01 15:35                 ` Tejun Heo
2017-06-01 18:44                 ` Waiman Long
2017-06-01 18:47                   ` Tejun Heo
2017-06-01 19:27                     ` Waiman Long
2017-06-01 20:38                       ` Tejun Heo
2017-06-01 20:48                         ` Waiman Long
2017-06-01 20:52                           ` Tejun Heo
2017-06-01 21:12                             ` Waiman Long
2017-06-01 21:18                               ` Tejun Heo
2017-06-02 20:36                                 ` Waiman Long
2017-06-03 10:33                                   ` Tejun Heo
2017-06-01 19:55                   ` Waiman Long
2017-06-01 20:15                 ` Waiman Long
2017-06-01 18:41               ` Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 12/17] cgroup: Remove cgroup v2 no internal process constraint Waiman Long
2017-05-19 20:38   ` Tejun Heo
2017-05-20  2:10     ` Mike Galbraith
2017-05-24 17:01       ` Tejun Heo
2017-05-22 16:56     ` Waiman Long
2017-05-24 17:05       ` Tejun Heo
2017-05-24 18:09         ` Waiman Long
2017-05-24 18:19         ` Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 13/17] cgroup: Allow fine-grained controllers control in cgroup v2 Waiman Long
2017-05-19 20:55   ` Tejun Heo
2017-05-19 21:20     ` Waiman Long
2017-05-24 17:31       ` Tejun Heo
2017-05-24 17:49         ` Waiman Long
2017-05-24 17:56           ` Tejun Heo
2017-05-24 18:17             ` Waiman Long
2017-05-15 13:34 ` Waiman Long [this message]
2017-05-15 13:34 ` [RFC PATCH v2 15/17] sched: Misc preps for cgroup unified hierarchy interface Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 16/17] sched: Implement interface for cgroup unified hierarchy Waiman Long
2017-05-15 13:34 ` [RFC PATCH v2 17/17] sched: Make cpu/cpuacct threaded controllers 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=1494855256-12558-15-git-send-email-longman@redhat.com \
    --to=longman@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=efault@gmx.de \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizefan@huawei.com \
    --cc=luto@amacapital.net \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pjt@google.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;
as well as URLs for NNTP newsgroup(s).