linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mmotm 1/2] cgroup: fix to stop adding a new task while rmdir going on
@ 2008-12-10  4:35 KAMEZAWA Hiroyuki
  2008-12-10  4:45 ` [PATCH mmotm 2/2] cgroup: add CSS_POPULATED flag to show css is in use KAMEZAWA Hiroyuki
  2008-12-10 22:48 ` [PATCH mmotm 1/2] cgroup: fix to stop adding a new task while rmdir going on Paul Menage
  0 siblings, 2 replies; 4+ messages in thread
From: KAMEZAWA Hiroyuki @ 2008-12-10  4:35 UTC (permalink / raw)
  To: linux-mm; +Cc: lizf, nishimura, menage, balbir, akpm

still need reviews.
==
Recently, pre_destroy() was moved to out of cgroup_lock() for avoiding
dead lock. But, by this, serialization between task attach and rmdir()
is lost.

This adds CGRP_TRY_REMOVE flag to cgroup and check it at attaching.
If attach_pid founds CGRP_TRY_REMOVE, it returns -EBUSY.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>


---
 include/linux/cgroup.h |    2 ++
 kernel/cgroup.c        |   11 +++++++++++
 2 files changed, 13 insertions(+)

Index: mmotm-2.6.28-Dec09/include/linux/cgroup.h
===================================================================
--- mmotm-2.6.28-Dec09.orig/include/linux/cgroup.h
+++ mmotm-2.6.28-Dec09/include/linux/cgroup.h
@@ -98,6 +98,8 @@ enum {
 	CGRP_RELEASABLE,
 	/* Control Group requires release notifications to userspace */
 	CGRP_NOTIFY_ON_RELEASE,
+	/* Control Group is in rmdir() sequence. stop adding new tasks */
+	CGRP_TRY_REMOVE,
 };
 
 struct cgroup {
Index: mmotm-2.6.28-Dec09/kernel/cgroup.c
===================================================================
--- mmotm-2.6.28-Dec09.orig/kernel/cgroup.c
+++ mmotm-2.6.28-Dec09/kernel/cgroup.c
@@ -122,6 +122,11 @@ inline int cgroup_is_removed(const struc
 {
 	return test_bit(CGRP_REMOVED, &cgrp->flags);
 }
+/* cgroup is in rmdir() sequnece */
+static inline int cgroup_is_being_removed(const struct cgroup *cgrp)
+{
+	return test_bit(CGRP_TRY_REMOVE, &cgrp->flags);
+}
 
 /* bits in struct cgroupfs_root flags field */
 enum {
@@ -1307,6 +1312,10 @@ static int cgroup_tasks_write(struct cgr
 	int ret;
 	if (!cgroup_lock_live_group(cgrp))
 		return -ENODEV;
+	if (cgroup_is_being_removed(cgrp)) {
+		cgroup_unlock();
+		return -EBUSY;
+	}
 	ret = attach_task_by_pid(cgrp, pid);
 	cgroup_unlock();
 	return ret;
@@ -2469,6 +2478,7 @@ static int cgroup_rmdir(struct inode *un
 		mutex_unlock(&cgroup_mutex);
 		return -EBUSY;
 	}
+	set_bit(CGRP_TRY_REMOVE, &cgrp->flags);
 	mutex_unlock(&cgroup_mutex);
 
 	/*
@@ -2483,6 +2493,7 @@ static int cgroup_rmdir(struct inode *un
 	if (atomic_read(&cgrp->count)
 	    || !list_empty(&cgrp->children)
 	    || cgroup_has_css_refs(cgrp)) {
+		clear_bit(CGRP_TRY_REMOVE, &cgrp->flags);
 		mutex_unlock(&cgroup_mutex);
 		return -EBUSY;
 	}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-11  0:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-10  4:35 [PATCH mmotm 1/2] cgroup: fix to stop adding a new task while rmdir going on KAMEZAWA Hiroyuki
2008-12-10  4:45 ` [PATCH mmotm 2/2] cgroup: add CSS_POPULATED flag to show css is in use KAMEZAWA Hiroyuki
2008-12-10 22:48 ` [PATCH mmotm 1/2] cgroup: fix to stop adding a new task while rmdir going on Paul Menage
2008-12-11  0:26   ` KAMEZAWA Hiroyuki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox