Re: [PATCH] hung_task: avoid duplicate stack dumps in sys_info()
From: Andrew Morton
Date: Mon Nov 30 2026 - 19:50:45 EST
On Mon, 30 Nov 2026 23:11:56 +0800 Leon Hwang <leon.hwang@xxxxxxxxx> wrote:
> When hung_task_sys_info includes blocked_tasks, khungtaskd dumps each
> reported hung task's stack, then calls sys_info() to dump D-state tasks.
> A task that stays blocked gets its stack printed twice in the same scan.
>
> Track the tasks khungtaskd reports during the scan. If a recorded task
> still appears blocked at the same switch count, print a short message
> in place of the second stack dump.
>
> With this change, the second dump would be replaced with a log.
>
> [ 20.143549] INFO: task cat:607 blocked for more than 5 seconds.
> [ 20.143560] Not tainted 7.4.0-rc4-gfb22a6547753-dirty #12
> [ 20.143564] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
> [ 20.143567] task:cat state:D stack:0 pid:607 tgid:607 ppid:603 task_flags:0x400000 flags:0x00080000
>
> ...
>
> [ 20.144250] task cat:607 has been reported by hung task detector.
OK. This is a pretty minor bug! And userspace can filter out the
duplicates easily enough (I assume).
> ---
> include/linux/hung_task.h | 9 +++++
> kernel/hung_task.c | 76 ++++++++++++++++++++++++++++++++++++---
> kernel/sched/core.c | 4 +++
> 3 files changed, 85 insertions(+), 4 deletions(-)
And that's a lot of churn.
<idea>
task_struct.atomic_flags has plenty of unused bits and using one of
them for this purpose seems appropriate.
Can we set one of those bits for deduplication and later test-n-clear
it in
check_hung_uninterruptible_tasks()
->sys_info(si_mask)
->show_state_filter(TASK_UNINTERRUPTIBLE)?
Or something along these lines?