From: Min Zhang <mzhang@mvista.com>
To: linux-kernel@vger.kernel.org
Cc: Min Zhang <mzhang@mvista.com>
Subject: [PATCH] waitpid: traverse pid task list instead of children or ptraced list
Date: Mon, 21 Nov 2011 19:35:09 -0800 [thread overview]
Message-ID: <1321932909-7101-1-git-send-email-mzhang@mvista.com> (raw)
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
reply other threads:[~2011-11-22 3:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321932909-7101-1-git-send-email-mzhang@mvista.com \
--to=mzhang@mvista.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®