From nobody Mon Dec 1 22:36:16 2025 Received: from CWXP265CU008.outbound.protection.outlook.com (mail-ukwestazon11020103.outbound.protection.outlook.com [52.101.195.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DBE124EA90 for ; Sat, 29 Nov 2025 23:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.195.103 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764460332; cv=fail; b=DETsYunmwls1g2xN8llevzNd15TEOiF335LOREDLWmtTnmp2sK37D4iappz4TBzzVohQK/VnCFSr38428ImWePiOImgaQvhU0cs9ooQ2TVWDYxIMxDZ1F2LNumxRgkxmgT4qObHF6jKnMh08y3PgWbRM38xePcVQdw0ax8aSfYs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764460332; c=relaxed/simple; bh=T9rQSaTaCmcetPJnmenX91WQ96JUv2e9uLF6Fhl0Prw=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=kqx/9CEwHs/aD50BXTmAsbjU/ae4MYLJGln5lj1WzfvLW4dBYXlUZbJ+W1Rd08NBJbM89vYTFn0KTf/9xa4E5LanDLUOjwHxA1ZGhlp/nFTAaz019nZycBaaf0YNqKxMklp4y+AXxLa59PH2GYNtgjvlc9rYIGZfFNYS3HA2oBw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomlin.com; spf=pass smtp.mailfrom=atomlin.com; arc=fail smtp.client-ip=52.101.195.103 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=atomlin.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uO8mvpem+tOAK4Aqyia65LhLpvBfylem0ff/YMNm62YQJt0xINyIiw9sWdiKQuTt/rFAImmfjlNNmNDYIh4aypr+CGI8JUZO1ZIPE8c3MmUU/+ryq2n6kfx2UspNUfRv29BMoLW8Dajz5Yfn8uBPLmqwpbPDTJvE9lJRuQsXhqQ87plGZ20svq61K/yTyulaFwqUWKAtz+1EoK9cadjn6K6TdimNn3BksGckUnWdUPqx/uFTEfwswRs0W0sExJgp9Va+qJLdbcjEWiTqLIHpeo/lNHJtgKxLg/mj+jtuAIgagjwCCWKQ92+geKooPn5SfrvtB/LbdqTKuv39AbBEmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ll8Tf27v5ojF+msy3Nr1Q2/dScuy7P61TCbEfYIz5cw=; b=y+W7SFOHOeM/7uRPS/BfVceRdA8zZe4LOzixu5pkUBHm1vBRhGttJFiLS/myhSBFQbALEftUeYoHuconUJL0cBHmTVEMTNJcAXasTzHVT5jzq4Ldh3MyDX3NtsLVKUtBRzhvyY/8tiPMTjbzIN492f0wUNvU55Mkm13zUQ2mag0N4sNGymvR6/WCmR2sqnNKjf1fOdlO1/SvIZUkMkkvJh4dZmuN6qP0pCeH5K+fJMCZ8r12UT0107mOen9nQDK9Wifr3ecJT3go2oJ7tK2SDXSlePlxeaqm918eFQhQZ9IMT4cLaRtU+x0JHFBcRNoLWuBSSDcSPWODygMTsaAbjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=atomlin.com; dmarc=pass action=none header.from=atomlin.com; dkim=pass header.d=atomlin.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=atomlin.com; Received: from CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:70::10) by LO2P123MB3598.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:12d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9366.17; Sat, 29 Nov 2025 23:52:04 +0000 Received: from CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf]) by CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf%5]) with mapi id 15.20.9366.012; Sat, 29 Nov 2025 23:52:04 +0000 From: Aaron Tomlin To: akpm@linux-foundation.org, lance.yang@linux.dev, mhiramat@kernel.org, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] hung_task: Migrate hung_task_detect_count to sysfs Date: Sat, 29 Nov 2025 18:51:59 -0500 Message-ID: <20251129235159.1227977-1-atomlin@atomlin.com> X-Mailer: git-send-email 2.51.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9P221CA0005.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::28) To CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:70::10) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CWLP123MB3523:EE_|LO2P123MB3598:EE_ X-MS-Office365-Filtering-Correlation-Id: 28bbbc1b-e125-4243-633b-08de2fa24bf4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Q3hQbXsTWW3YvQ5eTKSMuBZLna1TvEi+f17szZPox2xpV6UYqsKEpI1uYtWs?= =?us-ascii?Q?DzebfFkWiKiUOcg3eqy2/7s9095gtsGNXmwJVo/vW9u+IycikQU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HGh9Obw/di8ICrAnyyY3mssdh2PwzLDa4s2RhcxUrG8esg?= =?us-ascii?Q?N8KSNsK4f/Wz+WQHDrV4CCRrcqpRbFC9rxDyAaLaUdsC09qFgdF+ID+3vddt?= =?us-ascii?Q?5+NNB4U6VW/MLVP6ny3I0p4YR8UfiDkjLgcgfn//ll3vdywjm3wtO+0Z1wNh?= =?us-ascii?Q?JR0mnfhILi8TElL6HxaMPshPcOGm+UJO8CFQNuBe9pqgM+SKmZXo/UyqWFq+?= =?us-ascii?Q?vcy5R/mz1z63XknrimyZ1RaN/iAjD1PSV+Hh3hQZi8Bv01Rde/+oHN2wORbn?= =?us-ascii?Q?wD1xju20z3Q+KSLrvNRqPODFCCnNrutJRT6laY/ntyiFDKknPqZvFggfiggh?= =?us-ascii?Q?suaa0U3VXjB4ZTVP6E9lfcjJUVq1EjTybktPgm4BgM1d8C+RupoQOpMrZEkO?= =?us-ascii?Q?WTt4HBWuZug62WvQa7GY/rFCXzaXG1sBeT0ZUjVq8MapGK7SEFSQl7dktMKA?= =?us-ascii?Q?jHu3EwgZy9XcmOYoiFqzPH/cgWADJqd5?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?nSF1iLqpC+cURqFklSQNRmajOgXClb0dTQSDAwE3iPP7RS6eBAYkoinBZwm0?= =?us-ascii?Q?meVpBYVf956BoguPX+/LO9f+P6vgeWt1n/jOVqZWLh+UX3pQKCAeKdiQ54Xd?= =?us-ascii?Q?672WTpodzp87+grMWZDUUDNr0NxewNcURTWVWx38tZfqp2GuNd117iHwDgOg?= =?us-ascii?Q?LYWzmxo9I8vERtgng1aM69CBMyYL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Q?Sua+kSiwFt4izeV4p6UAbIvLq8tYJ9tvLB37pDwaqLudw8ZnNUMXeTOtpCLy?= =?us-ascii?Q?YQEpBGy9cXic6Fahf2GwXic65fMtgSCbwU012VxcJFKWKmCtOQMbLFr0x9Oy?= =?us-ascii?Q?tfA+qN9oC357nKDxQLrYjr5tENOlFDZwnKeMKMK9CSV3X+NdrV++GgwetwTu?= =?us-ascii?Q?xtNmlkJxuWwKcuDI6NE79a6ML8WXzIajMjeBnHrXWOvtgaxPZMm7cK2539FD?= =?us-ascii?Q?mvSQ0tOP6WhWDtj9w4W15Ot6rOdmZz14R7Db2S+hfDM8BlFbRgKTHsV5OFl8?= =?us-ascii?Q?5DA41f6hEqQPGQI5gVs3AK/sE2xR+i4JGr1yo5eTU54vJdOqoqLy4Vwll7Ri?= =?us-ascii?Q?0tUTFGKmxXN449FVH+s5Qd9B5OghiTPwnZHlMzu2i3qFmtBvc3TNNaKtr8nG?= =?us-ascii?Q?Q0bomBggDfR4sO+G8GFgCmR1VMWDk91jg+bE3yyNxnEDf139CqLy0ALx/QBm?= =?us-ascii?Q?q6b1rzLYZNsOCatkLsr416V2INiJciCb4JzkOYmu?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28bbbc1b-e125-4243-633b-08de2fa24bf4 X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2025 23:52:04.1382 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e6a32402-7d7b-4830-9a2b-76945bbbcb57 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: l0N8GjwbHi74GKmmGqVqWuYx7jLaWrhPHOOU14lwN/2vjPzKRE5RJjq/gUZvWLW7eiEihuVFsRFVsgg1x0e46g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO2P123MB3598 Content-Type: text/plain; charset="utf-8" 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 --- .../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 +Description: + Indicates the total number of tasks that have been detected as hun= g since + the system boot. diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-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 checke= d. This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. =20 =20 -hung_task_detect_count -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 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 =3D PID_MAX_LIMIT; =20 -/* - * 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 =3D __ATTR_RO(hun= g_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 =20 /* * Limit number of tasks checked in a batch. @@ -222,13 +239,9 @@ static void check_hung_task(struct task_struct *t, uns= igned 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); =20 if (sysctl_hung_task_panic) { @@ -423,13 +436,6 @@ static const struct ctl_table hung_task_sysctls[] =3D { .proc_handler =3D proc_dointvec_minmax, .extra1 =3D SYSCTL_NEG_ONE, }, - { - .procname =3D "hung_task_detect_count", - .data =3D &sysctl_hung_task_detect_count, - .maxlen =3D sizeof(unsigned long), - .mode =3D 0444, - .proc_handler =3D proc_doulongvec_minmax, - }, }; =20 static void __init hung_task_sysctl_init(void) --=20 2.51.0