From: Aleksa Sarai <asarai@suse.de>
To: Jonathan Corbet <corbet@lwn.net>, Tejun Heo <tj@kernel.org>,
Li Zefan <lizefan@huawei.com>,
Johannes Weiner <hannes@cmpxchg.org>, Kenny Yu <kennyyu@fb.com>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, Aleksa Sarai <asarai@suse.de>
Subject: [PATCH 1/2] cgroup: pids: show number of failed forks since limit reset
Date: Fri, 24 Jun 2016 13:00:48 +1000 [thread overview]
Message-ID: <20160624030049.13341-2-asarai@suse.de> (raw)
In-Reply-To: <20160624030049.13341-1-asarai@suse.de>
This allows users to dynamically adjust their limits based on how many
failed forks happened since they last reset their limits, otherwise they
would have to track (in a racy way) how many limit failures there were
since the last limit change manually. In addition, we log the first
failure since the limit was reset (which was the original semantics of
the patchset).
In addition, I clarified the licensing for this file.
Signed-off-by: Aleksa Sarai <asarai@suse.de>
---
kernel/cgroup_pids.c | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/kernel/cgroup_pids.c b/kernel/cgroup_pids.c
index 2bd673783f1a..54ec3e4f3b71 100644
--- a/kernel/cgroup_pids.c
+++ b/kernel/cgroup_pids.c
@@ -26,9 +26,10 @@
*
* Copyright (C) 2015 Aleksa Sarai <cyphar@cyphar.com>
*
- * This file is subject to the terms and conditions of version 2 of the GNU
- * General Public License. See the file COPYING in the main directory of the
- * Linux distribution for more details.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
*/
#include <linux/kernel.h>
@@ -53,8 +54,11 @@ struct pids_cgroup {
/* Handle for "pids.events" */
struct cgroup_file events_file;
- /* Number of times fork failed because limit was hit. */
- atomic64_t events_limit;
+ /* Total number of times fork failed because limit was hit. */
+ atomic64_t hits_total;
+
+ /* Number of times fork failed since limit was last set. */
+ atomic64_t hits_since;
};
static struct pids_cgroup *css_pids(struct cgroup_subsys_state *css)
@@ -78,7 +82,8 @@ pids_css_alloc(struct cgroup_subsys_state *parent)
pids->limit = PIDS_MAX;
atomic64_set(&pids->counter, 0);
- atomic64_set(&pids->events_limit, 0);
+ atomic64_set(&pids->hits_total, 0);
+ atomic64_set(&pids->hits_since, 0);
return &pids->css;
}
@@ -226,8 +231,12 @@ static int pids_can_fork(struct task_struct *task)
pids = css_pids(css);
err = pids_try_charge(pids, 1);
if (err) {
- /* Only log the first time events_limit is incremented. */
- if (atomic64_inc_return(&pids->events_limit) == 1) {
+ /*
+ * We only log the first time a fork fails after a limit has
+ * been set. Resetting the limit will cause us to log again.
+ */
+ atomic64_inc(&pids->hits_total);
+ if (atomic64_inc_return(&pids->hits_since) == 1) {
pr_info("cgroup: fork rejected by pids controller in ");
pr_cont_cgroup_path(task_cgroup(current, pids_cgrp_id));
pr_cont("\n");
@@ -281,6 +290,9 @@ set_limit:
* critical that any racing fork()s follow the new limit.
*/
pids->limit = limit;
+ /* Reset the since counter and notify userspace. */
+ atomic64_set(&pids->hits_since, 0);
+ cgroup_file_notify(&pids->events_file);
return nbytes;
}
@@ -310,7 +322,8 @@ static int pids_events_show(struct seq_file *sf, void *v)
{
struct pids_cgroup *pids = css_pids(seq_css(sf));
- seq_printf(sf, "max %lld\n", (s64)atomic64_read(&pids->events_limit));
+ seq_printf(sf, "since\t%lld\n", (s64)atomic64_read(&pids->hits_since));
+ seq_printf(sf, "total\t%lld\n", (s64)atomic64_read(&pids->hits_total));
return 0;
}
--
2.8.4
next prev parent reply other threads:[~2016-06-24 3:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 3:00 [PATCH 0/2] cgroup: pids: extend pids.events Aleksa Sarai
2016-06-24 3:00 ` Aleksa Sarai [this message]
2016-06-24 3:00 ` [PATCH 2/2] docs: cgroup/pids: update documentation to include pids.events Aleksa Sarai
2016-06-24 15:31 ` [PATCH 1/2] cgroup: pids: show number of failed forks since limit reset Tejun Heo
[not found] ` <20160624153151.GQ3262-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2016-06-26 11:34 ` Aleksa Sarai
2016-06-26 23:42 ` Tejun Heo
2016-06-29 5:10 ` Aleksa Sarai
[not found] ` <ec289e47-9761-ff21-b264-1391aa22cfd4-l3A5Bk7waGM@public.gmane.org>
2016-06-29 15:33 ` Tejun Heo
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=20160624030049.13341-2-asarai@suse.de \
--to=asarai@suse.de \
--cc=cgroups@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=hannes@cmpxchg.org \
--cc=kennyyu@fb.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=tj@kernel.org \
/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