All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroups: add task along with its threads in one shot inside cgroup
@ 2008-12-17 20:30 Gowrishankar M
       [not found] ` <1229545826-16978-1-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Gowrishankar M @ 2008-12-17 20:30 UTC (permalink / raw)
  To: containers; +Cc: Gowrishankar M, Dave, Eric, Sukadev, Balbir

From: Gowrishankar M <gomuthuk-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>

In current model, task by task we populate cgroup.
Incase of multi-threaded task, it becomes difficult
as we should first know about list of threads created
and add them one by one in cgroup.

In below patch, when a thread group leader is scanned,
belonging threads are also moved along with it, while
populating cgroup tasks.

Below steps can help to verify the patch:
(1) mount -t cgroup -o cpuset cgroup /cgroup
(2) /bin/mkdir /cgroup/testgroup and cd /cgroup/testgroup
(3) /bin/echo 0 > cpuset.mems
(4) /bin/echo 0 > cpuset.cpus
(5) /bin/echo "<PID of thread group leader>" > tasks (tip: ps -aeL)
(6) cat tasks and check for thread ids.

Signed-off-by: Gowrishankar M <gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
 kernel/cgroup.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 35eebd5..de7f0cc 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1279,6 +1279,7 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk)
 static int attach_task_by_pid(struct cgroup *cgrp, u64 pid)
 {
 	struct task_struct *tsk;
+	struct task_struct *p;
 	int ret;
 
 	if (pid) {
@@ -1288,21 +1289,23 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid)
 			rcu_read_unlock();
 			return -ESRCH;
 		}
-		get_task_struct(tsk);
 		rcu_read_unlock();
 
 		if ((current->euid) && (current->euid != tsk->uid)
 		    && (current->euid != tsk->suid)) {
-			put_task_struct(tsk);
 			return -EACCES;
 		}
-	} else {
+	} else
 		tsk = current;
-		get_task_struct(tsk);
-	}
 
-	ret = cgroup_attach_task(cgrp, tsk);
-	put_task_struct(tsk);
+	p = tsk;
+	do {
+		get_task_struct(p);
+		ret = cgroup_attach_task(cgrp, p);
+		put_task_struct(p);
+		if (thread_group_empty(p) && !(has_group_leader_pid(p)))
+			break;
+	} while_each_thread(tsk, p);
 	return ret;
 }
 
-- 
1.5.5.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cgroups: add task along with its threads in one shot inside cgroup
       [not found] ` <1229545826-16978-1-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
@ 2008-12-18  1:51   ` Li Zefan
  0 siblings, 0 replies; 2+ messages in thread
From: Li Zefan @ 2008-12-18  1:51 UTC (permalink / raw)
  To: Gowrishankar M; +Cc: containers, Sukadev, Balbir, Eric, Dave

Gowrishankar M wrote:
> From: Gowrishankar M <gomuthuk-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> 
> In current model, task by task we populate cgroup.
> Incase of multi-threaded task, it becomes difficult
> as we should first know about list of threads created
> and add them one by one in cgroup.
> 

It was proposed to add 'procs' control file to do so long ago, but there
is a big issue, that there is no way to do it atomically, i.e you may
success to move some threads but fail for others.

You can get some information here:
	https://lists.linux-foundation.org/pipermail/containers/2008-July/011747.html

> In below patch, when a thread group leader is scanned,
> belonging threads are also moved along with it, while
> populating cgroup tasks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-12-18  1:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-17 20:30 [PATCH] cgroups: add task along with its threads in one shot inside cgroup Gowrishankar M
     [not found] ` <1229545826-16978-1-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-12-18  1:51   ` Li Zefan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.