From: Tejun Heo <tj@kernel.org>
To: lizefan@huawei.com, hannes@cmpxchg.org
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@fb.com, Tejun Heo <tj@kernel.org>
Subject: [PATCH 08/12] cgroup: factor out cgroup_apply_control_enable() from cgroup_subtree_control_write()
Date: Mon, 22 Feb 2016 22:45:42 -0500 [thread overview]
Message-ID: <1456199146-14765-9-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1456199146-14765-1-git-send-email-tj@kernel.org>
Factor out css enabling and showing into cgroup_apply_control_enable().
* Nest subsystem walk inside child walk. The child walk will later be
converted to subtree walk which is a bit more expensive.
* Instead of operating on the differential masks @css_enable, simply
enable or show csses according to the current cgroup_control() and
cgroup_ss_mask(). This leads to the same result and is simpler and
more robust.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
kernel/cgroup.c | 77 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 47 insertions(+), 30 deletions(-)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index da178ed..5a5cb52 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3008,6 +3008,49 @@ static bool cgroup_drain_offline(struct cgroup *cgrp)
}
/**
+ * cgroup_apply_control_enable - enable or show csses according to control
+ * @cgrp: parent of the target cgroups
+ *
+ * Walk @cgrp's children and create new csses or make the existing ones
+ * visible. A css is created invisible if it's being implicitly enabled
+ * through dependency. An invisible css is made visible when the userland
+ * explicitly enables it.
+ *
+ * Returns 0 on success, -errno on failure. On failure, csses which have
+ * been processed already aren't cleaned up. The caller is responsible for
+ * cleaning up with cgroup_apply_control_disble().
+ */
+static int cgroup_apply_control_enable(struct cgroup *cgrp)
+{
+ struct cgroup *dsct;
+ struct cgroup_subsys *ss;
+ int ssid, ret;
+
+ cgroup_for_each_live_child(dsct, cgrp) {
+ for_each_subsys(ss, ssid) {
+ struct cgroup_subsys_state *css = cgroup_css(dsct, ss);
+
+ if (!(cgroup_ss_mask(dsct) & (1 << ss->id)))
+ continue;
+
+ if (!css) {
+ css = css_create(dsct, ss);
+ if (IS_ERR(css))
+ return PTR_ERR(css);
+ }
+
+ if (cgroup_control(dsct) & (1 << ss->id)) {
+ ret = css_populate_dir(css, NULL);
+ if (ret)
+ return ret;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/**
* cgroup_apply_control_disable - kill or hide csses according to control
* @cgrp: parent of the target cgroups
*
@@ -3155,36 +3198,10 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
cgrp->subtree_control = new_sc;
cgrp->subtree_ss_mask = new_ss;
- /*
- * Create new csses or make the existing ones visible. A css is
- * created invisible if it's being implicitly enabled through
- * dependency. An invisible css is made visible when the userland
- * explicitly enables it.
- */
- do_each_subsys_mask(ss, ssid, enable) {
- cgroup_for_each_live_child(child, cgrp) {
- if (css_enable & (1 << ssid)) {
- struct cgroup_subsys_state *css;
-
- css = css_create(child, ss);
- if (IS_ERR(css)) {
- ret = PTR_ERR(css);
- goto err_undo_css;
- }
-
- if (cgrp->subtree_control & (1 << ssid)) {
- ret = css_populate_dir(css, NULL);
- if (ret)
- goto err_undo_css;
- }
- } else {
- ret = css_populate_dir(cgroup_css(child, ss),
- NULL);
- if (ret)
- goto err_undo_css;
- }
- }
- } while_each_subsys_mask();
+ /* prepare csses */
+ ret = cgroup_apply_control_enable(cgrp);
+ if (ret)
+ goto err_undo_css;
/*
* At this point, cgroup_e_css() results reflect the new csses
--
2.5.0
next prev parent reply other threads:[~2016-02-23 3:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-23 3:45 [PATCHSET cgroup/for-4.6] cgroup: make control mask updates modular and recursive Tejun Heo
2016-02-23 3:45 ` [PATCH 01/12] cgroup: separate out interface file creation from css creation Tejun Heo
2016-02-23 3:45 ` [PATCH 02/12] cgroup: explicitly track whether a cgroup_subsys_state is visible to userland Tejun Heo
2016-02-23 3:45 ` [PATCH 03/12] cgroup: reorder operations in cgroup_mkdir() Tejun Heo
2016-02-23 3:45 ` [PATCH 04/12] cgroup: factor out cgroup_create() out of cgroup_mkdir() Tejun Heo
2016-02-23 3:45 ` [PATCH 05/12] cgroup: introduce cgroup_control() and cgroup_ss_mask() Tejun Heo
2016-02-23 3:45 ` [PATCH 06/12] cgroup: factor out cgroup_drain_offline() from cgroup_subtree_control_write() Tejun Heo
2016-02-23 3:45 ` [PATCH 07/12] cgroup: factor out cgroup_apply_control_disable() " Tejun Heo
2016-02-23 3:45 ` Tejun Heo [this message]
2016-02-23 3:45 ` [PATCH 09/12] cgroup: make cgroup_drain_offline() and cgroup_apply_control_{disable|enable}() recursive Tejun Heo
2016-02-23 3:45 ` [PATCH 10/12] cgroup: introduce cgroup_{save|propagate|restore}_control() Tejun Heo
2016-02-23 3:45 ` [PATCH 11/12] cgroup: Factor out cgroup_{apply|finalize}_control() from cgroup_subtree_control_write() Tejun Heo
2016-02-23 3:45 ` [PATCH 12/12] cgroup: make cgroup_calc_subtree_ss_mask() take @this_ss_mask 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=1456199146-14765-9-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@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;
as well as URLs for NNTP newsgroup(s).