Skip to content

hung_task: Improve warning budget handling and task reporting

Aaron Tomlin lkml 6 versions – Applied

Status from this message: [merged mm-nonmm-stable] hung_task-log-summary-line-when-warning-budget-is-exhausted.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v11 Latest2 patches 3 repliesApplied 2/2
  2. v102 patches 1 replySuperseded
  3. v92 patches 10 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v82 patches6 repliesSuperseded
v72 patches7 repliesSuperseded
v12 patches5 repliesSuperseded

Changes in v11 from the cover letter

- Guarded the suppression notice in hung_task_info() with !hung_task_call_panic so suppression messages are not emitted for tasks dumped while panicking, and simplified the log message to state details are suppressed until the budget is reset

- Added Reviewed-by: tag from Bradley Morgan <[email protected]>

- Linked to v10: https://lore.kernel.org/lkml/[email protected]/

Patches in v11 All 2 applied

#Subject and filesSizeRepliesApplied
1/2hung_task: Reset warning budget when problem gets resolvedDocumentation/admin-guide/sysctl/kernel.rst kernel/hung_task.c+44 -102 repliesApplied
2/2hung_task: Log summary line when warning budget is exhaustedkernel/hung_task.c+6 -20 repliesApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchLance YangPetr MladekBradley Morgan
1/2T-b R-b R-b R-b
2/2R-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v11 thread

Cover letter [PATCH v11 0/2] hung_task: Improve warning budget handling and task reporting

The hung_task watchdog detects tasks stuck in TASK_UNINTERRUPTIBLE (D) state for longer than CONFIG_DEFAULT_HUNG_TASK_TIMEOUT seconds. To prevent log spam during system spikes, sysctl_hung_task_warnings enforces a budget on the number of logged warnings.

However, the current implementation has two major limitations:

1. Permanent exhaustion of warning budget

sysctl_hung_task_warnings is decremented directly when printing warnings. Once this budget hits zero, no further warnings are reported until an administrator manually updates the sysctl value or reboots the system. Consequently, a single temporary hang episode permanently blinds the kernel watchdog to any subsequent hung tasks after system recovery.

2. Total log suppression when budget is exhausted

Once the warning budget reaches zero, hung_task_info() completely suppresses all output, including the basic single-line alert. While suppressing verbose stack dumps and lock debugging is desirable to prevent dmesg flooding, hiding basic task alerts leaves administrators entirely unaware that tasks are hanging.

This patch series resolves both limitations by decoupling the configured warning limit from the active runtime budget, automatically resetting the budget upon system recovery or sysctl updates, and emitting a single aggregate summary line when hung tasks are detected under an exhausted warning budget.

Patch 1 separates the configured sysctl hung_task_warnings from the runtime budget, making khungtaskd the sole owner of runtime budget updates. The budget is reloaded directly when a scan finds zero hung tasks, or via an atomic reset request published on sysctl write.

Patch 2 prevents dmesg flooding during system-wide hangs by keeping non-panic per-task stack dumps budgeted, while providing ongoing visibility by logging a single aggregate summary line at the end of each scan iteration when the warning budget is exhausted.

Changes since v10:

- Guarded the suppression notice in hung_task_info() with !hung_task_call_panic so suppression messages are not emitted for tasks dumped while panicking, and simplified the log message to state details are suppressed until the budget is reset

- Added Reviewed-by: tag from Bradley Morgan <[email protected]>

- Linked to v10: https://lore.kernel.org/lkml/[email protected]/

Changes since v9:

- Renamed hung_task_warnings_printed to hung_task_warnings_budget and added top-level comments distinguishing between the configured sysctl limit and the runtime remaining budget (Petr Mladek)

- Used atomic_xchg_acquire() when checking reset_hung_task_warnings in check_hung_uninterruptible_tasks() for explicit acquire/release barrier symmetry with the sysctl handler (Petr Mladek, Lance Yang)

- Refined the suppression message in hung_task_info() to explicitly reflect that details remain suppressed until the budget is reset or a panic is triggered (Lance Yang)

- Clarified commit descriptions regarding khungtaskd single-writer budget ownership and panic diagnostic retention (Lance Yang)

- Added Reviewed-by: tag from Petr Mladek

- Linked to v9: https://lore.kernel.org/lkml/[email protected]/

