cgroup: remove synchronize_rcu() from cgroup_diput()

Free cgroup via call_rcu(). The actual work is done through
workqueue.

Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Li Zefan 2013-01-24 14:31:42 +08:00 committed by Tejun Heo
parent 86a3db5643
commit be44562613
2 changed files with 44 additions and 29 deletions

View File

@ -203,6 +203,7 @@ struct cgroup {
/* For RCU-protected deletion */ /* For RCU-protected deletion */
struct rcu_head rcu_head; struct rcu_head rcu_head;
struct work_struct free_work;
/* List of events which userspace want to receive */ /* List of events which userspace want to receive */
struct list_head event_list; struct list_head event_list;

View File

@ -852,20 +852,10 @@ static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb)
return inode; return inode;
} }
static void cgroup_diput(struct dentry *dentry, struct inode *inode) static void cgroup_free_fn(struct work_struct *work)
{ {
/* is dentry a directory ? if so, kfree() associated cgroup */ struct cgroup *cgrp = container_of(work, struct cgroup, free_work);
if (S_ISDIR(inode->i_mode)) {
struct cgroup *cgrp = dentry->d_fsdata;
struct cgroup_subsys *ss; struct cgroup_subsys *ss;
BUG_ON(!(cgroup_is_removed(cgrp)));
/* It's possible for external users to be holding css
* reference counts on a cgroup; css_put() needs to
* be able to access the cgroup after decrementing
* the reference count in order to know if it needs to
* queue the cgroup to be handled by the release
* agent */
synchronize_rcu();
mutex_lock(&cgroup_mutex); mutex_lock(&cgroup_mutex);
/* /*
@ -893,6 +883,29 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id); ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id);
kfree(cgrp); kfree(cgrp);
}
static void cgroup_free_rcu(struct rcu_head *head)
{
struct cgroup *cgrp = container_of(head, struct cgroup, rcu_head);
schedule_work(&cgrp->free_work);
}
static void cgroup_diput(struct dentry *dentry, struct inode *inode)
{
/* is dentry a directory ? if so, kfree() associated cgroup */
if (S_ISDIR(inode->i_mode)) {
struct cgroup *cgrp = dentry->d_fsdata;
BUG_ON(!(cgroup_is_removed(cgrp)));
/* It's possible for external users to be holding css
* reference counts on a cgroup; css_put() needs to
* be able to access the cgroup after decrementing
* the reference count in order to know if it needs to
* queue the cgroup to be handled by the release
* agent */
call_rcu(&cgrp->rcu_head, cgroup_free_rcu);
} else { } else {
struct cfent *cfe = __d_cfe(dentry); struct cfent *cfe = __d_cfe(dentry);
struct cgroup *cgrp = dentry->d_parent->d_fsdata; struct cgroup *cgrp = dentry->d_parent->d_fsdata;
@ -1391,6 +1404,7 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp)
INIT_LIST_HEAD(&cgrp->allcg_node); INIT_LIST_HEAD(&cgrp->allcg_node);
INIT_LIST_HEAD(&cgrp->release_list); INIT_LIST_HEAD(&cgrp->release_list);
INIT_LIST_HEAD(&cgrp->pidlists); INIT_LIST_HEAD(&cgrp->pidlists);
INIT_WORK(&cgrp->free_work, cgroup_free_fn);
mutex_init(&cgrp->pidlist_mutex); mutex_init(&cgrp->pidlist_mutex);
INIT_LIST_HEAD(&cgrp->event_list); INIT_LIST_HEAD(&cgrp->event_list);
spin_lock_init(&cgrp->event_list_lock); spin_lock_init(&cgrp->event_list_lock);