diff options
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, | |||
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 | }; |