Skip to content

Commit

Permalink
Memory controller: task migration
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Pavel Emelianov <[email protected]>
Cc: Paul Menage <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Nick Piggin <[email protected]>
Cc: Kirill Korotaev <[email protected]>
Cc: Herbert Poetzl <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Vaidyanathan Srinivasan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Balbir Singh authored and Linus Torvalds committed Feb 7, 2008
1 parent 8a9f3cc commit 67e465a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit 67e465a

Please sign in to comment.