[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251129235159.1227977-1-atomlin@atomlin.com>
Date: Sat, 29 Nov 2025 18:51:59 -0500
From: Aaron Tomlin <atomlin@...mlin.com>
To: akpm@...ux-foundation.org,
lance.yang@...ux.dev,
mhiramat@...nel.org,
gregkh@...uxfoundation.org
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] hung_task: Migrate hung_task_detect_count to sysfs
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@...mlin.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@...r.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
Powered by blists - more mailing lists