.../sysfs-kernel-hung_task_detect_count | 7 ++++ Documentation/admin-guide/sysctl/kernel.rst | 9 ---- kernel/hung_task.c | 42 +++++++++++-------- 3 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count
The hung_task_detect_count metric, which tracks the cumulative number of
tasks detected as hung since boot, is currently exposed via the legacy
/proc/sys/kernel/hung_task_detect_count sysctl file.
Migrate this metric to a read-only file in the /sys/kernel/ hierarchy:
/sys/kernel/hung_task_detect_count. The sysctl file is removed, and the
metric is now controlled by the CONFIG_SYSFS Kconfig option.
This patch is made to continue the effort of moving read-only
statistics and counters out of the /proc/sys/ hierarchy and into the
more appropriate /sys filesystem. The internal variable is renamed from
sysctl_hung_task_detect_count to hung_task_detect_count and its
increment logic is updated to use the more efficient prefix form.
The documentation is updated to reflect the removal of the sysctl entry.
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
.../sysfs-kernel-hung_task_detect_count | 7 ++++
Documentation/admin-guide/sysctl/kernel.rst | 9 ----
kernel/hung_task.c | 42 +++++++++++--------
3 files changed, 31 insertions(+), 27 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count
diff --git a/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count b/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count
new file mode 100644
index 000000000000..92ee79ccfe6d
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count
@@ -0,0 +1,7 @@
+What: /sys/kernel/hung_task_detect_count
+Date: Nov 2025
+KernelVersion: 6.18
+Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
+Description:
+ Indicates the total number of tasks that have been detected as hung since
+ the system boot.
diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index f3ee807b5d8b..4d9b7b18712f 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -413,15 +413,6 @@ The upper bound on the number of tasks that are checked.
This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
-hung_task_detect_count
-======================
-
-Indicates the total number of tasks that have been detected as hung since
-the system boot.
-
-This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled.
-
-
hung_task_timeout_secs
======================
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index b2c1f14b8129..8f4371ac6837 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -32,10 +32,27 @@
*/
static int __read_mostly sysctl_hung_task_check_count = PID_MAX_LIMIT;
-/*
- * Total number of tasks detected as hung since boot:
- */
-static unsigned long __read_mostly sysctl_hung_task_detect_count;
+#ifdef CONFIG_SYSFS
+/* Total number of tasks detected as hung since boot */
+static unsigned long hung_task_detect_count;
+
+static ssize_t hung_task_detect_count_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *page)
+{
+ return sysfs_emit(page, "%lu\n", hung_task_detect_count);
+}
+
+static struct kobj_attribute hung_task_detect_count_attr = __ATTR_RO(hung_task_detect_count);
+
+static __init int kernel_hung_task_detect_sysfs_init(void)
+{
+ sysfs_add_file_to_group(kernel_kobj,
+ &hung_task_detect_count_attr.attr, NULL);
+ return 0;
+}
+late_initcall(kernel_hung_task_detect_sysfs_init);
+#endif
/*
* Limit number of tasks checked in a batch.
@@ -222,13 +239,9 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
{
if (!task_is_hung(t, timeout))
return;
-
- /*
- * This counter tracks the total number of tasks detected as hung
- * since boot.
- */
- sysctl_hung_task_detect_count++;
-
+#ifdef CONFIG_SYSFS
+ ++hung_task_detect_count;
+#endif
trace_sched_process_hang(t);
if (sysctl_hung_task_panic) {
@@ -423,13 +436,6 @@ static const struct ctl_table hung_task_sysctls[] = {
.proc_handler = proc_dointvec_minmax,
.extra1 = SYSCTL_NEG_ONE,
},
- {
- .procname = "hung_task_detect_count",
- .data = &sysctl_hung_task_detect_count,
- .maxlen = sizeof(unsigned long),
- .mode = 0444,
- .proc_handler = proc_doulongvec_minmax,
- },
};
static void __init hung_task_sysctl_init(void)
--
2.51.0
Hi Aaron, Thanks for the patch. On 2025/11/30 07:51, Aaron Tomlin wrote: > The hung_task_detect_count metric, which tracks the cumulative number of > tasks detected as hung since boot, is currently exposed via the legacy > /proc/sys/kernel/hung_task_detect_count sysctl file. > > Migrate this metric to a read-only file in the /sys/kernel/ hierarchy: > /sys/kernel/hung_task_detect_count. The sysctl file is removed, and the > metric is now controlled by the CONFIG_SYSFS Kconfig option. Emm, I don't think we should do this :) Removing the sysctl file is going to break userspace tools that currently read it ... And, yeah, while moving read-only stats to sysfs makes sense on paper, is it really worth the churn? Since we'd likely have to keep the old sysctl file anyway for backward compatibility, we'd just end up maintaining two interfaces fo the exact same counter :) [...] Thanks anyway, Lance
On Sun, Nov 30, 2025 at 01:43:51PM +0800, Lance Yang wrote:
> Hi Aaron,
Hi Lance,
> Thanks for the patch.
No problem.
> Emm, I don't think we should do this :)
>
> Removing the sysctl file is going to break userspace tools that
> currently read it ...
Thank you for your feedback. I appreciate the concern regarding user-space
compatibility and the potential maintenance overhead of dual interfaces.
I agree that removing the sysctl entry entirely right now is too
disruptive, as it would immediately break existing user-space tools relying
on /proc/sys/kernel/hung_task_detect_count. Your point about avoiding
unnecessary churn and maintaining two interfaces is well-taken.
However, I believe that moving the counter to sysfs is still a worthwhile
long-term goal for the following reasons:
1. Consistency and standardisation: Moving read-only counters to
/sys/kernel/ aligns with current kernel conventions and provides a
more consistent location for performance and diagnostic metrics.
This follows the pattern of existing counters like
/sys/kernel/softlockup_count.
2. Graceful Migration Path: By adding the
/sys/kernel/hung_task_detect_count entry first (as a read-only
counter) and keeping the legacy
/proc/sys/kernel/hung_task_detect_count file in place, we provide
the necessary backwards compatibility and offer a grace period for
user-space tools to migrate. The old sysctl file can then be flagged
for deprecation in a future release.
I am currently working on some additional updates for kernel/hung_task.c.
I believe integrating the sysfs entry now, while I am already touching this
file, would be an efficient and worthwhile start.
My proposal is to modify the patch to add the sysfs entry while preserving
the existing sysctl entry for the immediate future. If you agree that this
phased migration is a worthwhile endeavor, I will prepare and submit a v2
patch that implements this dual-interface approach.
Please let me know your thoughts on this approach for phased migration.
Thanks,
--
Aaron Tomlin
On 2025/12/1 01:11, Aaron Tomlin wrote: > On Sun, Nov 30, 2025 at 01:43:51PM +0800, Lance Yang wrote: >> Hi Aaron, > > Hi Lance, > > >> Thanks for the patch. > > No problem. > >> Emm, I don't think we should do this :) >> >> Removing the sysctl file is going to break userspace tools that >> currently read it ... > > Thank you for your feedback. I appreciate the concern regarding user-space > compatibility and the potential maintenance overhead of dual interfaces. > > I agree that removing the sysctl entry entirely right now is too > disruptive, as it would immediately break existing user-space tools relying > on /proc/sys/kernel/hung_task_detect_count. Your point about avoiding > unnecessary churn and maintaining two interfaces is well-taken. > > However, I believe that moving the counter to sysfs is still a worthwhile > long-term goal for the following reasons: > > 1. Consistency and standardisation: Moving read-only counters to > /sys/kernel/ aligns with current kernel conventions and provides a > more consistent location for performance and diagnostic metrics. > This follows the pattern of existing counters like > /sys/kernel/softlockup_count. > > 2. Graceful Migration Path: By adding the > /sys/kernel/hung_task_detect_count entry first (as a read-only > counter) and keeping the legacy > /proc/sys/kernel/hung_task_detect_count file in place, we provide > the necessary backwards compatibility and offer a grace period for > user-space tools to migrate. The old sysctl file can then be flagged > for deprecation in a future release. > Deprecating established sysctl ABIs is often a very long process(sometimes indefinite) ... and I would prefer to avoid introducing redundancy unless strictly necessary or the current interface is functionally deficient :) So, it's a NACK from my side regarding the interface migration. > I am currently working on some additional updates for kernel/hung_task.c. Please let's keep it simple and leave the interface as is. I look forward to your other updates for hung_task.c! [...] Thanks, Lance
On Sun, Nov 30, 2025 at 01:43:51PM +0800, Lance Yang wrote: > Hi Aaron, > > Thanks for the patch. > > On 2025/11/30 07:51, Aaron Tomlin wrote: > > The hung_task_detect_count metric, which tracks the cumulative number of > > tasks detected as hung since boot, is currently exposed via the legacy > > /proc/sys/kernel/hung_task_detect_count sysctl file. > > > > Migrate this metric to a read-only file in the /sys/kernel/ hierarchy: > > /sys/kernel/hung_task_detect_count. The sysctl file is removed, and the > > metric is now controlled by the CONFIG_SYSFS Kconfig option. > > Emm, I don't think we should do this :) I agree, because: > Removing the sysctl file is going to break userspace tools that > currently read it ... We can't do that. thanks, greg k-h
© 2016 - 2025 Red Hat, Inc.