Commit 8beeff2e authored by Tetsuo Handa's avatar Tetsuo Handa Committed by Stefan Bader

kernel/hung_task.c: break RCU locks based on jiffies

BugLink: https://bugs.launchpad.net/bugs/1818813

[ Upstream commit 304ae427 ]

check_hung_uninterruptible_tasks() is currently calling rcu_lock_break()
for every 1024 threads.  But check_hung_task() is very slow if printk()
was called, and is very fast otherwise.

If many threads within some 1024 threads called printk(), the RCU grace
period might be extended enough to trigger RCU stall warnings.
Therefore, calling rcu_lock_break() for every some fixed jiffies will be
safer.

Link: http://lkml.kernel.org/r/1544800658-11423-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jpSigned-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: default avatarPaul E. McKenney <paulmck@linux.ibm.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 2089eecd
...@@ -30,7 +30,7 @@ int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT; ...@@ -30,7 +30,7 @@ int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT;
* is disabled during the critical section. It also controls the size of * is disabled during the critical section. It also controls the size of
* the RCU grace period. So it needs to be upper-bound. * the RCU grace period. So it needs to be upper-bound.
*/ */
#define HUNG_TASK_BATCHING 1024 #define HUNG_TASK_LOCK_BREAK (HZ / 10)
/* /*
* Zero means infinite timeout - no checking done: * Zero means infinite timeout - no checking done:
...@@ -158,7 +158,7 @@ static bool rcu_lock_break(struct task_struct *g, struct task_struct *t) ...@@ -158,7 +158,7 @@ static bool rcu_lock_break(struct task_struct *g, struct task_struct *t)
static void check_hung_uninterruptible_tasks(unsigned long timeout) static void check_hung_uninterruptible_tasks(unsigned long timeout)
{ {
int max_count = sysctl_hung_task_check_count; int max_count = sysctl_hung_task_check_count;
int batch_count = HUNG_TASK_BATCHING; unsigned long last_break = jiffies;
struct task_struct *g, *t; struct task_struct *g, *t;
/* /*
...@@ -172,10 +172,10 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) ...@@ -172,10 +172,10 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
for_each_process_thread(g, t) { for_each_process_thread(g, t) {
if (!max_count--) if (!max_count--)
goto unlock; goto unlock;
if (!--batch_count) { if (time_after(jiffies, last_break + HUNG_TASK_LOCK_BREAK)) {
batch_count = HUNG_TASK_BATCHING;
if (!rcu_lock_break(g, t)) if (!rcu_lock_break(g, t))
goto unlock; goto unlock;
last_break = jiffies;
} }
/* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */
if (t->state == TASK_UNINTERRUPTIBLE) if (t->state == TASK_UNINTERRUPTIBLE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment