Skip to content

Commit b4aa14a

Browse files
Tetsuo Handatorvalds
authored andcommitted
kernel/hung_task.c: use timeout diff when timeout is updated
When new timeout is written to /proc/sys/kernel/hung_task_timeout_secs, khungtaskd is interrupted and again sleeps for full timeout duration. This means that hang task will not be checked if new timeout is written periodically within old timeout duration and/or checking of hang task will be delayed for up to previous timeout duration. Fix this by remembering last time khungtaskd checked hang task. This change will allow other watchdog tasks (if any) to share khungtaskd by sleeping for minimal timeout diff of all watchdog tasks. Doing more watchdog tasks from khungtaskd will reduce the possibility of printk() collisions by multiple watchdog threads. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Aaron Tomlin <atomlin@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3f2b1a0 commit b4aa14a

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

‎kernel/hung_task.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,12 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
185185
rcu_read_unlock();
186186
}
187187

188-
static unsigned long timeout_jiffies(unsigned long timeout)
188+
static long hung_timeout_jiffies(unsigned long last_checked,
189+
unsigned long timeout)
189190
{
190191
/* timeout of 0 will disable the watchdog */
191-
return timeout ? timeout * HZ : MAX_SCHEDULE_TIMEOUT;
192+
return timeout ? last_checked - jiffies + timeout * HZ :
193+
MAX_SCHEDULE_TIMEOUT;
192194
}
193195

194196
/*
@@ -224,18 +226,21 @@ EXPORT_SYMBOL_GPL(reset_hung_task_detector);
224226
*/
225227
static int watchdog(void *dummy)
226228
{
229+
unsigned long hung_last_checked = jiffies;
230+
227231
set_user_nice(current, 0);
228232

229233
for ( ; ; ) {
230234
unsigned long timeout = sysctl_hung_task_timeout_secs;
235+
long t = hung_timeout_jiffies(hung_last_checked, timeout);
231236

232-
while (schedule_timeout_interruptible(timeout_jiffies(timeout)))
233-
timeout = sysctl_hung_task_timeout_secs;
234-
235-
if (atomic_xchg(&reset_hung_task, 0))
237+
if (t <= 0) {
238+
if (!atomic_xchg(&reset_hung_task, 0))
239+
check_hung_uninterruptible_tasks(timeout);
240+
hung_last_checked = jiffies;
236241
continue;
237-
238-
check_hung_uninterruptible_tasks(timeout);
242+
}
243+
schedule_timeout_interruptible(t);
239244
}
240245

241246
return 0;

0 commit comments

Comments
 (0)