[RFC 1/2] cgroup: Introduce per-cgroup resource top show interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Xiu Jianfeng <xiujianfeng@xxxxxxxxxx>

This patch introduces cgroup.top interface for each cgroup. When
accessed by userspace, cgroup.top is able to:
1. Sort cgroups by their usage on various resources(e.g. memory, cpu, etc.)
2. Display resource usage status on all child cgroups.

Signed-off-by: Xiu Jianfeng <xiujianfeng@xxxxxxxxxx>
Co-developed-by: Lu Jialin <lujialin4@xxxxxxxxxx>
Signed-off-by: Lu Jialin <lujialin4@xxxxxxxxxx>
---
 include/linux/cgroup-defs.h |  1 +
 kernel/cgroup/cgroup.c      | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 4bcf56b3491c..ba11e09f8f03 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -651,6 +651,7 @@ struct cgroup_subsys {
 	int (*css_extra_stat_show)(struct seq_file *seq,
 				   struct cgroup_subsys_state *css);
 
+	void (*css_top)(struct cgroup_subsys_state *css, struct seq_file *seq);
 	int (*can_attach)(struct cgroup_taskset *tset);
 	void (*cancel_attach)(struct cgroup_taskset *tset);
 	void (*attach)(struct cgroup_taskset *tset);
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index ffaccd6373f1..01bd1a734a01 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3867,6 +3867,22 @@ static ssize_t cgroup_kill_write(struct kernfs_open_file *of, char *buf,
 	return ret ?: nbytes;
 }
 
+static int cgroup_top_show(struct seq_file *seq, void *v)
+{
+	struct cgroup *cgrp = seq_css(seq)->cgroup;
+	struct cgroup_subsys_state *css;
+	int ssid;
+
+	rcu_read_lock();
+	for_each_css(css, ssid, cgrp) {
+		if (css->ss->css_top)
+			css->ss->css_top(css, seq);
+	}
+	rcu_read_unlock();
+
+	return 0;
+}
+
 static int cgroup_file_open(struct kernfs_open_file *of)
 {
 	struct cftype *cft = of_cft(of);
@@ -5125,6 +5141,10 @@ static struct cftype cgroup_base_files[] = {
 		.release = cgroup_pressure_release,
 	},
 #endif /* CONFIG_PSI */
+	{
+		.name = "cgroup.top",
+		.seq_show = cgroup_top_show,
+	},
 	{ }	/* terminate */
 };
 
-- 
2.17.1




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [Monitors]

  Powered by Linux