All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>, Ratan Nalumasu <rnalumasu@gmail.com>,
	Roland McGrath <roland@redhat.com>,
	Vitaly Mayatskikh <vmayatsk@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [RFC,PATCH 2/2] change __wake_up_parent() to use filtered wakeup
Date: Mon, 22 Jun 2009 19:04:37 +0200	[thread overview]
Message-ID: <20090622170437.GA4906@redhat.com> (raw)

Ratan Nalumasu reported that in a process with many threads doing
unnecessary wakeups.  Every waiting thread in the process wakes up to loop
through the children and see that the only ones it cares about are still
not ready.

Now that we have struct wait_opts we can change do_wait/__wake_up_parent
to use filtered wakeups.

We can make child_wait_callback() more clever later, right now it only
checks eligible_child().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---

 kernel/signal.c |    3 ++-
 kernel/exit.c   |   22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

--- WAIT/kernel/signal.c~2_WAKE_PARENT	2009-06-22 17:19:55.000000000 +0200
+++ WAIT/kernel/signal.c	2009-06-22 18:35:37.000000000 +0200
@@ -1388,7 +1388,8 @@ ret:
 static inline void __wake_up_parent(struct task_struct *p,
 				    struct task_struct *parent)
 {
-	wake_up_interruptible_sync(&parent->signal->wait_chldexit);
+	__wake_up_sync_key(&parent->signal->wait_chldexit,
+				TASK_INTERRUPTIBLE, 1, p);
 }
 
 /*
--- WAIT/kernel/exit.c~2_WAKE_PARENT	2009-06-22 17:33:08.000000000 +0200
+++ WAIT/kernel/exit.c	2009-06-22 18:55:08.000000000 +0200
@@ -1089,6 +1089,7 @@ struct wait_opts {
 	int __user		*wo_stat;
 	struct rusage __user	*wo_rusage;
 
+	wait_queue_t		child_wait;
 	int			notask_error;
 };
 
@@ -1558,15 +1559,29 @@ static int ptrace_do_wait(struct wait_op
 	return 0;
 }
 
+static int child_wait_callback(wait_queue_t *wait, unsigned mode,
+				int sync, void *key)
+{
+	struct wait_opts *wo = container_of(wait, struct wait_opts,
+						child_wait);
+	struct task_struct *p = key;
+
+	if (!eligible_child(wo, p))
+		return 0;
+
+	return default_wake_function(wait, mode, sync, key);
+}
+
 static long do_wait(struct wait_opts *wo)
 {
-	DECLARE_WAITQUEUE(wait, current);
 	struct task_struct *tsk;
 	int retval;
 
 	trace_sched_process_wait(wo->wo_pid);
 
-	add_wait_queue(&current->signal->wait_chldexit,&wait);
+	init_waitqueue_func_entry(&wo->child_wait, child_wait_callback);
+	wo->child_wait.private = current;
+	add_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
 repeat:
 	/*
 	 * If there is nothing that can match our critiera just get out.
@@ -1607,7 +1622,8 @@ notask:
 	}
 end:
 	__set_current_state(TASK_RUNNING);
-	remove_wait_queue(&current->signal->wait_chldexit,&wait);
+	remove_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
+
 	if (wo->wo_info) {
 		struct siginfo __user *infop = wo->wo_info;
 


             reply	other threads:[~2009-06-22 20:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22 17:04 Oleg Nesterov [this message]
2009-06-24  9:13 ` [RFC,PATCH 2/2] change __wake_up_parent() to use filtered wakeup Roland McGrath
2009-06-24 15:21   ` Oleg Nesterov
2009-06-24 18:57     ` Roland McGrath
2009-06-24 16:11       ` Oleg Nesterov
2009-06-24 19:42         ` Roland McGrath
2009-06-24 17:13           ` Oleg Nesterov
2009-06-24 20:51             ` Roland McGrath
     [not found]               ` <93ad5f3f0906252111n48742b9ax8dc2ad35b30f4292@mail.gmail.com>
2009-06-29  3:38                 ` Oleg Nesterov
2009-06-29 23:08                   ` [rfc] do not place sub-threads on task_struct->children list Oleg Nesterov
2009-06-30 19:30                     ` Roland McGrath
2009-07-01  5:40                       ` Oleg Nesterov
2009-06-30 19:22                   ` [RFC,PATCH 2/2] change __wake_up_parent() to use filtered wakeup Roland McGrath

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=20090622170437.GA4906@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rnalumasu@gmail.com \
    --cc=roland@redhat.com \
    --cc=vmayatsk@redhat.com \
    /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 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.