From: Lu Jialin <lujialin4@huawei.com>
To: Zefan Li <lizefan.x@bytedance.com>, Tejun Heo <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeelb@google.com>,
Muchun Song <songmuchun@bytedance.com>
Cc: Lu Jialin <lujialin4@huawei.com>,
Xiu Jianfeng <xiujianfeng@huawei.com>, <cgroups@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Subject: [RFC 1/2] cgroup: Introduce per-cgroup resource top show interface
Date: Fri, 26 Aug 2022 09:15:02 +0800 [thread overview]
Message-ID: <20220826011503.103894-2-lujialin4@huawei.com> (raw)
In-Reply-To: <20220826011503.103894-1-lujialin4@huawei.com>
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
next prev parent reply other threads:[~2022-08-26 1:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 1:15 [RFC 0/2] Introduce cgroup.top interface Lu Jialin
2022-08-26 1:15 ` Lu Jialin [this message]
2022-08-26 1:15 ` [RFC 2/2] memcg: Adapt cgroup.top into per-memcg Lu Jialin
2022-08-26 7:38 ` Michal Hocko
2022-08-26 3:17 ` [RFC 0/2] Introduce cgroup.top interface Tejun Heo
2022-08-26 9:50 ` lujialin (A)
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=20220826011503.103894-2-lujialin4@huawei.com \
--to=lujialin4@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=mhocko@kernel.org \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.com \
--cc=songmuchun@bytedance.com \
--cc=tj@kernel.org \
--cc=xiujianfeng@huawei.com \
/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