diff options
author | Balbir Singh <balbir@linux.vnet.ibm.com> | 2008-02-07 11:13:54 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-07 19:42:18 +0300 |
commit | 67e465a77ba658635309ee00b367bec6555ea544 (patch) | |
tree | 172060de1a91624725215c5f0e1131ce5e5c5e92 /mm | |
parent | 8a9f3ccd24741b50200c3f33d62534c7271f3dfc (diff) | |
download | linux-67e465a77ba658635309ee00b367bec6555ea544.tar.xz |
Memory controller: task migration
Allow tasks to migrate from one cgroup to the other. We migrate
mm_struct's mem_cgroup only when the thread group id migrates.
Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Pavel Emelianov <xemul@openvz.org>
Cc: Paul Menage <menage@google.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Kirill Korotaev <dev@sw.ru>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: David Rientjes <rientjes@google.com>
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>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/memcontrol.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ebca767292dc..b25df2a9d024 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -326,11 +326,46 @@ static int mem_cgroup_populate(struct cgroup_subsys *ss, ARRAY_SIZE(mem_cgroup_files)); } +static void mem_cgroup_move_task(struct cgroup_subsys *ss, + struct cgroup *cont, + struct cgroup *old_cont, + struct task_struct *p) +{ + struct mm_struct *mm; + struct mem_cgroup *mem, *old_mem; + + mm = get_task_mm(p); + if (mm == NULL) + return; + + mem = mem_cgroup_from_cont(cont); + old_mem = mem_cgroup_from_cont(old_cont); + + if (mem == old_mem) + goto out; + + /* + * Only thread group leaders are allowed to migrate, the mm_struct is + * in effect owned by the leader + */ + if (p->tgid != p->pid) + goto out; + + css_get(&mem->css); + rcu_assign_pointer(mm->mem_cgroup, mem); + css_put(&old_mem->css); + +out: + mmput(mm); + return; +} + struct cgroup_subsys mem_cgroup_subsys = { .name = "memory", .subsys_id = mem_cgroup_subsys_id, .create = mem_cgroup_create, .destroy = mem_cgroup_destroy, .populate = mem_cgroup_populate, + .attach = mem_cgroup_move_task, .early_init = 1, }; |