diff options
author | Paul Menage <menage@google.com> | 2009-01-07 21:08:36 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-08 11:31:10 -0500 |
commit | 999cd8a450f8f93701669a61cac4d3b19eca07e8 (patch) | |
tree | 990e5b08e6db971d2e9943f89abf39e7c8f4cb1e /include/linux/cgroup.h | |
parent | b5a84319a4343a0db753436fd8147e61eaafa7ea (diff) |
cgroups: add a per-subsystem hierarchy_mutex
These patches introduce new locking/refcount support for cgroups to
reduce the need for subsystems to call cgroup_lock(). This will
ultimately allow the atomicity of cgroup_rmdir() (which was removed
recently) to be restored.
These three patches give:
1/3 - introduce a per-subsystem hierarchy_mutex which a subsystem can
use to prevent changes to its own cgroup tree
2/3 - use hierarchy_mutex in place of calling cgroup_lock() in the
memory controller
3/3 - introduce a css_tryget() function similar to the one recently
proposed by Kamezawa, but avoiding spurious refcount failures in
the event of a race between a css_tryget() and an unsuccessful
cgroup_rmdir()
Future patches will likely involve:
- using hierarchy mutex in place of cgroup_lock() in more subsystems
where appropriate
- restoring the atomicity of cgroup_rmdir() with respect to cgroup_create()
This patch:
Add a hierarchy_mutex to the cgroup_subsys object that protects changes to
the hierarchy observed by that subsystem. It is taken by the cgroup
subsystem (in addition to cgroup_mutex) for the following operations:
- linking a cgroup into that subsystem's cgroup tree
- unlinking a cgroup from that subsystem's cgroup tree
- moving the subsystem to/from a hierarchy (including across the
bind() callback)
Thus if the subsystem holds its own hierarchy_mutex, it can safely
traverse its own hierarchy.
Signed-off-by: Paul Menage <menage@google.com>
Tested-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/cgroup.h')
-rw-r--r-- | include/linux/cgroup.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 73d1c730c3c4..ce1c1f34c30c 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -340,8 +340,23 @@ struct cgroup_subsys { | |||
340 | #define MAX_CGROUP_TYPE_NAMELEN 32 | 340 | #define MAX_CGROUP_TYPE_NAMELEN 32 |
341 | const char *name; | 341 | const char *name; |
342 | 342 | ||
343 | struct cgroupfs_root *root; | 343 | /* |
344 | * Protects sibling/children links of cgroups in this | ||
345 | * hierarchy, plus protects which hierarchy (or none) the | ||
346 | * subsystem is a part of (i.e. root/sibling). To avoid | ||
347 | * potential deadlocks, the following operations should not be | ||
348 | * undertaken while holding any hierarchy_mutex: | ||
349 | * | ||
350 | * - allocating memory | ||
351 | * - initiating hotplug events | ||
352 | */ | ||
353 | struct mutex hierarchy_mutex; | ||
344 | 354 | ||
355 | /* | ||
356 | * Link to parent, and list entry in parent's children. | ||
357 | * Protected by this->hierarchy_mutex and cgroup_lock() | ||
358 | */ | ||
359 | struct cgroupfs_root *root; | ||
345 | struct list_head sibling; | 360 | struct list_head sibling; |
346 | }; | 361 | }; |
347 | 362 | ||