[-mm PATCH 5/9] Memory controller task migration (v4)

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>
Cc: Paul Menage <menage@...>, Linux Kernel Mailing List <linux-kernel@...>, Linux Containers <containers@...>, YAMAMOTO Takashi <yamamoto@...>, Peter Zijlstra <a.p.zijlstra@...>, Linux MM Mailing List <linux-mm@...>, Vaidyanathan Srinivasan <svaidy@...>, Pavel Emelianov <xemul@...>, Dhaval Giani <dhaval@...>, Balbir Singh <balbir@...>, Dave Hansen <haveblue@...>, Eric W Biederman <ebiederm@...>
Date: Friday, July 27, 2007 - 4:10 pm

Allow tasks to migrate from one container to the other. We migrate
mm_struct's mem_container only when the thread group id migrates.


Signed-off-by: <balbir@linux.vnet.ibm.com>
---

 mm/memcontrol.c |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff -puN mm/memcontrol.c~mem-control-task-migration mm/memcontrol.c
--- linux-2.6.23-rc1-mm1/mm/memcontrol.c~mem-control-task-migration	2007-07-28 01:12:50.000000000 +0530
+++ linux-2.6.23-rc1-mm1-balbir/mm/memcontrol.c	2007-07-28 01:12:50.000000000 +0530
@@ -303,11 +303,46 @@ static int mem_container_populate(struct
 					ARRAY_SIZE(mem_container_files));
 }
 
+static void mem_container_move_task(struct container_subsys *ss,
+				struct container *cont,
+				struct container *old_cont,
+				struct task_struct *p)
+{
+	struct mm_struct *mm;
+	struct mem_container *mem, *old_mem;
+
+	mm = get_task_mm(p);
+	if (mm == NULL)
+		return;
+
+	mem = mem_container_from_cont(cont);
+	old_mem = mem_container_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_container, mem);
+	css_put(&old_mem->css);
+
+out:
+	mmput(mm);
+	return;
+}
+
 struct container_subsys mem_container_subsys = {
 	.name = "memory",
 	.subsys_id = mem_container_subsys_id,
 	.create = mem_container_create,
 	.destroy = mem_container_destroy,
 	.populate = mem_container_populate,
+	.attach = mem_container_move_task,
 	.early_init = 1,
 };
_

-- 
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[-mm PATCH 0/9] Memory controller introduction (v4), Balbir Singh, (Fri Jul 27, 4:09 pm)
Re: [-mm PATCH 0/9] Memory controller introduction (v4), KAMEZAWA Hiroyuki, (Tue Aug 7, 11:51 pm)
Re: [-mm PATCH 0/9] Memory controller introduction (v4), KAMEZAWA Hiroyuki, (Wed Aug 8, 3:51 am)
Re: [-mm PATCH 0/9] Memory controller introduction (v4), Vaidyanathan Srinivasan, (Fri Aug 10, 12:49 am)
[-mm PATCH 2/9] Memory controller containers setup (v4), Balbir Singh, (Fri Jul 27, 4:09 pm)
[-mm PATCH 7/9] Memory controller OOM handling (v4), Balbir Singh, (Fri Jul 27, 4:10 pm)
[-mm PATCH 5/9] Memory controller task migration (v4), Balbir Singh, (Fri Jul 27, 4:10 pm)
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4), YAMAMOTO Takashi, (Mon Jul 30, 11:38 pm)
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4), Vaidyanathan Srinivasan, (Tue Jul 31, 8:44 am)
Re: [-mm PATCH 4/9] Memory controller memory accounting (v4), YAMAMOTO Takashi, (Wed Aug 15, 4:44 am)
Re: [-mm PATCH 6/9] Memory controller add per container LRU ..., Vaidyanathan Srinivasan, (Tue Jul 31, 8:55 am)
Re: [-mm PATCH 6/9] Memory controller add per container LRU ..., Vaidyanathan Srinivasan, (Tue Aug 7, 2:30 pm)
Re: [-mm PATCH 6/9] Memory controller add per container LRU ..., Gautham R Shenoy, (Mon Jul 30, 10:28 am)
[-mm PATCH 3/9] Memory controller accounting setup (v4), Balbir Singh, (Fri Jul 27, 4:10 pm)