From: Tejun Heo <tj@kernel.org>
To: lizefan@huawei.com
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
hannes@cmpxchg.org, mhocko@suse.cz, nasa4836@gmail.com,
Tejun Heo <tj@kernel.org>
Subject: [PATCH 4/6] cgroup: use RCU free in create_css() failure path
Date: Thu, 24 Apr 2014 17:02:11 -0400 [thread overview]
Message-ID: <1398373333-1521-5-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1398373333-1521-1-git-send-email-tj@kernel.org>
Currently, when create_css() fails in the middle, the half-initialized
css is freed by invoking cgroup_subsys->css_free() directly. This
patch updates the function so that it invokes RCU free path instead.
As the RCU free path puts the parent css and owning cgroup, their
references are now acquired right after a new css is successfully
allocated.
This doesn't make any visible difference now but is to enable
implementing css->id and RCU protected lookup by such IDs.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
kernel/cgroup.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 7cb9c08..0e2c401 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4185,12 +4185,14 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
if (IS_ERR(css))
return PTR_ERR(css);
+ init_css(css, ss, cgrp);
+ cgroup_get(cgrp);
+ css_get(css->parent);
+
err = percpu_ref_init(&css->refcnt, css_release);
if (err)
goto err_free_css;
- init_css(css, ss, cgrp);
-
err = cgroup_populate_dir(cgrp, 1 << ss->id);
if (err)
goto err_free_percpu_ref;
@@ -4199,9 +4201,6 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss)
if (err)
goto err_clear_dir;
- cgroup_get(cgrp);
- css_get(css->parent);
-
if (ss->broken_hierarchy && !ss->warned_broken_hierarchy &&
parent->parent) {
pr_warn("%s (%d) created nested cgroup for controller \"%s\" which has incomplete hierarchy support. Nested cgroups may change behavior in the future.\n",
@@ -4218,7 +4217,7 @@ err_clear_dir:
err_free_percpu_ref:
percpu_ref_cancel_init(&css->refcnt);
err_free_css:
- ss->css_free(css);
+ call_rcu(&css->rcu_head, css_free_rcu_fn);
return err;
}
--
1.9.0
next prev parent reply other threads:[~2014-04-24 21:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-24 21:02 [PATCHSET cgroup/for-3.16] cgroup: implement css->id Tejun Heo
2014-04-24 21:02 ` [PATCH 1/6] cgroup: make flags and subsys_masks unsigned int Tejun Heo
2014-04-24 21:02 ` [PATCH 2/6] cgroup, memcg: allocate cgroup ID from 1 Tejun Heo
2014-04-30 13:11 ` Michal Hocko
2014-04-24 21:02 ` [PATCH 3/6] cgroup: protect cgroup_root->cgroup_idr with a spinlock Tejun Heo
2014-04-24 21:02 ` Tejun Heo [this message]
2014-04-24 21:02 ` [PATCH 5/6] cgroup: update init_css() into init_and_link_css() Tejun Heo
2014-04-24 21:02 ` [PATCH 6/6] cgroup, memcg: implement css->id and convert css_from_id() to use it Tejun Heo
2014-04-28 3:33 ` Li Zefan
2014-05-01 15:46 ` Tejun Heo
2014-05-04 6:02 ` Li Zefan
2014-04-30 13:24 ` Michal Hocko
2014-05-04 6:08 ` [PATCHSET cgroup/for-3.16] cgroup: implement css->id Li Zefan
2014-05-04 19:18 ` 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=1398373333-1521-5-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mhocko@suse.cz \
--cc=nasa4836@gmail.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).