From nobody Mon Feb 9 01:46:41 2026 Received: from LO2P265CU024.outbound.protection.outlook.com (mail-uksouthazon11021113.outbound.protection.outlook.com [52.101.95.113]) (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 B4D47322B81 for ; Sun, 25 Jan 2026 13:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.95.113 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769349545; cv=fail; b=Tw8YHBRuj85QNettKY7cMsaQ8LJSmtW3dJycq5Adl3Or0PVC3xPVUClEWcQo2aVI/tEhAGK3uC7YwPiQJqwh/lwwPlygFKAnKwWtXiv499LLvry8p3Fq3vEzFBL4QWWJiWGN+6b55/ReYeBAq030YTPKHz8SIoTrNAYA7UPBl38= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769349545; c=relaxed/simple; bh=9mggJ9yoFJB9oOmSVml7iHsl5vtyjmuK1xbPlf4yOc8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=dbvhRYJWNIgcVF7svXiKcqCIBSSPjW9yo3CRRNXm/M9W++h+hCPBjCt9nGcJmD49G/5ceSa0tC2S1NlNOsCh+u23ZGLp3F6AqQC88WUxnS+vn+/EfwYXWKG+7AfFAqyOuuTEIZIKelQ3jXWA0OiRkewzbUwdo7hMXyKyh8dg0hU= 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.95.113 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=RTgIcKehE97EprnBStNmYnz37y/p/aYyDRXvSk/v4Is+6YxQcdn3xOaOlFnjHgNtKCwq0XY57dDCAkG2y16athAVCSUaTdVFx8VmZr7+qV7mI+TIBL1ldfIN0a+5X0kBy6mxNFyyhAUR9La+/CoOud/LgN9fdR6KL5VvD7WCRpomnsp3MX57WwBGEyZl+ejVDPQBZok5gvOJexrRqBQQLFfKEnVKjPJ4cCOx2qfgUWCrwbyopDk+k7FnTVSaR6jYbQRkJTRFTq1/bBYkadB6i+xSKugzd6kgp6TyqyIb9b5ayO8ndHkFmnfoaZUzJeTt3k2o8IGTLD2HGHLUmkop9g== 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=M2k1WB6FQJO2ebxCbiWDUW5UP8aYAJ/Zbj+swrh/URs=; b=zIzs8yeqAV4mhQygqF+MU9vOQDxUaL1cdHHgWihery5CAolsea3joiurmJCcJCpKf/uZcUQPBHPY4/FALS6q35bK9ioNmQIXLPPGaMEVOJYFS1llwBcSm4cMkDAn+2MvFV0sMBZaTGFGBZTUTe277zoXxjx7kJeODlYmxjGGxrJs4H5fZ0vaEfb/Tqkmosg7CPg2rY0VbR8TSOFjO++xf1Zcg2u0wauvjW/T130uccq+z2Fwvr5/w7TEPEzq2oFRlXpFcWz6NnD1CkwLLQyFJKjeGDAe7jp5vgq6lOHaMU7vmbG7Q2xIVub7T+kVXTU/oEQeHP3+SaZpaivWe16aTg== 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 LOYP123MB3104.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:e2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.9; Sun, 25 Jan 2026 13:59:00 +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.9542.010; Sun, 25 Jan 2026 13:59:00 +0000 From: Aaron Tomlin To: akpm@linux-foundation.org, lance.yang@linux.dev, mhiramat@kernel.org, gregkh@linuxfoundation.org, pmladek@suse.com, joel.granados@kernel.org Cc: neelx@suse.com, sean@ashe.io, mproche@gmail.com, chjohnst@gmail.com, nick.lange@gmail.com, linux-kernel@vger.kernel.org Subject: [v7 PATCH 1/2] hung_task: Refactor detection logic and atomicise detection count Date: Sun, 25 Jan 2026 08:58:47 -0500 Message-ID: <20260125135848.3356585-2-atomlin@atomlin.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260125135848.3356585-1-atomlin@atomlin.com> References: <20260125135848.3356585-1-atomlin@atomlin.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0544.namprd03.prod.outlook.com (2603:10b6:408:138::9) 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_|LOYP123MB3104:EE_ X-MS-Office365-Filtering-Correlation-Id: c289cda8-8d55-4163-9744-08de5c19e3bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bloAEoRVLPJWktIgvgIJuKSn3CAiFAlRPq3TIwHOaeVmQuL9VXEY8mhK6JL+?= =?us-ascii?Q?wQ1+hcr9nZtcG/PUuWGKaew3JadnOMXXoI8gMSERGKUJdN2RSENzMBEg/rrF?= =?us-ascii?Q?OKogMUbnSVPH13/2K0yk79MK/m3bEOR7asW2S6BMvpe9UcV0vGzSYoh2PUXs?= =?us-ascii?Q?w++znARJSh8Xt8zOXRaxchFQY5EVeGWwrlLp0t4/DZSxMQa4rJC3FLX08TLu?= =?us-ascii?Q?o72quT8ijmRK/oBND+NTauGa606DGTt9Njwn0Nv30OrXoBxlc9oQJVJ300dK?= =?us-ascii?Q?wr7FibhqFNLkvlGN8CxKy2xgZokdpuDMR+p8G2FfRcB9o9epduxksP1gno4M?= =?us-ascii?Q?xYqfkQsmSM1pxIlKYtFPKI+8PRZnhYepDTghWZpe15Hgh/HugoM5McJqn7Kz?= =?us-ascii?Q?WYbdOopJKEwybJhsrw0hXgRuumwd64DuJpRiLNTMNTTnMj9min7C61z38Aud?= =?us-ascii?Q?wbkCRw1LKFvi9HWN8e73u9a3VJBSsOMrn7d2JA0lq+d9/M/zhjqFcWt5e/fe?= =?us-ascii?Q?9N/w01N+QA/Ea/zt9eo4CYdm5pUsZQ74uQlN9fTnuqdZTQAaUljVmO7bl6rh?= =?us-ascii?Q?x4fG4zvYaIEVU8njICVjNKQBDC5aY1KyZNJSGlwkVWyB+UdhPW+HuXJWgat6?= =?us-ascii?Q?e46Q5n2DM2za3cbPF+V199BfyZ4PGCqbslO+NN6+EgfWioYgTwEulqiIKojG?= =?us-ascii?Q?X8ZPRvBU5U1m7evhcZOA9fIryh9C4ve+W18/fV+gQzUC5lwbAIuMtm2lKIGN?= =?us-ascii?Q?IkBE/4dr8VSlSjhOL5uUsyiZZet+dW5I5uLkDZgI0C9KRdCQjoGgpKgyzgwL?= =?us-ascii?Q?fWbGC03CggZTt+0tanmttE/Xwxf6fsJmEWd6DqLpDD9VRG0PhVASwv1mqi3v?= =?us-ascii?Q?yNA4bWpXrjyjE3+uKNpLPs1GpgLjEC/5GWtKZanTaFLRPcq3cyI8KkKS6Evw?= =?us-ascii?Q?YjfTWuiFoUiXIZc+/nRWkL6mfX/XvPqSK6e7dkcSvyJCuHRSm5+v5AoY108e?= =?us-ascii?Q?ErbvpsMro+mwymhceMwRusvm9NGHF1tHCwKXNmc5pTpIz+UwzSLwoS2GUfJo?= =?us-ascii?Q?8ZLBhXLOxMqmAN4KWSDXikwdnB0U1ilK48AR3O3iyXeUK7tr286gKhNYFFT1?= =?us-ascii?Q?vl0JaXLjg1xdqW/ETL13KBaDu3oJ2FOcKgel7HZSPoDI7n2d/hGkXk6kpGd9?= =?us-ascii?Q?pi0RGIELv3K1EqTebYEiIA+jJFuhPo2uh8BCFpuSM/sfwi0cPj2kCIA9ars6?= =?us-ascii?Q?VtOdksiGohACYapCstf6dVgnIFNyobDwKLyYVcr8V35k87SnVxJGYr7svgtB?= =?us-ascii?Q?JKbQ1bbG/mesNyS4ljGYPEG1TBOZc6fns5ly2Un/eOwFbqWOaH5MVVbswf7m?= =?us-ascii?Q?WvNDVghlCXkydnHiQvm2ZOiReZ8tgMintc11CM2OxVw+jhkWMTKmTpYk2jdd?= =?us-ascii?Q?FLTKBk0I95HlfCQV7aey/uDC5SDC7rEOgQ9fBztZN6eKDVJ5T3jVJ3ICWjSq?= =?us-ascii?Q?9ug+LK7jk5Q5mGGjdorhjlMY/v78L3oCXGLohcofFLzatAee+HTaORYIYB7Y?= =?us-ascii?Q?HAYqC7oNblnM0OFi1eI=3D?= 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)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0mBd7ZT/4XkJbo2kQ/VdC8EvN7Nwcpno2HKgTkhnOPGLJXVq1XmwNbRmh27W?= =?us-ascii?Q?HcSPcd9EcQNSrhPUEzf450FstdC6ilFpKl29Vx4oLjy18iGO2rw26Xz5kgxJ?= =?us-ascii?Q?Pd/xiK6Or+9hIzo0C92dEmVhzIqMgTvIt4/z5w3iE0rwzHr0wLW4zDalq1u4?= =?us-ascii?Q?Biq7qLzGn+gjzlsN7EhuFMiaR4NAfr7+hqOQtlTabw34NOHTW2fdaoffq2v6?= =?us-ascii?Q?3q4CEShWtLpHdtxwnfj9GHOb6kH5T2kHtapKLNBWk5FSGFe+8Y34rOdMKm1E?= =?us-ascii?Q?PghEmhVy1o05OeMZ4YXE493J7/KCwiPGluULKpjmmPgIl/oWkoDANOe9CSHw?= =?us-ascii?Q?Pao35iRxKSi+2iPvdL4SN4vS4v+CyUEdPuzRjQ1LN8y9iTyivXKlmVMFXBY9?= =?us-ascii?Q?VsXGryA4HcUIrCqGedEtVd1KgXXzGjyzX+RIvsd9d1GSTvVLPYvU6JdpTDwL?= =?us-ascii?Q?cNIKXkZewEU7l6nOQi5iAIML5OilVWf649hElMsChitfvy1WKAGmq8m9+f2V?= =?us-ascii?Q?xruR14tCOLqtZPVjUIP0x0/V/ZiYIs1snnqgtnVoLMWWSJfX40N9EWMbXezX?= =?us-ascii?Q?OkNBiZoYgtKskMA5l2sKNPKfmUPDKPy9W8aYdexdiWBB3exEoGuY1h3SUEsT?= =?us-ascii?Q?3FAGCjW3bJZ4jz1pcy9HMSKPTbcACp8gvoC3Cfz+zcv4CKmsTafF8xsDzscg?= =?us-ascii?Q?X6174KGdFcJIECMTJKMNpN08Ny0HoQhex/dlytv2gpSMMdZwjtHY3Exa9RLq?= =?us-ascii?Q?lDnC923bI7dZsKO35+JkOvaXjd0H7CDKZl2vN2+39JOMXdZGI45qu/iseqcD?= =?us-ascii?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OJmbbQOrtzk?= =?us-ascii?Q?IrQid5JPNQ=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: c289cda8-8d55-4163-9744-08de5c19e3bc X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2026 13:59:00.0343 (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: kFSNnkQnrQ0n45i2UHgcMXeucy68xmy1zpIZ4K0ogamXPCoEeVzBq33oFzvWQyx/4IIB7TKjCQIbbKbfe17dkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LOYP123MB3104 Content-Type: text/plain; charset="utf-8" The check_hung_task() function currently conflates two distinct responsibilities: validating whether a task is hung and handling the subsequent reporting (printing warnings, triggering panics, or tracepoints). This patch refactors the logic by introducing hung_task_info(), a function dedicated solely to reporting. The actual detection check, task_is_hung(), is hoisted into the primary loop within check_hung_uninterruptible_tasks(). This separation clearly decouples the mechanism of detection from the policy of reporting. Furthermore, to facilitate future support for concurrent hung task detection, the global sysctl_hung_task_detect_count variable is converted from unsigned long to atomic_long_t. Consequently, the counting logic is updated to accumulate the number of hung tasks locally (this_round_count) during the iteration. The global counter is then updated atomically via atomic_long_cmpxchg_relaxed() once the loop concludes, rather than incrementally during the scan. These changes are strictly preparatory and introduce no functional change to the system's runtime behaviour. Signed-off-by: Aaron Tomlin Reviewed-by: Masami Hiramatsu (Google) Reviewed-by: Petr Mladek --- kernel/hung_task.c | 58 ++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/kernel/hung_task.c b/kernel/hung_task.c index d2254c91450b..df10830ed9ef 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -36,7 +36,7 @@ static int __read_mostly sysctl_hung_task_check_count =3D= PID_MAX_LIMIT; /* * Total number of tasks detected as hung since boot: */ -static unsigned long __read_mostly sysctl_hung_task_detect_count; +static atomic_long_t sysctl_hung_task_detect_count =3D ATOMIC_LONG_INIT(0); =20 /* * Limit number of tasks checked in a batch. @@ -223,31 +223,29 @@ static inline void debug_show_blocker(struct task_str= uct *task, unsigned long ti } #endif =20 -static void check_hung_task(struct task_struct *t, unsigned long timeout, - unsigned long prev_detect_count) +/** + * hung_task_info - Print diagnostic details for a hung task + * @t: Pointer to the detected hung task. + * @timeout: Timeout threshold for detecting hung tasks + * @this_round_count: Count of hung tasks detected in the current iteration + * + * Print structured information about the specified hung task, if warnings + * are enabled or if the panic batch threshold is exceeded. + */ +static void hung_task_info(struct task_struct *t, unsigned long timeout, + unsigned long this_round_count) { - unsigned long total_hung_task; - - 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++; - - total_hung_task =3D sysctl_hung_task_detect_count - prev_detect_count; trace_sched_process_hang(t); =20 - if (sysctl_hung_task_panic && total_hung_task >=3D sysctl_hung_task_panic= ) { + if (sysctl_hung_task_panic && this_round_count >=3D sysctl_hung_task_pani= c) { console_verbose(); hung_task_call_panic =3D true; } =20 /* - * Ok, the task did not get scheduled for more than 2 minutes, - * complain: + * The given task did not get scheduled for more than + * CONFIG_DEFAULT_HUNG_TASK_TIMEOUT. Therefore, complain + * accordingly */ if (sysctl_hung_task_warnings || hung_task_call_panic) { if (sysctl_hung_task_warnings > 0) @@ -297,18 +295,18 @@ static bool rcu_lock_break(struct task_struct *g, str= uct task_struct *t) =20 /* * Check whether a TASK_UNINTERRUPTIBLE does not get woken up for - * a really long time (120 seconds). If that happens, print out - * a warning. + * a really long time. If that happens, print out a warning. */ static void check_hung_uninterruptible_tasks(unsigned long timeout) { int max_count =3D sysctl_hung_task_check_count; unsigned long last_break =3D jiffies; struct task_struct *g, *t; - unsigned long prev_detect_count =3D sysctl_hung_task_detect_count; + unsigned long total_count, this_round_count; int need_warning =3D sysctl_hung_task_warnings; unsigned long si_mask =3D hung_task_si_mask; =20 + total_count =3D atomic_long_read(&sysctl_hung_task_detect_count); /* * If the system crashed already then all bets are off, * do not report extra hung tasks: @@ -316,10 +314,9 @@ static void check_hung_uninterruptible_tasks(unsigned = long timeout) if (test_taint(TAINT_DIE) || did_panic) return; =20 - + this_round_count =3D 0; rcu_read_lock(); for_each_process_thread(g, t) { - if (!max_count--) goto unlock; if (time_after(jiffies, last_break + HUNG_TASK_LOCK_BREAK)) { @@ -328,14 +325,25 @@ static void check_hung_uninterruptible_tasks(unsigned= long timeout) last_break =3D jiffies; } =20 - check_hung_task(t, timeout, prev_detect_count); + if (task_is_hung(t, timeout)) { + this_round_count++; + hung_task_info(t, timeout, this_round_count); + } } unlock: rcu_read_unlock(); =20 - if (!(sysctl_hung_task_detect_count - prev_detect_count)) + if (!this_round_count) return; =20 + /* + * This counter tracks the total number of tasks detected as hung + * since boot. + */ + atomic_long_cmpxchg_relaxed(&sysctl_hung_task_detect_count, + total_count, total_count + + this_round_count); + if (need_warning || hung_task_call_panic) { si_mask |=3D SYS_INFO_LOCKS; =20 --=20 2.51.0