mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] waitpid: traverse pid task list instead of children or ptraced list
@ 2011-11-22  3:35 Min Zhang
  0 siblings, 0 replies; only message in thread
From: Min Zhang @ 2011-11-22  3:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: Min Zhang

Shorten waitpid system call time by traversing pid task list intead of
entire children or ptraced list when waiting for specific PIDTYPE_PID/PGID/SID.

Tested by fork thousands child processes, PTRACE_ATTACH on each, then
waitpid on each. Result shows saving 2 order of magnitude of time.

Signed-off-by: Min Zhang <mzhang@mvista.com>
---
 kernel/exit.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index 2913b35..89c5d51 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1634,6 +1634,19 @@ static int do_wait_thread(struct wait_opts *wo, struct task_struct *tsk)
 {
 	struct task_struct *p;
 
+	/* traverse pid task list for a specific child pid */
+	if (wo->wo_type != PIDTYPE_MAX) {
+		do_each_pid_task(wo->wo_pid, wo->wo_type, p) {
+			if (p->parent == tsk) {
+				int ret = wait_consider_task(wo, 0, p);
+				if (ret)
+					return ret;
+			}
+		} while_each_pid_task(wo->wo_pid, wo->wo_type, p);
+		return 0;
+	}
+
+	/* traverse entire children list for any child pid */
 	list_for_each_entry(p, &tsk->children, sibling) {
 		int ret = wait_consider_task(wo, 0, p);
 		if (ret)
@@ -1647,6 +1660,19 @@ static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk)
 {
 	struct task_struct *p;
 
+	/* traverse pid task list for a specific child pid */
+	if (wo->wo_type != PIDTYPE_MAX) {
+		do_each_pid_task(wo->wo_pid, wo->wo_type, p) {
+			if (task_is_traced(p) && p->parent == tsk) {
+				int ret = wait_consider_task(wo, 1, p);
+				if (ret)
+					return ret;
+			}
+		} while_each_pid_task(wo->wo_pid, wo->wo_type, p);
+		return 0;
+	}
+
+	/* traverse entire children list for any child pid */
 	list_for_each_entry(p, &tsk->ptraced, ptrace_entry) {
 		int ret = wait_consider_task(wo, 1, p);
 		if (ret)
-- 
1.6.4.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-11-22  3:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-22  3:35 [PATCH] waitpid: traverse pid task list instead of children or ptraced list Min Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®