Introduce support for writing to /proc/sys/kernel/hung_task_detect_count.
Writing any value to this file atomically resets the counter of detected
hung tasks to zero. This grants system administrators the ability to clear
the cumulative diagnostic history after resolving an incident, simplifying
monitoring without requiring a system restart.
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
Documentation/admin-guide/sysctl/kernel.rst | 2 +-
kernel/hung_task.c | 30 +++++++++++++++++++--
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index 239da22c4e28..43c17b919969 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -418,7 +418,7 @@ hung_task_detect_count
======================
Indicates the total number of tasks that have been detected as hung since
-the system boot.
+the system boot. The counter can be reset to zero when written to.
This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index 6f3fb26378b5..979b7e2fcc19 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -377,6 +377,32 @@ static long hung_timeout_jiffies(unsigned long last_checked,
}
#ifdef CONFIG_SYSCTL
+
+/**
+ * proc_dohung_task_detect_count - proc handler for hung_task_detect_count
+ *
+ * Handles read access for the hung task counter. For write access, it
+ * accepts any successfully parsed value and atomically resets the counter
+ * to zero. Returns the byte count written on success or a negative error
+ * code on failure.
+ */
+static int proc_dohung_task_detect_count(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ int ret;
+
+ if (!write)
+ return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
+
+ ret = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
+ if (ret)
+ return ret;
+
+ WRITE_ONCE(sysctl_hung_task_detect_count, 0);
+
+ return ret;
+}
+
/*
* Process updating of timeout sysctl
*/
@@ -459,8 +485,8 @@ static const struct ctl_table hung_task_sysctls[] = {
.procname = "hung_task_detect_count",
.data = &sysctl_hung_task_detect_count,
.maxlen = sizeof(unsigned long),
- .mode = 0444,
- .proc_handler = proc_doulongvec_minmax,
+ .mode = 0644,
+ .proc_handler = proc_dohung_task_detect_count,
},
{
.procname = "hung_task_sys_info",
--
2.51.0
Hi Aaron, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master v6.19-rc1 next-20251215] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Aaron-Tomlin/hung_task-Consolidate-hung-task-warning-into-an-atomic-log-block/20251211-113605 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20251211033004.1628875-3-atomlin%40atomlin.com patch subject: [PATCH v2 2/2] hung_task: Enable runtime reset of hung_task_detect_count config: x86_64-rhel-9.4-ltp (https://download.01.org/0day-ci/archive/20251215/202512150521.53lGwfu6-lkp@intel.com/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251215/202512150521.53lGwfu6-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202512150521.53lGwfu6-lkp@intel.com/ All warnings (new ones prefixed by >>): Warning: kernel/hung_task.c:390 function parameter 'table' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'write' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'buffer' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'lenp' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'ppos' not described in 'proc_dohung_task_detect_count' -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi Aaron, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master next-20251211] [cannot apply to v6.18] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Aaron-Tomlin/hung_task-Consolidate-hung-task-warning-into-an-atomic-log-block/20251211-113605 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20251211033004.1628875-3-atomlin%40atomlin.com patch subject: [PATCH v2 2/2] hung_task: Enable runtime reset of hung_task_detect_count config: s390-randconfig-001-20251211 (https://download.01.org/0day-ci/archive/20251211/202512112355.FQD4j4e8-lkp@intel.com/config) compiler: s390-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251211/202512112355.FQD4j4e8-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202512112355.FQD4j4e8-lkp@intel.com/ All warnings (new ones prefixed by >>): >> Warning: kernel/hung_task.c:390 function parameter 'table' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'write' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'buffer' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'lenp' not described in 'proc_dohung_task_detect_count' >> Warning: kernel/hung_task.c:390 function parameter 'ppos' not described in 'proc_dohung_task_detect_count' -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
On 2025/12/11 11:30, Aaron Tomlin wrote:
> Introduce support for writing to /proc/sys/kernel/hung_task_detect_count.
>
> Writing any value to this file atomically resets the counter of detected
> hung tasks to zero. This grants system administrators the ability to clear
> the cumulative diagnostic history after resolving an incident, simplifying
> monitoring without requiring a system restart.
>
> Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
> ---
> Documentation/admin-guide/sysctl/kernel.rst | 2 +-
> kernel/hung_task.c | 30 +++++++++++++++++++--
> 2 files changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
> index 239da22c4e28..43c17b919969 100644
> --- a/Documentation/admin-guide/sysctl/kernel.rst
> +++ b/Documentation/admin-guide/sysctl/kernel.rst
> @@ -418,7 +418,7 @@ hung_task_detect_count
> ======================
>
> Indicates the total number of tasks that have been detected as hung since
> -the system boot.
> +the system boot. The counter can be reset to zero when written to.
>
> This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
>
> diff --git a/kernel/hung_task.c b/kernel/hung_task.c
> index 6f3fb26378b5..979b7e2fcc19 100644
> --- a/kernel/hung_task.c
> +++ b/kernel/hung_task.c
> @@ -377,6 +377,32 @@ static long hung_timeout_jiffies(unsigned long last_checked,
> }
>
> #ifdef CONFIG_SYSCTL
> +
> +/**
> + * proc_dohung_task_detect_count - proc handler for hung_task_detect_count
> + *
> + * Handles read access for the hung task counter. For write access, it
> + * accepts any successfully parsed value and atomically resets the counter
> + * to zero. Returns the byte count written on success or a negative error
> + * code on failure.
> + */
> +static int proc_dohung_task_detect_count(const struct ctl_table *table, int write,
> + void *buffer, size_t *lenp, loff_t *ppos)
> +{
> + int ret;
> +
> + if (!write)
> + return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
> +
> + ret = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
Since the intent is "any write resets to zero", we could skip parsing
the input entirely (untested):
WRITE_ONCE(sysctl_hung_task_detect_count, 0);
*ppos += *lenp;
return 0;
See vmstat_refresh() for a similar pattern :)
> + if (ret)
> + return ret;
> +
> + WRITE_ONCE(sysctl_hung_task_detect_count, 0);
> +
> + return ret;
> +}
Cheers,
Lance
> +
> /*
> * Process updating of timeout sysctl
> */
> @@ -459,8 +485,8 @@ static const struct ctl_table hung_task_sysctls[] = {
> .procname = "hung_task_detect_count",
> .data = &sysctl_hung_task_detect_count,
> .maxlen = sizeof(unsigned long),
> - .mode = 0444,
> - .proc_handler = proc_doulongvec_minmax,
> + .mode = 0644,
> + .proc_handler = proc_dohung_task_detect_count,
> },
> {
> .procname = "hung_task_sys_info",
On Thu, Dec 11, 2025 at 01:14:38PM +0800, Lance Yang wrote: > Since the intent is "any write resets to zero", we could skip parsing > the input entirely (untested): > > WRITE_ONCE(sysctl_hung_task_detect_count, 0); > *ppos += *lenp; > return 0; > Hi Lance, Acknowledged. I will simply test for a 'write' operation. Kind regards, -- Aaron Tomlin
© 2016 - 2025 Red Hat, Inc.