Re: [PATCH] hung_task: avoid duplicate stack dumps in sys_info()

From: Leon Hwang

Date: Tue Dec 01 2026 - 11:52:48 EST


On 2026/12/1 08:50, Andrew Morton wrote:
> 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.

Agreed.

A minor bug should be fixed with less 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?

Adding PFA_HUNG_TASK_REPORTED to task_struct.atomic_flags works. See
below patch.

Thanks,
Leon

---