lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1321932909-7101-1-git-send-email-mzhang@mvista.com>
Date:	Mon, 21 Nov 2011 19:35:09 -0800
From:	Min Zhang <mzhang@...sta.com>
To:	linux-kernel@...r.kernel.org
Cc:	Min Zhang <mzhang@...sta.com>
Subject: [PATCH] waitpid: traverse pid task list instead of children or ptraced list

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@...sta.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