aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>2008-02-07 03:14:27 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-07 11:42:20 -0500
commit4fca88c87b7969c698912e2de9b1b31088c777cb (patch)
tree6a086aaffb4ec17eadd2f2427c5816a02be6606f
parentd2ceb9b7ddedbb2e8e590bc6ce33c854043016f9 (diff)
memory cgroup enhancements: add- pre_destroy() handler
Add a handler "pre_destroy" to cgroup_subsys. It is called before cgroup_rmdir() checks all subsys's refcnt. I think this is useful for subsys which have some extra refs even if there are no tasks in cgroup. By adding pre_destroy(), the kernel keeps the rule "destroy() against subsystem is called only when refcnt=0." and allows css ref to be used by other objects than tasks. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Balbir Singh <balbir@linux.vnet.ibm.com> Cc: David Rientjes <rientjes@google.com> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: Kirill Korotaev <dev@sw.ru> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Cc: Paul Menage <menage@google.com> Cc: Pavel Emelianov <xemul@openvz.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/cgroup.h1
-rw-r--r--kernel/cgroup.c22
2 files changed, 23 insertions, 0 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 87479328d46d..d8e92223a79c 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -233,6 +233,7 @@ int cgroup_is_descendant(const struct cgroup *cont);
233struct cgroup_subsys { 233struct cgroup_subsys {
234 struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss, 234 struct cgroup_subsys_state *(*create)(struct cgroup_subsys *ss,
235 struct cgroup *cont); 235 struct cgroup *cont);
236 void (*pre_destroy)(struct cgroup_subsys *ss, struct cgroup *cont);
236 void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cont); 237 void (*destroy)(struct cgroup_subsys *ss, struct cgroup *cont);
237 int (*can_attach)(struct cgroup_subsys *ss, 238 int (*can_attach)(struct cgroup_subsys *ss,
238 struct cgroup *cont, struct task_struct *tsk); 239 struct cgroup *cont, struct task_struct *tsk);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 4d67a39c58a8..4e8b16a8266c 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -586,6 +586,21 @@ static struct inode *cgroup_new_inode(mode_t mode, struct super_block *sb)
586 return inode; 586 return inode;
587} 587}
588 588
589/*
590 * Call subsys's pre_destroy handler.
591 * This is called before css refcnt check.
592 */
593
594static void cgroup_call_pre_destroy(struct cgroup *cgrp)
595{
596 struct cgroup_subsys *ss;
597 for_each_subsys(cgrp->root, ss)
598 if (ss->pre_destroy && cgrp->subsys[ss->subsys_id])
599 ss->pre_destroy(ss, cgrp);
600 return;
601}
602
603
589static void cgroup_diput(struct dentry *dentry, struct inode *inode) 604static void cgroup_diput(struct dentry *dentry, struct inode *inode)
590{ 605{
591 /* is dentry a directory ? if so, kfree() associated cgroup */ 606 /* is dentry a directory ? if so, kfree() associated cgroup */
@@ -2160,6 +2175,13 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
2160 parent = cgrp->parent; 2175 parent = cgrp->parent;
2161 root = cgrp->root; 2176 root = cgrp->root;
2162 sb = root->sb; 2177 sb = root->sb;
2178 /*
2179 * Call pre_destroy handlers of subsys
2180 */
2181 cgroup_call_pre_destroy(cgrp);
2182 /*
2183 * Notify subsyses that rmdir() request comes.
2184 */
2163 2185
2164 if (cgroup_has_css_refs(cgrp)) { 2186 if (cgroup_has_css_refs(cgrp)) {
2165 mutex_unlock(&cgroup_mutex); 2187 mutex_unlock(&cgroup_mutex);