From: Mandeep Singh Baines <msb@google.com>
To: fweisbec@gmail.com, mingo@elte.hu, linux-kernel@vger.kernel.org
Cc: rientjes@google.com, mbligh@google.com, thockin@google.com
Subject: [PATCH] softlockup: remove hung_task_check_count
Date: Tue, 20 Jan 2009 17:46:15 -0800 [thread overview]
Message-ID: <20090121014615.GA21018@google.com> (raw)
As suggested by Frederic Weisbecker.
Patch against tip/core/softlockup.
---
To avoid holding the tasklist lock too long, hung_task_check_count was used
as an upper bound on the number of tasks that are checked by hung_task.
This can be problematic if hung_task_check_count is set much lower than
the number of tasks in the system. A large number of tasks will not get
checked. This patch removes the hung_task_check_count sysctl.
Instead of checking a limited number of tasks, all tasks are checked. To
avoid holding the tasklist lock too long, the lock is released and the
processor rescheduled (if necessary) every n tasks (currently 1024).
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>
---
include/linux/sched.h | 1 -
kernel/hung_task.c | 25 +++++++++++++++++++++----
kernel/sysctl.c | 9 ---------
3 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index f2f94d5..278121c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -315,7 +315,6 @@ static inline void touch_all_softlockup_watchdogs(void)
#ifdef CONFIG_DETECT_HUNG_TASK
extern unsigned int sysctl_hung_task_panic;
-extern unsigned long sysctl_hung_task_check_count;
extern unsigned long sysctl_hung_task_timeout_secs;
extern unsigned long sysctl_hung_task_warnings;
extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index ba8ccd4..f9b18e2 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -19,7 +19,7 @@
/*
* Have a reasonable limit on the number of tasks checked:
*/
-unsigned long __read_mostly sysctl_hung_task_check_count = 1024;
+#define HUNG_TASK_CHECK_COUNT 1024
/*
* Zero means infinite timeout - no checking done:
@@ -116,7 +116,7 @@ static void check_hung_task(struct task_struct *t, unsigned long now,
*/
static void check_hung_uninterruptible_tasks(unsigned long timeout)
{
- int max_count = sysctl_hung_task_check_count;
+ int max_count = HUNG_TASK_CHECK_COUNT;
unsigned long now = get_timestamp();
struct task_struct *g, *t;
@@ -129,8 +129,25 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
read_lock(&tasklist_lock);
do_each_thread(g, t) {
- if (!--max_count)
- goto unlock;
+ if (!--max_count) {
+ /*
+ * Drop the lock every once in a while and resched if
+ * necessary. Don't want to hold the lock too long.
+ */
+ get_task_struct(t);
+ read_unlock(&tasklist_lock);
+ max_count = HUNG_TASK_CHECK_COUNT;
+ if (need_resched())
+ schedule();
+ read_lock(&tasklist_lock);
+ put_task_struct(t);
+ /*
+ * t was unlinked from tasklist. Can't continue in this
+ * case. Exit and try again next time.
+ */
+ if (t->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);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 2481ed3..16526a2 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -820,15 +820,6 @@ static struct ctl_table kern_table[] = {
},
{
.ctl_name = CTL_UNNUMBERED,
- .procname = "hung_task_check_count",
- .data = &sysctl_hung_task_check_count,
- .maxlen = sizeof(unsigned long),
- .mode = 0644,
- .proc_handler = &proc_doulongvec_minmax,
- .strategy = &sysctl_intvec,
- },
- {
- .ctl_name = CTL_UNNUMBERED,
.procname = "hung_task_timeout_secs",
.data = &sysctl_hung_task_timeout_secs,
.maxlen = sizeof(unsigned long),
--
1.5.4.5
next reply other threads:[~2009-01-21 1:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-21 1:46 Mandeep Singh Baines [this message]
2009-01-21 11:13 ` [PATCH] softlockup: remove hung_task_check_count Ingo Molnar
2009-01-21 13:14 ` Frédéric Weisbecker
2009-01-22 0:54 ` [PATCH v2] " Mandeep Singh Baines
2009-01-22 8:34 ` Ingo Molnar
2009-01-22 19:55 ` [PATCH v3] " Mandeep Singh Baines
2009-01-23 3:21 ` Mandeep Baines
2009-01-23 9:23 ` Ingo Molnar
2009-01-23 10:04 ` Frédéric Weisbecker
2009-01-24 1:55 ` Mandeep Singh Baines
2009-01-24 15:52 ` Frederic Weisbecker
2009-01-26 2:25 ` Mandeep Baines
2009-01-24 2:56 ` Mandeep Singh Baines
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=20090121014615.GA21018@google.com \
--to=msb@google.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mbligh@google.com \
--cc=mingo@elte.hu \
--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