diff options
author | Balbir Singh <balbir@linux.vnet.ibm.com> | 2008-02-07 03:13:54 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-07 11:42:18 -0500 |
commit | 67e465a77ba658635309ee00b367bec6555ea544 (patch) | |
tree | 172060de1a91624725215c5f0e1131ce5e5c5e92 /mm/memcontrol.c | |
parent | 8a9f3ccd24741b50200c3f33d62534c7271f3dfc (diff) |
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/memcontrol.c')
-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, | |||
326 | ARRAY_SIZE(mem_cgroup_files)); | 326 | ARRAY_SIZE(mem_cgroup_files)); |
327 | } | 327 | } |
328 | 328 | ||
329 | static void mem_cgroup_move_task(struct cgroup_subsys *ss, | ||
330 | struct cgroup *cont, | ||
331 | struct cgroup *old_cont, | ||
332 | struct task_struct *p) | ||
333 | { | ||
334 | struct mm_struct *mm; | ||
335 | struct mem_cgroup *mem, *old_mem; | ||
336 | |||
337 | mm = get_task_mm(p); | ||
338 | if (mm == NULL) | ||
339 | return; | ||
340 | |||
341 | mem = mem_cgroup_from_cont(cont); | ||
342 | old_mem = mem_cgroup_from_cont(old_cont); | ||
343 | |||
344 | if (mem == old_mem) | ||
345 | goto out; | ||
346 | |||
347 | /* | ||
348 | * Only thread group leaders are allowed to migrate, the mm_struct is | ||
349 | * in effect owned by the leader | ||
350 | */ | ||
351 | if (p->tgid != p->pid) | ||
352 | goto out; | ||
353 | |||
354 | css_get(&mem->css); | ||
355 | rcu_assign_pointer(mm->mem_cgroup, mem); | ||
356 | css_put(&old_mem->css); | ||
357 | |||
358 | out: | ||
359 | mmput(mm); | ||
360 | return; | ||
361 | } | ||
362 | |||
329 | struct cgroup_subsys mem_cgroup_subsys = { | 363 | struct cgroup_subsys mem_cgroup_subsys = { |
330 | .name = "memory", | 364 | .name = "memory", |
331 | .subsys_id = mem_cgroup_subsys_id, | 365 | .subsys_id = mem_cgroup_subsys_id, |
332 | .create = mem_cgroup_create, | 366 | .create = mem_cgroup_create, |
333 | .destroy = mem_cgroup_destroy, | 367 | .destroy = mem_cgroup_destroy, |
334 | .populate = mem_cgroup_populate, | 368 | .populate = mem_cgroup_populate, |
369 | .attach = mem_cgroup_move_task, | ||
335 | .early_init = 1, | 370 | .early_init = 1, |
336 | }; | 371 | }; |