hung_task: avoid duplicate stack dumps in sys_info()
Subsystems (2)
PATCH 1/1 hung_task: avoid duplicate stack dumps in sys_info()
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.
--- include/linux/hung_task.h | 9 +++++ kernel/hung_task.c | 76 ++++++++++++++++++++++++++++++++++++--- kernel/sched/core.c | 4 +++ 3 files changed, 85 insertions(+), 4 deletions(-)
include/linux/hung_task.h +9 -0
@@ -12,6 +12,15 @@#include <linux/sched.h> #include <linux/compiler.h> +#ifdef CONFIG_DETECT_HUNG_TASK +bool hung_task_check_reported (const struct task_struct *p); +#else +static inline bool hung_task_check_reported (const struct task_struct *p) +{ +return false; +} +#endif +/* * @blocker: Combines lock address and blocking type. *
kernel/hung_task.c +72 -4
136 lines not on this page · raw message
kernel/sched/core.c +4 -0
@@ -68,6 +68,7 @@#include <linux/wait_api.h> #include <linux/workqueue_api.h> #include <linux/livepatch_sched.h> +#include <linux/hung_task.h> #ifdef CONFIG_PREEMPT_DYNAMIC # ifdef CONFIG_GENERIC_IRQ_ENTRY
@@ -8205,6 +8206,9 @@ state_filter_match(unsigned long state_filter, struct task_struct *p)if (state_filter ==TASK_UNINTERRUPTIBLE && (state &TASK_NOLOAD ))return false; +if (state_filter ==TASK_UNINTERRUPTIBLE &&hung_task_check_reported (p)) +return false; +return true; }
Signature · 1 line
2.55.0
Andrew Morton
maintainerQuoted 10 lines · On Mon, 30 Nov 2026 23:11:56 +0800 Leon Hwang <[email protected]> wrote:
When
hung_task_sys_infoincludesblocked_tasks, khungtaskd dumps each reported hung task's stack, then callssys_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.
Quoted 8 lines
[ 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).
Quoted 5 lines
--- 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?