From: brookxu <brookxu.cn@gmail.com>
To: viro@zeniv.linux.org.uk, tj@kernel.org, lizefan.x@bytedance.com,
hannes@cmpxchg.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
cgroups@vger.kernel.org
Subject: [RFC PATCH 2/3] misc_cgroup: add failcnt counter
Date: Thu, 22 Jul 2021 17:38:39 +0800 [thread overview]
Message-ID: <cba4e118c342f55097c1fa5c255b26bfb2609590.1626946231.git.brookxu@tencent.com> (raw)
In-Reply-To: <4775e8d187920399403b296f8bb11bd687688671.1626946231.git.brookxu@tencent.com>
In-Reply-To: <4775e8d187920399403b296f8bb11bd687688671.1626946231.git.brookxu@tencent.com>
From: Chunguang Xu <brookxu@tencent.com>
Instead of printing logs, we should probably track failures through
a failcnt counter, similar to mem_cgroup.
Signed-off-by: Chunguang Xu <brookxu@tencent.com>
---
include/linux/misc_cgroup.h | 1 +
kernel/cgroup/misc.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index 8450a5e66de0..dd1a786f39b8 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -37,6 +37,7 @@ struct misc_cg;
struct misc_res {
unsigned long max;
atomic_long_t usage;
+ atomic_long_t failcnt;
bool failed;
};
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index 5d51b8eeece6..7c568b619f82 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -165,6 +165,7 @@ int misc_cg_try_charge(enum misc_res_type type, struct misc_cg *cg,
pr_cont("\n");
res->failed = true;
}
+ atomic_long_inc(&res->failcnt);
ret = -EBUSY;
goto err_charge;
}
@@ -312,6 +313,29 @@ static int misc_cg_current_show(struct seq_file *sf, void *v)
return 0;
}
+/**
+ * misc_cg_failcnt_show() - Show the fail count of the misc cgroup.
+ * @sf: Interface file
+ * @v: Arguments passed
+ *
+ * Context: Any context.
+ * Return: 0 to denote successful print.
+ */
+static int misc_cg_failcnt_show(struct seq_file *sf, void *v)
+{
+ int i;
+ unsigned long failcnt;
+ struct misc_cg *cg = css_misc(seq_css(sf));
+
+ for (i = 0; i < MISC_CG_RES_TYPES; i++) {
+ failcnt = atomic_long_read(&cg->res[i].failcnt);
+ if (READ_ONCE(misc_res_capacity[i]) || failcnt)
+ seq_printf(sf, "%s %lu\n", misc_res_name[i], failcnt);
+ }
+
+ return 0;
+}
+
/**
* misc_cg_capacity_show() - Show the total capacity of misc res on the host.
* @sf: Interface file
@@ -349,6 +373,11 @@ static struct cftype misc_cg_files[] = {
.seq_show = misc_cg_current_show,
.flags = CFTYPE_NOT_ON_ROOT,
},
+ {
+ .name = "failcnt",
+ .seq_show = misc_cg_failcnt_show,
+ .flags = CFTYPE_NOT_ON_ROOT,
+ },
{
.name = "capacity",
.seq_show = misc_cg_capacity_show,
@@ -383,6 +412,7 @@ misc_cg_alloc(struct cgroup_subsys_state *parent_css)
for (i = 0; i < MISC_CG_RES_TYPES; i++) {
WRITE_ONCE(cg->res[i].max, MAX_NUM);
atomic_long_set(&cg->res[i].usage, 0);
+ atomic_long_set(&cg->res[i].failcnt, 0);
}
return &cg->css;
--
2.30.0
next prev parent reply other threads:[~2021-07-22 9:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-22 9:38 [RFC PATCH 1/3] misc_cgroup: add support for nofile limit brookxu
2021-07-22 9:38 ` brookxu [this message]
2021-07-22 9:38 ` [RFC PATCH 3/3] misc_cgroup: delete failed logs to avoid log flooding brookxu
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=cba4e118c342f55097c1fa5c255b26bfb2609590.1626946231.git.brookxu@tencent.com \
--to=brookxu.cn@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).