hung_task: Migrate hung_task_detect_count to sysfs
Subsystems (2)
PATCH 1/1 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.
--- .../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
Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count new file +7 -0
@@ -0,0 +1,7 @@ +What: /sys/kernel/hung_task_detect_count +Date: Nov 2025 +KernelVersion: 6.18 +Contact: Linux kernel mailing list <[email protected]> +Description: + Indicates the total number of tasks that have been detected as hung since + the system boot.
Documentation/admin-guide/sysctl/kernel.rst +0 -9
@@ -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 ======================
kernel/hung_task.c +24 -18
60 lines not on this page · raw message
Signature · 1 line
2.51.0
Lance Yang
maintainerHi Aaron,
Thanks for the patch.
Quoted 7 lines · Aaron Tomlin
The
hung_task_detect_countmetric, which tracks the cumulative number of tasks detected as hung since boot, is currently exposed via the legacy/proc/sys/kernel/hung_task_detect_countsysctl 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 theCONFIG_SYSFSKconfigoption.
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
Quoted 9 lines · Lance Yang
Hi Aaron,
Thanks for the patch.
Quoted 4 lines · Aaron Tomlin
The
hung_task_detect_countmetric, which tracks the cumulative number of tasks detected as hung since boot, is currently exposed via the legacy/proc/sys/kernel/hung_task_detect_countsysctl file.
Quoted 5 lines
Quoted 3 lines
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 theCONFIG_SYSFSKconfigoption.Emm, I don't think we should do this :)
I agree, because:
Quoted 2 lines
Removing the sysctl file is going to break userspace tools that currently read it ...
We can't do that.
thanks,
greg k-h
Quoted 1 line · Lance Yang
Hi Aaron,
Hi Lance,
Quoted 1 line
Thanks for the patch.
No problem.
Quoted 4 lines
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,
Signature · 1 line
Aaron Tomlin
Lance Yang
maintainerQuoted 32 lines · Aaron Tomlin
Quoted 1 line · Lance Yang
Hi Aaron,
Hi Lance,
Quoted 1 line
Thanks for the patch.
No problem.
Quoted 4 lines
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.
Quoted 8 lines
2. Graceful Migration Path: By adding the
/sys/kernel/hung_task_detect_countentry first (as a read-only counter) and keeping the legacy/proc/sys/kernel/hung_task_detect_countfile 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.
Quoted 1 line
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
Quoted 10 lines · Lance Yang
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.
Quoted 1 line
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!
Hi Lance,
I completely understand.
Kind regards,
Signature · 1 line
Aaron Tomlin