Re: [PATCH][v2] hung_task: Panic after fixed number of hung tasks

From: Randy Dunlap

Date: Fri Oct 10 2025 - 20:25:24 EST


Hi,

On 9/27/25 10:31 PM, lirongqing wrote:
> From: Li RongQing <lirongqing@xxxxxxxxx>
>
> Currently, when hung_task_panic is enabled, kernel will panic immediately
> upon detecting the first hung task. However, some hung tasks are transient
> and the system can recover fully, while others are unrecoverable and
> trigger consecutive hung task reports, and a panic is expected.
>
> This commit adds a new sysctl parameter hung_task_count_to_panic to allows
> specifying the number of consecutive hung tasks that must be detected
> before triggering a kernel panic. This provides finer control for
> environments where transient hangs maybe happen but persistent hangs should
> still be fatal.
>
> Acked-by: Lance Yang <lance.yang@xxxxxxxxx>
> Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
> ---
> Diff with v1: change documentation as Lance suggested
>
> Documentation/admin-guide/sysctl/kernel.rst | 8 ++++++++
> kernel/hung_task.c | 14 +++++++++++++-
> 2 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
> index 8b49eab..98b47a7 100644
> --- a/Documentation/admin-guide/sysctl/kernel.rst
> +++ b/Documentation/admin-guide/sysctl/kernel.rst
> @@ -405,6 +405,14 @@ This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
> 1 Panic immediately.
> = =================================================
>
> +hung_task_count_to_panic
> +=====================

The underline length should be at least as long as the title to
prevent kernel-doc build warnings. Same length is preferred.

> +
> +When set to a non-zero value, a kernel panic will be triggered if the
> +number of detected hung tasks reaches this value.
> +
> +Note that setting hung_task_panic=1 will still cause an immediate panic
> +on the first hung task.
>
> hung_task_check_count
> =====================

--
~Randy