Changes since v8:

- Resolved a concurrent sysctl write race condition on hung_task_warnings_printed by making khungtaskd the sole owner of runtime budget updates. Introduced an atomic flag set via sysctl write and picked up locklessly by khungtaskd at the start of a scan iteration (Lance Yang)

- Restored per-task header logging back inside the warning budget check in hung_task_info() to prevent dmesg ring buffer saturation and console lock contention during mass hung task events (Lance Yang)

- Added a single aggregate scan summary line printed at the end of each watchdog scan when hung tasks are detected and the warning budget is exhausted (Lance Yang)

- Linked to v8: https://lore.kernel.org/lkml/[email protected]/

Changes since v7:

- Consolidated the commit message of each patch (Lance Yang)

- Linked to v7: https://lore.kernel.org/lkml/[email protected]/

Changes since v6:

- Restructured the series in a new direction. Introduced an internal counter (hung_task_warnings_printed) decoupled from sysctl_hung_task_warnings. The warning budget automatically resets to the configured limit once a check interval completes with zero hung tasks detected, or when modified via sysctl (Petr Mladek)

- Ensured the single-line blocked hung task message is always printed even after the warning budget reaches zero. Now budget enforcement is restricted solely to suppressing verbose diagnostics (Petr Mladek)

- Refined the description of sysctl hung_task_warnings (Lance Yang)

- Removed field hung_task_reported from struct task_struct

- Removed the CONFIG_DETECT_HUNG_TASK_BLOCKER integration and hung_task_blockers[] used to track memory addresses of blocker locks across check intervals

- Removed the skip_show_task logic and dmesg log suppression messages

- Removed tracking variables (warnings_decremented and hung_task_has_active) and the dmesg recovery notice printed when clearing the blocker array

- Linked to v6: https://lore.kernel.org/lkml/[email protected]/

Changes since v5:

- Skipped hung_task_info() and sys_info() for tasks already reported in previous rounds to avoid log spam

- Linked to v5: https://lore.kernel.org/lkml/[email protected]/

Changes since v4:

- Replaced the stack-local hashmap implementation with a persistent array (Petr Mladek)

- Persistently track blocker addresses across scan intervals. Suppress warning reports and keep the sysctl_hung_task_warnings budget intact if the blocker is already tracked in the array (Petr Mladek)

- Reset the warnings budget and clear the blocker array when the hang resolves (Petr Mladek)

- Output a recovery message to the kernel ring buffer upon hang resolution

- Linked to v4: https://lore.kernel.org/lkml/[email protected]/

Changes since v3:

- Deduct from the global budget if printing a full stack trace

- Pivoted from heuristic Wait Channel hashing to deterministic blocker address hashing via CONFIG_DETECT_HUNG_TASK_BLOCKER

- Replaced the hung_task_reported bit-field with a standalone u8 byte. Move hung_task_reported into an existing structural alignment hole within task_struct following blocked_lock, resulting in zero overall memory footprint increase and optimal cacheline grouping

- Linked to v3: https://lore.kernel.org/lkml/[email protected]/

Changes since v2:

- Replaced the per-round cache flush with a task_struct bit-field for persistent cross-scan tracking, mitigating delayed budget exhaustion

- Abandoned exact-stack hashing in favour of Wait Channel hashing

- Transitioned from jhash() to hash_long() to optimise single-pointer hashing, and relocated the hash map to the local stack

- Linked to v2: https://lore.kernel.org/lkml/[email protected]/

Changes since v1:

- Preserve "INFO:" headers for all hung tasks; suppress only the stack dumps for duplicates (Masami Hiramatsu)

- Print a clear notification when a trace is explicitly suppressed

- Add #ifdef CONFIG_STACKTRACE guards to prevent Kconfig build errors

- Optimise overhead by unwinding the stack only if a warning is actually going to be printed

- Linked to v1: https://lore.kernel.org/lkml/[email protected]/

Aaron Tomlin (2):
hung_task: Reset warning budget when problem gets resolved
hung_task: Log summary line when warning budget is exhausted

 Documentation/admin-guide/sysctl/kernel.rst |  5 +-
 kernel/hung_task.c                          | 55 +++++++++++++++++----
 2 files changed, 49 insertions(+), 11 deletions(-)
Signature · 1 line
2.55.0