From nobody Mon Feb 9 05:53:02 2026 Received: from CWXP265CU008.outbound.protection.outlook.com (mail-ukwestazon11020135.outbound.protection.outlook.com [52.101.195.135]) (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 07F5121CA0D for ; Sun, 8 Feb 2026 00:21:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.195.135 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770510094; cv=fail; b=I1qmdC0Y0oIl2PoVXJN2uA7wlk096Ivs2yzGwZTQeuM0cOPZiH41cQIP7lvK2SHRtcfUPq8YdaMNVZt1MC/awaWuRKjzkDQOMagWKfRTedeC5G6IKoR8jRL79dV6KixZ1vwHuTLwgtcTUPsCJiXFOEAf/snxkSBuh4eNSGQnZJM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770510094; c=relaxed/simple; bh=aoI4KyyaCj7whdn5Brh+ob6L6DAxz0Lwflc5EyBY18k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=YS7V5MPdI4etGV1j2dp7PRzWByt9y/xPMex7TAxuc1E5RBNuVLGeWuxj+BhaeL7sc02ABQ0vH1jwX+axrrk8wulljR6r4AMVBrL+dzoISufpbzxR2p15K9hDSBIfE4kU1lu1UTw2OjJV/Zc7R0VhoYuhnTLyhgkKCdtNHWSynrg= 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.135 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=Cz2ke3fH8fN0BBv8uu6R+fKlM+qwINTYOw5fKTswTcDSCKpb1D1sbVOden5Uc6S3ler+sSz4I5sizokKadm/4tdLhyltW37xRHCPpOsV/zR0y+XcLjUUpuCJbKx1Q6HCNCPwBKY75rtuy/SjWReEznuyurzqelMHSv3HML3qF2sbs6UIJbUperN0mzcBau5kfj18rmGpJDbjnhLidSbW+Yl4mJZgFGa208SxKTDCcHhkiM0tH5uVg5ZOR07luuR8dqxIVxhsW279mclPc/ECFza1h2Um/gJb/Gd7XqZFMwpBaZWwz50IWJ9DePS8QzZZLnHrxoa57hk5amDhAMChaA== 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=nv6Qz7ez+kud/5lpyBJGFOI1PoA57HKCDdlQuWC5f1Q=; b=cQUg9CG/1CNfBoeI7fRO1cOGdRaRRU3QmHh6l3//CuS8Cm2zuAaiLAro+cElgnbdwZvBRZtxqGX2lQnc+wz2N9rvPc7OoIjTFSCO4Vsx5viFU5BTg2wNtxD0/OpvsVC24xGkQddnJ8nNeEkfjAIDcoUp6wD8pCfkU8/IzU4HG9NTTw/spwxZdXRZkCkfgvgZAgYv1OKcP+dJpVgcUz503FrUkn84zlx+8wSHlqnFW1dm0++7W8xr9Q5pfph6DjUSOb6OiFU4siaISDNb8PMcZVqos16EueSRaN3vmd7HVKK3s8tV/1V25hBoMnkGdp5aUYWeI8Md59pRgujgkQ5o1w== 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:31 +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:31 +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 3/3] hung_task: Increment the global counter immediately Date: Sat, 7 Feb 2026 19:21:16 -0500 Message-ID: <20260208002116.3790497-4-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: BN9P222CA0014.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::19) 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: b1fecb78-7605-45aa-28cf-08de66a80271 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?Slc62YsTzLwvkQO00/P/NgaGtnMFBHUmZ/bT2HHtogxOwWx9ImRDfj7WQKKm?= =?us-ascii?Q?f/R1/kdVKlhPg6Tpp8IUuL3dxjZt2fy01HfQdhakWON0GRPt/8W1uYbDh6c1?= =?us-ascii?Q?jjRgDu3qNW7RTULA6jXjHYpzMDm3N5pZsFDuir5cR6TBZg9OyVlyViNzww5D?= =?us-ascii?Q?/VKuZ0X+kl6KL8Ryi7NbzGNlAMfKE3FkFBVkikW6cDPXIzOxYg0nTGvC6izI?= =?us-ascii?Q?KBPjl18C8KfwW0zMOC4rUsgpO+KTD7gvjKSeYVOpG1htkRHNsZJ0PuFTgK87?= =?us-ascii?Q?vPLaZeoyr0gnYggpPdS4/5PBcltTR91wy2dXjXfqege3QRtY+rXEJsyvtBbB?= =?us-ascii?Q?B/iCr7xEU/d3AAMPK7B/Z6iFr10YHxdv+TvqL3Xe+aAEufJ+c8gvOOm+46vP?= =?us-ascii?Q?YHIKkbjrQlpQZ3IuhrPBRZ1FQQDzSnyEddl7rcOnjWeUpAul0YsUwG9nP79z?= =?us-ascii?Q?qqqr6lcCODWOvwnBpG1ekPtQItKFOA1THvRe+dJED8AFgap4oeHsu62FVlq/?= =?us-ascii?Q?rkHi8kVDSrbLczHOjuGIqyGgnlvLnBsSl7Jd7iLZgFSwTIl1ILV9/SJn+M7S?= =?us-ascii?Q?SyigUwIrmJWzsmOxt8NjwFrGybImeBBgt+oE8gIZL66cMb3w/URezPmlOZcp?= =?us-ascii?Q?d13sqBFecoF5uhbtyhYw4b4j7d8iX5wamvl/teEEKId6NBuR/e/oTXk5bDZK?= =?us-ascii?Q?xymQOIzYcnR8s72qT+hbplUFYWvZtiFIo5zv2Mtcn+3AouYAd3cIBJrgd0eZ?= =?us-ascii?Q?DFnGMVXacnETFvtLuHOj/7i8qUZ7XIoQ6RofnhE57ApaYOpLcnCnd7FPxYle?= =?us-ascii?Q?zTGP7C6CAaRyXKOY1aB2jWnAXIwXUWKkEcfcXbM0EKKXyswo287+PxFTwXuk?= =?us-ascii?Q?zSPBSYq1Kxhiqwfyyd5Vk4DWU4i2jVCDZ2cJ6Nittg00PYBXUit2riZsYgUh?= =?us-ascii?Q?qK3K/YVbEThIqfGv/BQitT6v4aWUDD5Y7Asof0s2/KFsQkyAipgWBl1Yhkna?= =?us-ascii?Q?zsneaR3dFz4aIeJy/7a+cKoYVvGFEZSz6mx5GGNCgnD6kYYPkFzBS33sEvXH?= =?us-ascii?Q?S0CK455NzSCOoYyoMzYCDUVE5IWe4bJ5xLOS1f4GUvcos/YpYX3IHddu2baD?= =?us-ascii?Q?pCKFfKTgUVKZd6jD44NPS12jj58/Dt7jWzLZk1WNWfx3MbuPNcLbv4yPN5UF?= =?us-ascii?Q?xLq1PHbgbha9hU7RFsA3Bv0VGHhfYXRZ/xwPfvIv3w4gdHuMFw7Rw71MQovs?= =?us-ascii?Q?N4Q79DI4d1dSeXqwlmodlT42Rowkf59ukCbie2kKtWO5gY6ailrUIDajmVJf?= =?us-ascii?Q?3jdJBI6omY6EpsMxeMcrjKO6qE6DFN/yIIktaXPZetVAx2MEQqTSWqDTWN/D?= =?us-ascii?Q?5v8wJ5XoF29P4Ikidns7vor3xseXz6FSEd7SLvndhRbm9qzOvEjLevBySdmi?= =?us-ascii?Q?9/XLa4hzhvu8fympFjbX8iqh5sWIlmw6AYvGPR5UmwYvF+yzWg8mT+Iwf56P?= =?us-ascii?Q?kr43PTV8jajSPpxedCa5KuXNdK7FtVCpm2oooSaYrl6SRO8XkD4fydD04NvO?= =?us-ascii?Q?IzNB1Jack7yRUmG/alY=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?Pv7PHqWuyMBuSExMReXWHAsVVZK2IJr4kExe2ykJRKLPSNhF48Ee0eh+V78y?= =?us-ascii?Q?YqYEIlYd8w43TH6PSGneoLRZTboBtQi4KsioJwY5JIqZbOn68hMOaJwS408N?= =?us-ascii?Q?IDFZ1Er3msnH6xQ/kzKc9BtOQm0Khlf0Y38fxx4EGyeXRmChsWSCuC1Y3IZ8?= =?us-ascii?Q?5uLwVdFXtr+mm/3DmOjViPC5MemUuBjXx0TxSoNmTm658Javh9BYHLK244cb?= =?us-ascii?Q?bLr3bd2nSZ47UEAKpEKXXlVxIz5yjgbOZlfsjEx2hhobSHcoMSSEKIdnaTuy?= =?us-ascii?Q?gEty0iUkED8Cgli1s3f8OmVilcVbf2IgDqAvo5+Fpw54nNByDfGSKqGsVNjA?= =?us-ascii?Q?A6d4EeBxLJl9NaZVt2WkBnFxlIKqhMJm/DJ9RbCqjgKaaLgrSGvwwOts7j3m?= =?us-ascii?Q?8h6/0/cQcqAa/7sMi/D8otbk3lllVhgj6QsjXGHEuueepRt/toZV2DuhcH/v?= =?us-ascii?Q?NZwvLK5L6OK08IaFIoYDRlXOOmASgJBsr3zWnNloeT7qHtAq9I4DAhUeycV+?= =?us-ascii?Q?M64s4PAM86X/gQ4CpveqsYMilf9HTdaesTum2GF2riWypghwHT0cMwjew0U9?= =?us-ascii?Q?pRcp/LFjyQPGDdUnHt6QKIdrXoccvwcdrIgN2d/CuM5Fj+C2L2nY38iY0k2J?= =?us-ascii?Q?WicJdH7igvoGOfULIHg4MbQJyepjAguPmvQhJX0googt+d2rZ9TE8JaaHn6i?= =?us-ascii?Q?KK4Lox0rLHNlGsQjobIbZs4Jy7FE4c5UnCtgDISyI0b5Zc2QqgMFafwrsq/a?= =?us-ascii?Q?GoeRQEVKZbUCP6It+kZv2S2HZro0UPSRVAJ7q+E/NFCm8xojjcDVvfn/aj8Y?= =?us-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a0+EpnG3bjxcQ95tpfh91rmeF4e34sM3/qW?= =?us-ascii?Q?UiiBqlo06w=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1fecb78-7605-45aa-28cf-08de66a80271 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:31.6482 (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: UPSGjEExRNeBLXMe8eQA84qYWHmkycnzYdWQg75vk7GtevbjHGhUiMxFI8a7pycBbJxmITGULbz/2Q03SVD6fg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB6460 Content-Type: text/plain; charset="utf-8" From: Petr Mladek A recent change allowed to reset the global counter of hung tasks using the sysctl interface. A potential race with the regular check has been solved by updating the global counter only once at the end of the check. However, the hung task check can take a significant amount of time, particularly when task information is being dumped to slow serial consoles. Some users monitor this global counter to trigger immediate migration of critical containers. Delaying the increment until the full check completes postpones these high-priority rescue operations. Update the global counter as soon as a hung task is detected. Since the value is read asynchronously, a relaxed atomic operation is sufficient. Reported-by: Lance Yang Closes: https://lore.kernel.org/r/f239e00f-4282-408d-b172-0f9885f4b01b@linu= x.dev Reviewed-by: Aaron Tomlin Signed-off-by: Petr Mladek Reviewed-by: Lance Yang --- kernel/hung_task.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 350093de0535..8bc043fbe89c 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -302,15 +302,10 @@ 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 total_count, this_round_count; + unsigned long this_round_count; int need_warning =3D sysctl_hung_task_warnings; unsigned long si_mask =3D hung_task_si_mask; =20 - /* - * The counter might get reset. Remember the initial value. - * Acquire prevents reordering task checks before this point. - */ - total_count =3D atomic_long_read_acquire(&sysctl_hung_task_detect_count); /* * If the system crashed already then all bets are off, * do not report extra hung tasks: @@ -330,6 +325,13 @@ static void check_hung_uninterruptible_tasks(unsigned = long timeout) } =20 if (task_is_hung(t, timeout)) { + /* + * Increment the global counter so that userspace could + * start migrating tasks ASAP. But count the current + * round separately because userspace could reset + * the global counter at any time. + */ + atomic_long_inc(&sysctl_hung_task_detect_count); this_round_count++; hung_task_info(t, timeout, this_round_count); } @@ -340,15 +342,6 @@ static void check_hung_uninterruptible_tasks(unsigned = long timeout) if (!this_round_count) return; =20 - /* - * Do not count this round when the global counter has been reset - * during this check. Release ensures we see all hang details - * recorded during the scan. - */ - atomic_long_cmpxchg_release(&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