mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mandeep Singh Baines <msb@google.com>
To: "Ingo Molnar" <mingo@elte.hu>,
	"Frédéric Weisbecker" <fweisbec@gmail.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	linux-kernel@vger.kernel.org
Cc: rientjes@google.com, mbligh@google.com, thockin@google.com,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 2/2 v4] softlockup: check all tasks in hung_task
Date: Wed, 4 Feb 2009 20:35:48 -0800	[thread overview]
Message-ID: <20090205043548.GA18933@google.com> (raw)
In-Reply-To: <20090204194339.GB22608@elte.hu>

Ingo Molnar (mingo@elte.hu) wrote:
> 
> * Mandeep Singh Baines <msb@google.com> wrote:
> 
> > +static void check_hung_rcu_refresh(struct task_struct *g, struct task_struct *t)
> 
> please rename this to rcu_lock_break().
> 

Fixed.

> >  	do_each_thread(g, t) {
> > -		if (!--max_count)
> > -			goto unlock;
> > +		if (!--max_count) {
> > +			max_count = sysctl_hung_task_check_count;
> > +			check_hung_rcu_refresh(g, t);
> > +			/* Exit if t or g was unhashed during refresh. */
> > +			if (t->state == TASK_DEAD || g->state == TASK_DEAD)
> > +				goto unlock;
> 
> Thinking about it some more, i think a slightly different approach (that has 
> the same end effect):
> 
>  - Add a "static const int check_count_batching = 1024;" variable that adds 
>    some natural batching - and initialize max_count to that value. There's 
>    little point to make that batching configurable.
> 

Fixed.

The batch_count controls the preemptibility of hung_task. While it might
not make sense to expose the value to user-space, we may want to use a
different value for the PREEMPT config (not sure what the specific values
should be):

#if defined(CONFIG_PREEMPT) && !defined(CONFIG_PREEMPT_RCU)
static const int check_count_batching = 256;
#else
static const int check_count_batching = 2048;
#endif

>  - Leave sysctl_hung_task_check_count present but change its default to 
>    something really large like MAX_PID.

Fixed.

Alternatively, the user could renice khungtaskd in order to control the share
of CPU used.

---
Changed the default value of hung_task_check_count to PID_MAX_LIMIT.
hung_task_batch_count added to put an upper bound on the critical
section. Every hung_task_batch_count checks, the rcu lock is broken.
Keeping the critical section small minimizes time preemption is disabled
and keeps rcu grace periods small.

To prevent following a stale pointer, get_task_struct is called on g and t.
To verify that g and t have not been unhashed while outside the critical
section, the task states are checked.

The design was proposed by Frédéric Weisbecker.

Frédéric Weisbecker (fweisbec@gmail.com) wrote:
>
> Instead of having this arbitrary limit of tasks, why not just
> lurk the need_resched() and then schedule if it needs too.
>
> I know that sounds a bit racy, because you will have to release the
> tasklist_lock and
> a lot of things can happen in the task list until you become resched.
> But you can do a get_task_struct() on g and t before your thread is
> going to sleep and then put them
> when it is awaken.
> Perhaps some tasks will disappear or be appended in the list before g
> and t, but that doesn't really matter:
> if they disappear, they didn't lockup, and if they were appended, they
> are not enough cold to be analyzed :-)
>
> This way you can drop the arbitrary limit of task number given by the user....
>
> Frederic.
>

Signed-off-by: Mandeep Singh Baines <msb@google.com>
---
 kernel/hung_task.c |   39 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index a841db3..34b678c 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -17,9 +17,18 @@
 #include <linux/sysctl.h>
 
 /*
- * Have a reasonable limit on the number of tasks checked:
+ * The number of tasks checked:
  */
-unsigned long __read_mostly sysctl_hung_task_check_count = 1024;
+unsigned long __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT;
+
+/*
+ * Limit number of tasks checked in a batch.
+ *
+ * This value controls the preemptibility of khungtaskd since preemption
+ * is disabled during the critical section. It also controls the size of
+ * the RCU grace period. So it needs to be upper-bound.
+ */
+static const int hung_task_batching = 1024;
 
 /*
  * Zero means infinite timeout - no checking done:
@@ -109,6 +118,24 @@ static void check_hung_task(struct task_struct *t, unsigned long now,
 		panic("hung_task: blocked tasks");
 }
 
+ /*
+  * To avoid extending the RCU grace period for an unbounded amount of time,
+  * periodically exit the critical section and enter a new one.
+  *
+  * For preemptible RCU it is sufficient to call rcu_read_unlock in order
+  * exit the grace period. For classic RCU, a reschedule is required.
+  */
+static void rcu_lock_break(struct task_struct *g, struct task_struct *t)
+{
+	get_task_struct(g);
+	get_task_struct(t);
+	rcu_read_unlock();
+	cond_resched();
+	rcu_read_lock();
+	put_task_struct(t);
+	put_task_struct(g);
+}
+
 /*
  * Check whether a TASK_UNINTERRUPTIBLE does not get woken up for
  * a really long time (120 seconds). If that happens, print out
@@ -116,6 +143,7 @@ static void check_hung_task(struct task_struct *t, unsigned long now,
  */
 static void check_hung_uninterruptible_tasks(unsigned long timeout)
 {
+	int batch_count = hung_task_batching;
 	int max_count = sysctl_hung_task_check_count;
 	unsigned long now = get_timestamp();
 	struct task_struct *g, *t;
@@ -131,6 +159,13 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
 	do_each_thread(g, t) {
 		if (!--max_count)
 			goto unlock;
+		if (!--batch_count) {
+			batch_count = hung_task_batching;
+			rcu_lock_break(g, t);
+			/* Exit if t or g was unhashed during refresh. */
+			if (t->state == TASK_DEAD || g->state == TASK_DEAD)
+				goto unlock;
+		}
 		/* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */
 		if (t->state == TASK_UNINTERRUPTIBLE)
 			check_hung_task(t, now, timeout);
-- 
1.5.4.5


  reply	other threads:[~2009-02-05  4:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-25 20:50 [RFC][PATCH 2/2] add a counter for writers spinning on a rwlock Frederic Weisbecker
2009-01-26 13:32 ` Ingo Molnar
2009-01-26 13:48 ` Peter Zijlstra
2009-01-26 15:25   ` Frédéric Weisbecker
2009-01-26 15:37     ` Peter Zijlstra
2009-01-26 16:04       ` Frédéric Weisbecker
2009-01-26 17:36         ` Mandeep Baines
2009-01-26 17:41           ` Peter Zijlstra
2009-01-27  0:30             ` [PATCH v4] softlockup: remove hung_task_check_count Mandeep Singh Baines
2009-01-27  9:27               ` Frederic Weisbecker
2009-01-27 13:26               ` Ingo Molnar
2009-01-27 18:48                 ` Mandeep Singh Baines
2009-01-28  8:25                   ` Peter Zijlstra
2009-01-29  1:42                     ` Mandeep Singh Baines
2009-01-30 20:41                       ` Mandeep Singh Baines
2009-01-30 20:46                       ` [PATCH 1/2] softlockup: convert read_lock in hung_task to rcu_read_lock Mandeep Singh Baines
2009-01-30 20:49                       ` [PATCH 2/2] softlockup: check all tasks in hung_task Mandeep Singh Baines
2009-01-31 19:22                         ` Peter Zijlstra
2009-02-03  0:05                           ` [PATCH 2/2 v2] " Mandeep Singh Baines
2009-02-03 12:23                             ` Ingo Molnar
2009-02-03 20:56                               ` [PATCH 2/2 v3] " Mandeep Singh Baines
2009-02-04 19:43                                 ` Ingo Molnar
2009-02-05  4:35                                   ` Mandeep Singh Baines [this message]
2009-02-05 14:34                                     ` [PATCH 2/2 v4] " Ingo Molnar
2009-02-05 17:48                                       ` Andrew Morton
2009-02-05 18:07                                         ` Ingo Molnar
2009-02-05 18:30                                           ` Andrew Morton
2009-02-05 18:58                                             ` Ingo Molnar
2009-02-05 18:40                                         ` Mandeep Singh Baines
2009-02-05 17:56                                       ` [PATCH] softlockup: convert read_lock in hung_task to rcu_read_lock Mandeep Singh Baines
2009-02-05 18:13                                         ` Ingo Molnar

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=20090205043548.GA18933@google.com \
    --to=msb@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbligh@google.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=rientjes@google.com \
    --cc=thockin@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome