From nobody Sat Feb 7 10:08:30 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38F503D9049 for ; Wed, 4 Feb 2026 11:04:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770203099; cv=none; b=Ifq3DOZkfc5MR5oV9lcgPrN6kBecj5PsViyPP/xh/Kn+Ek11nLH0eS0x7I91Ybq/l6Stt8c+hOE3fX78QKxmDi4H8YbidnW7q8KGZJ8+WGUFsH4SF4WXQeD/lc2Htpp9BJtI/OklOg1kLXWfD91qmdYGqgwVLjFPuVl55L7Ox8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770203099; c=relaxed/simple; bh=B6KoFRPip8BhItafJGx3ba+p3mv6CISpNAsl3/zfeQk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CgC2oU6tN6fnYTWOrqAgQhoCqfOVw/mAQ+KTGS0G6NWAnKBcjRs1mGrr9m605/MaY69P1Eg9A504kCJQCCcDbz9oh6KPUq1opfI7670OGDyBLSNOnl38iDTRIXLciaXwvDSpyOVsRCxjwhf2/RqyuSQeeTj3lEHeotZp3kgGGhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=XuB3/dqa; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="XuB3/dqa" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-47ee76e8656so90218185e9.0 for ; Wed, 04 Feb 2026 03:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1770203098; x=1770807898; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fAoVqNmVZFIYisuIWC/I92lVYzw+dRowIuIqXftz6Xs=; b=XuB3/dqaKAXww9YAM0pBJtd9pB7R8mWeKKV4rlIvuakruo77PgfYkTmSZvYkEbSX2E n+sl5wC/28O/Ejl4vhjQvPXbzTogY++1eM16WRd9jmkMrHFwXX0sUkNeIv+yQaY5tjq9 0/O+Tuf50ej+R2+NV459FPt1/qxlJTvwTN5cayv5lVz658L9+iTpKIRIQzoam4L5LWT1 vozzZ+e2O+uZZPx3hju3QTeCzpNUKJnTimscrmLEK2ywBjB4FBHWW+xqEdrZLSqNKZSa PqhD6GDwyaEFVhqAGEYqvuWAx3dTDwquKPiv6y2kARuNVydMq0iZ05c5xX0pMexgqPaM L6qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770203098; x=1770807898; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fAoVqNmVZFIYisuIWC/I92lVYzw+dRowIuIqXftz6Xs=; b=Yrm+6xV7XbBL4EEg19tj3A2SUo51oz8Rdjf9LxTNF40bRfY81D747tQ1+2wtXHwdz9 OFilewt/8Pg8XJIV5VxD26ykAzQv33ZqP098+SMxOIiJ5z9Gh5lH36Y787tDMqnhfXx0 ZGUZd1xd2Q0C18k88HXMA5u6nO2WctVhLnpWWe/y1890wullFXBtB0iQRGteKtspNtYX 0i6neF8Wj/Xnlcpw5j7we3VlRyyYOX+eD0w3t6TUY0ILMfyvA6J1Df3/gqgnsWWAMD1B ijP0Pi/zncrKYn07zju9SPUmQxJyG6zx4TMemPuq2l3zOf4i8gNuDEuF0/X+wI7DYrXU M7FQ== X-Forwarded-Encrypted: i=1; AJvYcCUqNGy7aJecNxYUnxuzfRuSNv8U3NCxEBl87S/bJZeF6+c99hoBi0DvaJ+GVd3XDT0CChQVtkGuON4JVUY=@vger.kernel.org X-Gm-Message-State: AOJu0YyXKZhHdnSmscU5WH4Y89MsV2zzs6iAXFBdSGJrEzs8SzPIW877 dIq10Q2eYCybuC9YgnaBOAJLaG3m02/2suZlEzYa1rX8XUNae0FKKSOF9SU3mTiJgeE= X-Gm-Gg: AZuq6aLiz+il50IA0m3uGiVNVoA0Ihggr3qf/X2vWOnfNxpqBqiJCfAX1fpbgCr4D+S /TYXBGq1nUycPwZb+V0qWddhc3wdHu32AR1ia77menOQ+/8WaechzfZs/CVQlQRTbWHUPqkCYL2 UJpOhwWOOvyqTT8S5C6p2pZeIot4v3OEdt1fIgzpSCuaMPxVcJ7TMflwb3GXwodXpKXOu9zdPUB XbAuEDUlfGYUqszssHW+g4eC0y6A/BUB3PTeqO/6OkXDcshzgDKc9vk+Qk3aZW6XYEg3ZybyAA6 Cd1pUgoM6Bmi7BhirS9dUc+2j0nx0XIlFN/MKo3wT9ioiaJCHuKxKP/42YlIilEf6wHAyknCZuv mzXX2gEnGfUojlBnzPDYNqALgtbj2xVYKSQ9OKcq/gaYTsF/gV61EbtzrPdPaMblswg1i3jWgRX g69eLIFFIOOnbTVw== X-Received: by 2002:a05:600c:800f:b0:477:79c7:8994 with SMTP id 5b1f17b1804b1-4830e9713d6mr32371745e9.30.1770203097593; Wed, 04 Feb 2026 03:04:57 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43617e25cefsm5820329f8f.9.2026.02.04.03.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 03:04:57 -0800 (PST) Date: Wed, 4 Feb 2026 12:04:54 +0100 From: Petr Mladek To: Lance Yang Cc: Aaron Tomlin , neelx@suse.com, sean@ashe.io, akpm@linux-foundation.org, mproche@gmail.com, chjohnst@gmail.com, nick.lange@gmail.com, linux-kernel@vger.kernel.org, mhiramat@kernel.org, joel.granados@kernel.org, gregkh@linuxfoundation.org Subject: [PATCH] hung_task: Increment the global counter immediately Message-ID: References: <20260125135848.3356585-1-atomlin@atomlin.com> <20260125135848.3356585-2-atomlin@atomlin.com> <45c17b93-a6f1-45e0-8b25-20665a281949@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Petr Mladek Reviewed-by: Aaron Tomlin Reviewed-by: Lance Yang --- This is a followup patch for https://lore.kernel.org/r/20260125135848.3356585-1-atomlin@atomlin.com Note that I could not use commit IDs because the original patchset is not in a stable tree yet. In fact, it seems that it is not even in linux-next at the moment. Best Regards, Petr 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.52.0