linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 1/3] misc_cgroup: introduce misc.events and misc_events.local
@ 2021-09-08  5:24 brookxu
  2021-09-08  5:24 ` [RFC PATCH 2/3] misc_cgroup: introduce misc.failcnt for V1 brookxu
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: brookxu @ 2021-09-08  5:24 UTC (permalink / raw)
  To: tj, lizefan.x, hannes; +Cc: vipinsh, mkoutny, linux-kernel, cgroups

From: Chunguang Xu <brookxu@tencent.com>

Introduce misc.events and misc.events.local to make it easier for
us to understand the pressure of resources. The main idea comes
from mem_cgroup.

Signed-off-by: Chunguang Xu <brookxu@tencent.com>
---
 include/linux/misc_cgroup.h |  9 +++++++
 kernel/cgroup/misc.c        | 50 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index da2367e2ac1e..d29f1743fae9 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -46,6 +46,15 @@ struct misc_res {
  */
 struct misc_cg {
 	struct cgroup_subsys_state css;
+
+	/* misc.events */
+	atomic_long_t events[MISC_CG_RES_TYPES];
+	struct cgroup_file events_file;
+
+	/* misc.events.local */
+	atomic_long_t events_local[MISC_CG_RES_TYPES];
+	struct cgroup_file events_local_file;
+
 	struct misc_res res[MISC_CG_RES_TYPES];
 };
 
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index ec02d963cad1..2a3d14be21e5 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -140,7 +140,7 @@ static void misc_cg_cancel_charge(enum misc_res_type type, struct misc_cg *cg,
 int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
 		       unsigned long amount)
 {
-	struct misc_cg *i, *j;
+	struct misc_cg *i, *j, *k;
 	int ret;
 	struct misc_res *res;
 	int new_usage;
@@ -171,6 +171,16 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
 	return 0;
 
 err_charge:
+	if (cgroup_subsys_on_dfl(misc_cgrp_subsys)) {
+		atomic_long_inc(&i->events_local[type]);
+		cgroup_file_notify(&i->events_local_file);
+
+		for (k = i; k; k = parent_misc(k)) {
+			atomic_long_inc(&k->events[type]);
+			cgroup_file_notify(&k->events_file);
+		}
+	}
+
 	for (j = cg; j != i; j = parent_misc(j))
 		misc_cg_cancel_charge(type, j, amount);
 	misc_cg_cancel_charge(type, i, amount);
@@ -335,6 +345,32 @@ static int misc_cg_capacity_show(struct seq_file *sf, void *v)
 	return 0;
 }
 
+static int misc_events_show(struct seq_file *sf, void *v)
+{
+	struct misc_cg *cg = css_misc(seq_css(sf));
+	unsigned long count, i;
+
+	for (i = 0; i < MISC_CG_RES_TYPES; i++) {
+		count = atomic_long_read(&cg->events[i]);
+		if (READ_ONCE(misc_res_capacity[i]) || count)
+			seq_printf(sf, "%s %lu\n", misc_res_name[i], count);
+	}
+	return 0;
+}
+
+static int misc_events_local_show(struct seq_file *sf, void *v)
+{
+	struct misc_cg *cg = css_misc(seq_css(sf));
+	unsigned long count, i;
+
+	for (i = 0; i < MISC_CG_RES_TYPES; i++) {
+		count = atomic_long_read(&cg->events_local[i]);
+		if (READ_ONCE(misc_res_capacity[i]) || count)
+			seq_printf(sf, "%s %lu\n", misc_res_name[i], count);
+	}
+	return 0;
+}
+
 /* Misc cgroup interface files */
 static struct cftype misc_cg_files[] = {
 	{
@@ -353,6 +389,18 @@ static struct cftype misc_cg_files[] = {
 		.seq_show = misc_cg_capacity_show,
 		.flags = CFTYPE_ONLY_ON_ROOT,
 	},
+	{
+		.name = "events",
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.file_offset = offsetof(struct misc_cg, events_file),
+		.seq_show = misc_events_show,
+	},
+	{
+		.name = "events.local",
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.file_offset = offsetof(struct misc_cg, events_local_file),
+		.seq_show = misc_events_local_show,
+	},
 	{}
 };
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-09-10 17:37 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08  5:24 [RFC PATCH 1/3] misc_cgroup: introduce misc.events and misc_events.local brookxu
2021-09-08  5:24 ` [RFC PATCH 2/3] misc_cgroup: introduce misc.failcnt for V1 brookxu
2021-09-09 14:37   ` Michal Koutný
2021-09-08  5:24 ` [RFC PATCH 3/3] misc_cgroup: remove error log to avoid log flood brookxu
2021-09-09 14:37   ` Michal Koutný
2021-09-09 16:49     ` Vipin Sharma
2021-09-09 18:56       ` Michal Koutný
2021-09-10  5:30         ` brookxu
2021-09-10  9:23           ` Michal Koutný
2021-09-10 14:29             ` brookxu.cn
2021-09-10 15:36               ` Michal Koutný
2021-09-10 16:29                 ` Tejun Heo
2021-09-10 17:16                   ` Vipin Sharma
2021-09-10 17:19                     ` Tejun Heo
2021-09-10 17:31                       ` Vipin Sharma
2021-09-10 17:37                         ` Tejun Heo
2021-09-09 14:37 ` [RFC PATCH 1/3] misc_cgroup: introduce misc.events and misc_events.local Michal Koutný
2021-09-09 17:08   ` Vipin Sharma
2021-09-10  5:20     ` brookxu
2021-09-10 10:33       ` Michal Koutný
2021-09-10 16:32         ` Tejun Heo
2021-09-09 16:56 ` Vipin Sharma
2021-09-10  5:21   ` brookxu

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).