From nobody Thu Apr 2 11:01:50 2026 Received: from CWXP265CU010.outbound.protection.outlook.com (mail-ukwestazon11022119.outbound.protection.outlook.com [52.101.101.119]) (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 8BE37379EDE for ; Tue, 3 Mar 2026 20:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.101.119 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772569853; cv=fail; b=fBGT5BoimEfjlaK8bSWWu06kXR2x530M+nySpkRaPuj1uBaXPCBNHKto5v9yR295P9mkfMLEsyBYjgZvU2bFg41VkeuzjPqGRbYU2WRiAbG0U/jy4D4z46Nu9WH5sj48oarjr2LGUQm74y8ar7el83tes9RDLd/lMzJJ1OCXbHI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772569853; c=relaxed/simple; bh=VrNj2ZW2x/FrSUFyTidG0Yld9m84e2QP65Z8Pqq9H8E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Xk255buWYiNBz/nBKPgW75k/omqBwUHbjM5QEMUHjlYVkzfgGfx7W6q96uc3c3EnfurpR5qq0KT6iFB1RSq/dn7ZnEHLJxyDWEsDOheNp3fdp8Wo+x0tExBjOYqQ00belg3oqAcUl7XZgulibAvXmBmI8aZgSXodMvSIV73RfyI= 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.101.119 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=RwYYqw8S68lM/oCtoY7gIZxN7QlBC9NZuKkbi/aaeKg/2xOfR6ncb8PH8iuAb1BwZWcMFf03OMUM7YOH5ZarBWTzK3uL3wQ+raASGBUFZjUL0LcabDU0hca4yB111NcI0sLQq4l2AwS1ySPiypYFYa54AfsfKkI4BOq4Ewobl33zhK/TPetKaD3x2dFcZgKQpCdSDiY59IAJ/SRKnySWusPbdtJVFxyG9Lc8R/0zFCvo0PeIIUIqH4PNP5j2SBLSw+wbcRU/yi64JgAZqOBJY/JWvAmAbvDoL0AYZC8lIkSjpb89H3uyqdkyYfdWH1aegPDECvHUNcOwexVqaC1QCQ== 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=3Mi/HekRkwBP5px0KHcQPaOqPdOUuAMWxCtPwCsnlvI=; b=Vt1DFapYFQPZgoL27Ou8F4U0QCGZNr6H+XUkevj6Mfz8o9zUdRkWH8l0+S2Z2i4ToxFXJ1VmC6JngIau+c8KHi9ddGdXxkBK9idKjXcsQmYEhk1/Y1YdF4cI30lKf7b4W48P7zb5Aleol+qVCd2hmcnY3daKQTaVLbDUkcPqQg4lyo9mdR91ImJ0UdlAm5DSaWrWpMqi4DeiKNqLvoBVnCkMEARdxq6MQ4xdd6Xxirxf8xAoOwuQnnH3zWV4umy+N+ebdaKgrY3KsWuJ2v1+/Ku430OrJ2HXmcNaa8uja3f01Logkqse3nJr0WoOz/l6SjA1dMEdKpILxNIrFvnJfA== 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 LO0P123MB6636.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:24e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.22; Tue, 3 Mar 2026 20:30:46 +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.9654.022; Tue, 3 Mar 2026 20:30:46 +0000 From: Aaron Tomlin To: akpm@linux-foundation.org, lance.yang@linux.dev, mhiramat@kernel.org, gregkh@linuxfoundation.org, pmladek@suse.com Cc: neelx@suse.com, sean@ashe.io, mproche@gmail.com, chjohnst@gmail.com, nick.lange@gmail.com, da.anzani@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 3/3] hung_task: Increment the global counter immediately Date: Tue, 3 Mar 2026 15:30:31 -0500 Message-ID: <20260303203031.4097316-4-atomlin@atomlin.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260303203031.4097316-1-atomlin@atomlin.com> References: <20260303203031.4097316-1-atomlin@atomlin.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BLAPR03CA0068.namprd03.prod.outlook.com (2603:10b6:208:329::13) 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_|LO0P123MB6636:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c3fd55e-a129-4dd7-c331-08de7963c016 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: GPzG3/auMafMraUeazhJAvAiD8eRQwIgQR8ut+RppR8BJ2c+cjh1hCD8BXtsHqinpDvbuJwdOjL3AdZ4KEoGCoOLSynLj+NW2DC8p4IDv38mvJGo/ujXyy0Hr9CzEiHDdVm0S52tOAhUMgUIz2Xhv57UQuzrPF3uh2A0fzSUE9rOzf7mAEZFSWwC1Fgwr1iqYer70wYEjh+9syUzU/bObijDl6uUI8Hg7BPU7/hIqM8Z5oudltL8zNSscihmEMbnd7ZZaZ9WYeujiHReTsMQRZZgTTxBTt31garr1ndUejQqupHwFdT5UpOwkq46WlTJYhjSG+DD69NHcjc13A4aBflM7LCP/6bEyojTJuWYUYfryvMHeTNDDr2oAamFyVp4/g7C2beU84ON7E+VHhqnM4co4c6g8Lg5QlSLguY1lTrWYf6VpRqem7pQ8qFBfhgboM0noaE4OTBy01N68JQ4++aFOFMYy3iHYt+pooNXybweSrc84bzyblFsAmZ2vQGdyPSPo+kaHYioC+JPHKdeJZIiy9qS1D+hgsht+r3D24f+mn3e0Cfpudfy+sadG2ArYP7zOxDILaG4wrJrEoCP5cgtUngaplvaMsXDW1tgxLiZNgzLR3ETCkUStDIcgpfvosvCBqV0rtxnc3FFmQlJCK1LgGXdmEkfMVdKPwqe2a/rEO1CPLPZj1KqqHMWdRkK/BzLqekwvxTm6naONZUUlYOqnXoJpA9m9cGWv1hVmrc= 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)(7416014)(376014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?4d4vUj/mYycxI31/ZH7AeUjsjBoyNNstbjyhf+nr+KnKfbrmKSWd4dv7WatX?= =?us-ascii?Q?dlp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xX7bxa3+A+u?= =?us-ascii?Q?YQ1ejdJHqEKC3u01WJq+TwlLWstH0cdL8gqnJ/g0tz/0H4e7pdDPAVRvBzjl?= =?us-ascii?Q?3WoIlEPjc+0fTjatlKv+1z1VvlyQUV2Mw7hVlbBYw3X8sOwQA7as5ZQ1fc0u?= =?us-ascii?Q?H+2L6yuSqXAJNcIWUu0HA2cHpc4v/RNiClB7/HqvezCo4tJropsQ6c08Uwxp?= =?us-ascii?Q?dB1faPEiKuxmQtLB1V2VUaqwXdZfUAeTsVh4UDeipmAFShUBjqHjkrBh3fLr?= =?us-ascii?Q?irh/Co4L8alHxZKrGZOzXcPXwxPRDNs9wo9UZiy0l2+g35Z2xwisd55qnMt9?= =?us-ascii?Q?kgXhsZphw/DbvJTX0fWQRn8I2m17IIHRAmBCPNoHkhgRl2r5mH9mlBTBhJwg?= =?us-ascii?Q?cLIT/cZuDzvIMlgw2RbC9nFjlNzPvbHXpPGRmvarJfiJ2zoMahoALRskURNf?= =?us-ascii?Q?TN2YPB9E4s65N3fRg218PEjc0MOkUK0XG/ZoU00xcPZSWI6qaJIOT7foXnQM?= =?us-ascii?Q?YYZQX8DjXfHbMz37V8vK5RP7VC/1b2IEG4c63JeqgyPPcwtrNKtWYEaa9eUt?= =?us-ascii?Q?WE2aL2upHw/7QRnUtyyotVzZKfYXDTqrWcRhSlMXcCpC4ljnbaIVIg+BhvMg?= =?us-ascii?Q?rRoaqMjdo4Zm/c+uMVNmByCGCpYXpWcuonZEPubmmvKX3EvhrbP8I6Hc3Iad?= =?us-ascii?Q?o5NmjITVL/d3MJ8Mw4/bpB484m4XTEaNqP43vSyseaUAxpVuBYZ8rBAKHx7R?= =?us-ascii?Q?QZXM/hB5frh1W6PTthxfL+fC/IWnALGrIogYsA9j9TL5DoUxG/K27DsM79L6?= =?us-ascii?Q?jfsxx5dAFQ=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c3fd55e-a129-4dd7-c331-08de7963c016 X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2026 20:30:46.6355 (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: yOvlK/LiTw1eIOve0zj1hSrfmX7YfWN4saDZi4dMd89FVlj1S0sYdsv0/sWsM01NyKgkArUYTnrAq55zhWzqdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO0P123MB6636 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 Reviewed-by: Lance Yang Signed-off-by: Petr Mladek --- 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