From nobody Mon Feb 9 05:53:25 2026 Received: from LO2P265CU024.outbound.protection.outlook.com (mail-uksouthazon11021079.outbound.protection.outlook.com [52.101.95.79]) (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 4FB53212FB9 for ; Sun, 8 Feb 2026 00:21:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.95.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770510087; cv=fail; b=HuerViag/wNiN030zeL9bB/vD4uKGyxxDxcclwTdb5/9JxxJJt0FGP2lULXsnYZeDB09wcq/c9xKwejnVGMEgikszTQp9lEbfiVfHTbgJ2mQgBpqK3E2+e9e0ovfmOKhfBFn1E6mY0b+L0eFIsDmTUP1FFTAl87pZwF56FxopgU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770510087; c=relaxed/simple; bh=H2GsV586hX63ZP3chK56geZlYbEFPECZrmH1bPqK7bQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=gckwrruSTTlRsn64BwY69XYVhUD6QX6Zl7jzwiKC6u7Cr1JVPZbBd+rPEbU2u1OQYtKNuD3VBfpDi1cbnGJsSBVxfl0LszMd8CmZM0iTqWa3AiopWHIj35NIC0p4nrdzpov3brvqJzuf8kabPyFmNP+OoYHFtnTc7mL43umMgus= 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.79 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=TVkNn+tKusbGfy2PI6AWbG4A7UUaNGEDpOBO+AL4aIdIsyOGRokhNkUkyd+GDzWZOITtwRf/4s3bjNFcT5IFUL2b4C/TjYtVe+qSM/47xuwG8h+lRut+Mjr+8NA8mSNvg7E+jNxML9gQ3HQljhVHlLBlA7Qx9r4wC7JcxbFYaA0zKi2YDsTh3+4wzGnGg/qCwe7csj5ilBQPcLN5fq+ri7UrhM7t8PkfNmclCmxI0/O3Z/lDylK9qg8ylo4ZpFOp6/rHSMvhjBSoUJL/d4trSIo6W362YJ8PtyfRDjyDAMOtugMVLA57/yr1JgHXHjVzHsTKTK08yhWYqd6q6BrqDQ== 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=HKKws6FLgEtfsjwTSMHpjlXrq/WO8iydIkQ+ttxZCjk=; b=XlE1wHNScfe1hnJ7l87JPgafGLxEyaZe2aW978LGxVw6g5rOPY+nW2JPFuXpkf83xHq4HLlG+UbsO1ITengaQjP2D3pBVlW9TkZvXOucR0h3meM5BwW+K8lAsQfzgWoZ+KqM/faiy3U92lQRLubfWeKDSs1iljbXC7KeaVm7oRgllaBPNLDEPuZoG8c/M6zGx/GzaBTGcn/U2tFO2TFx8E04YMq+W0twLfDm1ExLlQRL199hSNzS3EC9rAuNFbDYZsznn/npKt63KjUsmH67fG89P1v25NfKNow0uYbHU6fA7COw+3QeYEFy7ooU2hULpB8rOe3vRuRtkSwGDiADcQ== 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 CWLP123MB6460.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:1ca::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9587.17; Sun, 8 Feb 2026 00:21:23 +0000 Received: from CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf]) by CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf%2]) with mapi id 15.20.9587.013; Sun, 8 Feb 2026 00:21:23 +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: [PATCH v8 1/3] hung_task: Refactor detection logic and atomicise detection count Date: Sat, 7 Feb 2026 19:21:14 -0500 Message-ID: <20260208002116.3790497-2-atomlin@atomlin.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260208002116.3790497-1-atomlin@atomlin.com> References: <20260208002116.3790497-1-atomlin@atomlin.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN8PR04CA0044.namprd04.prod.outlook.com (2603:10b6:408:d4::18) 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_|CWLP123MB6460:EE_ X-MS-Office365-Filtering-Correlation-Id: ae2f5f8b-cad4-4657-07ab-08de66a7fdad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FmfuMK4LcF/nXO1mWGIu0XW4EKqJVo2NBIDUdHDZIo0iFkLWmDE42YMJfAqt?= =?us-ascii?Q?ZCmHQrhSrd/W+MfHJVoA6P/K2eufLjf6HZxCibQHnU/hHemB/gXCtmvOtqna?= =?us-ascii?Q?yPOMBK//L9+cBaLRewoW8ZD7bFPXDa0kSdL4rT9Kk/fi1DK6KmNtu414soQm?= =?us-ascii?Q?4nAliV/fCspC4N+PmsD/VEnIkmpe1lbmR7GPBmhgfKxxDSF46VEEadPe3VrB?= =?us-ascii?Q?H9RsvQKwaAxKrZ/Yhs+rlXxNDtF/2cS9EnKcEo+Xob6w3kCCpBCX4RzfMV+6?= =?us-ascii?Q?wMZN2BOCMzNG6B0YGft0KkZnmF40/t16jp/yllKJg3QBb5TSVDPOBh1jJOyq?= =?us-ascii?Q?e8CCV//t5eEFLcPz421YwKYA4sdeSH0rGxLohLsBnQTrhoYmdXQbQ+/zKiNr?= =?us-ascii?Q?ZH/9EEjruh9TnHF6cqYyo4B7VquteylLDW/6PSngmvwL0lB9zqCRB94CppuU?= =?us-ascii?Q?tur8MLn9viLH05fEoSI2Wmn/AXMtNlN22y+uWFW2b2NrVtA9j7eIjtWpOZG/?= =?us-ascii?Q?m+4GMJNVUazLrxhb0erl19Dyyunf1QUJOhqzykxGPEh+DYgAheYOzWbd1HUA?= =?us-ascii?Q?OG5bx5VJkIhNvX1+k6HtLvSEvURMXfQuI/rs0o7uL0rj4zXxUyPNnCIIAjES?= =?us-ascii?Q?c79q2lr32ZhLoFEi371omhdaPeMzMZaCTm7Mo78t7iB1gA9Rp6GUyBTbVL6c?= =?us-ascii?Q?r7X4bKYBHJlBlfkzTSEyA7FUFqi5pG1k8JVS8WX7pIGZH+2Vo4In/Dx7KoQ1?= =?us-ascii?Q?8k9GpX62NYqKn6I8s9REuZZj+PCU09+kQSbNCxrxPVouLnvGDzZhvAoIOS8/?= =?us-ascii?Q?gaM+AHpsi5r0SvyuCfbCsIec1zBVuDBE7woQ3d/k5Lik/c5wO1nNg8jVxnOP?= =?us-ascii?Q?lvd3lNRQTFtO0wo2JFyK4J0hfwoImTTB5b+iPSWichjfWz8JX2msERA37deg?= =?us-ascii?Q?5h5KHQnIyXiMBjyczLCKRqD3ijAErWjUnyEqF3G0VgEJc+iyWfUPLIU5yfau?= =?us-ascii?Q?hph3sLrmqCkvoT+ztVCNfaETRbcrIXOdX7DfuDOMi9WQ4GjttowjgBJzvOS8?= =?us-ascii?Q?fTIyN1Z/23KhAo1H7fPkJV9eIkUg2AljiL18kAY+l7JMtCKfnx6qT9jNEFbm?= =?us-ascii?Q?54uNg/VFXgV/5kcw40Lsvq7ARSB7Xi695jr5rY9sudo4X5RQJnLRehcB7A61?= =?us-ascii?Q?puhjrK4NexS6AfRQ8WPUpUfLbxnJeGkDELfTQR7gwqfACR/a3utTN46SDHhb?= =?us-ascii?Q?mFxC/mtnrbwTvDURj0rkzxK3mBeLcMWV8C9hPZuM+Peq3l/3UfsNxm3NLRnr?= =?us-ascii?Q?ePcJ95x9+pj+ky48k0Bi6IbySrubUBfbOl2Fbg+Q3S8i4xHPpCIgOhnak7WU?= =?us-ascii?Q?G8cTpdKoj36CBVUNNg0VtQgLFPFl25UKltMmLn9zdrENdckcWVjVwJ8xqPqz?= =?us-ascii?Q?kFHgKwIxNvZUqf5e/0P/GeMCejuKZ+EcrEiWfk/AfqJo1+5/BgrClyU7BTpv?= =?us-ascii?Q?MgJGFOza1Vq/6nGUa3QMwGrbfNCIY132W2mLfZetlAbbnLHmjXYgpm7I9evW?= =?us-ascii?Q?LwbrUI2dxBKLjRjyZ0o=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)(376014)(7416014)(366016);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6Kw2C39PDgkD+vESSYuxsx3gCtPpfWHTfb4Y/5IILHML9hcqjIwKnPireS17?= =?us-ascii?Q?V2mGS2IIQVEHktp0vVGXRpbATjvI7qDhAW7FbLjrRl4KJwIVCnk8OC5nTgkc?= =?us-ascii?Q?NL3BfQSg8wHhjKPpDFlJC+1ELggGVnpn2yG2oY8zraO+r/ssKI+JZ8bEheOP?= =?us-ascii?Q?4zyZvOGIjJK13MyN/aNcsgD/U4XIZgN7rMAorY0E0/mWCHn4Mjf58uniO9nY?= =?us-ascii?Q?5cMibS0k2MdssOVkR9qqJozhU/igKh0xRpJ0QZ5O6tZ2HWjNq0BJEgW0A6el?= =?us-ascii?Q?uJBYRHCfQ4jFTWGFtfr9lckDlesD2lmrrpxICwUnHnem9OZBYIx3prWb7IF4?= =?us-ascii?Q?rtougwiIBEBDjlf5MrNGXoPNEMUzE5EP8GBQIPf/iPPTQFOsbY52tUel0Z2d?= =?us-ascii?Q?5Ukunj2imI3y2XVKfX8lvYozKFXdnApHxi2c7DxuHSWe117OefcaV1KtMyV7?= =?us-ascii?Q?NDA9xnyRj17j3p6l74NHUf7XM3iGymwFB5DfJvNK3spOk/pqz9TT+uUx6gKG?= =?us-ascii?Q?LqrFxOf6teBJPSRC4rva8NaJ+icIziQd4ELPtjj5Bs+58fISy7NurahuJ+d1?= =?us-ascii?Q?z6If+7lgt47+OztGx5QdzFdvw0iPSiU+0bPsgg4w8J+kK1wSbYiABPMm/pqd?= =?us-ascii?Q?6MlgthYmi/Fx5ONhqUPsv8eFQT1nAtm6Vbyq49I5MKnBsfmHQo5YYSygf91I?= =?us-ascii?Q?dQnKeMdMmVJvQVHHKGgARlUh3WDQ2B75tZKaeQSZk7GhmicE4ANIiNT2oAkw?= =?us-ascii?Q?u2/aMOiM4SX4UUHCNSK9Bq1vddbrD1VGtr3HZZv6l2UzsadvaNQQtdNMPBNb?= =?us-ascii?Q?MTcNUf8JVumLbESbAysvYWEoK84i86AKSXH1m/+Jbt4Ggv84dcZpDzmSWlVW?= =?us-ascii?Q?EDEeaJn0bpAZMM1bO643OWrAHPpP/sTORJoualraXYAqjKvplU1CJrWBWiFn?= =?us-ascii?Q?iQRoJuhQj+ItIDGbdn/LZMM73Sr0LKQDribmunqXRfxxq6uVuOQiIGyuqKx+?= =?us-ascii?Q?UZWuGgFFuW94wSpLtNF86lQ0mvPDO7kZ4NbR4PpOBKAwH0qOmT9Lb0CuMIdO?= =?us-ascii?Q?LiPMMhQvNB1hlDKudTWOsKD93BOBFwfEz+3v4OQLyrNDaRAThyPuEqDLSoqy?= =?us-ascii?Q?J6SmEaq3iOtZw20mJwzo+K6XRziBNdpXYm79+4ueQzt/TQMmfI2ijByFdLE2?= =?us-ascii?Q?GbHiaJERzu+vKftSmo1wHYj5rf72W+kndx8tlFyup5vuhRa2+kRS5D2xZNTZ?= =?us-ascii?Q?h5enwrvaCbqyQoXQhOZTimAI7Kk0n8xijBKJwvAe5czFhBDgecquarYnanBK?= =?us-ascii?Q?holzMxCuEqsrmcwTbq8qa6bXhKH81PeqrdvlMAaaeDErx2OF6upXzzHyAbvL?= =?us-ascii?Q?EKkyLo88gB9YQWnTK8lYskkFy0oIMw1dviyg0ue18blPM4DZdTd5bznkCqfL?= =?us-ascii?Q?hr3mqa0JkS1YFc8RqeL6h4MVUq1H2OfcOV7sGYfZRU+RVP+61aqDPeyPbPKT?= =?us-ascii?Q?yf0auTEPWCLpQHRxyZXUX/m6duE3qafpQIGk1MjjnnQrooVpkd+l2UxLc2/8?= =?us-ascii?Q?c00U+N6v+1vE84jX+Ju4wov8CXkmOMxvWTbJ1GgYou/BcxCrWbePBrriXIKd?= =?us-ascii?Q?9mfFletJjCQXuorkzuYdhL+kgc/vgP5vT3V/Hk1x0LdYQ1VrjkfK0SGv8yQV?= =?us-ascii?Q?omytSbX2T9nKxHsjyneys+3aan4B+81F/ukAhE+0M10lgVIliQvvRdNQXWve?= =?us-ascii?Q?piiHOJ5igg=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae2f5f8b-cad4-4657-07ab-08de66a7fdad X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2026 00:21:23.6407 (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: Fe81DmlNbK0d/1O9aGJQrB1o2jEHmL4ij5X3Q57ZlZIqJU+ufI33RbGVOQYrhUoSaHidn1I+E6HXeMmKGbp8/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB6460 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. Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Aaron Tomlin --- 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