lkml.org 
[lkml]   [2022]   [Aug]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC 1/2] cgroup: Introduce per-cgroup resource top show interface
Date
From: Xiu Jianfeng <xiujianfeng@huawei.com>

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@huawei.com>
Co-developed-by: Lu Jialin <lujialin4@huawei.com>
Signed-off-by: Lu Jialin <lujialin4@huawei.com>
---
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
\
 
 \ /
  Last update: 2022-08-26 03:21    [W:0.075 / U:1.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site