From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (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 D1C701AA7A6 for ; Wed, 4 Feb 2026 11:22:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770204151; cv=none; b=Zb4W/SaoXuHRDwuPV0DSBpO3tXZb2V2yOmmhOtk57UlwDzNOJGDqleF5hThY28ZeK9Yoq8YWQzVU+CC3sE4AqxkdPgMJTvq8m9/+5s6K5j43iWG7LZUsGDukivDFPpSWYxxH3cDpBHtaT1wVRsQpkP7D8zHGDP2TlmyYfCHx7+w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770204151; c=relaxed/simple; bh=pOFkHwYf7cLGhFFCN7UTyhRmttzAamQSS3XgoQEYuh4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oZm3VtC55jZrWSKU9VbkNfoAsmG+qnR3rlbrQQRLnTRn7WL2G5RuHnQ8EocTVAG0RVFIflKp3oJVqsOwLNLs/HKPjmXMd4QkOwolsQpqPHKivuLDNKc2x9gP8Sh2RkoSC/Re4tT6rWHk6+J/dHVPaw7eJ4CtOxOiuBN7eIlVNCA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wC7OM6zD; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wC7OM6zD" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770204147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D2OM8bXSqdb9ojFTWQ5GUf2IfdDEBs7qrQ7IvdaOwcQ=; b=wC7OM6zDBIU3SzRFh5QAHZCQLm/58xfXMroTAKUQmfOAQJSBow6SQTRX0nkueHXKOf/Ygr 7YO40lS9rhvUAi1Gn2dR6ZNiQkEYkod/6YIKDQw81D2lHfSV8s9nF4pNyhLGUx1rHU4gOb uBk6s72OGl9Dblm3jClKm8dJXVgMZKA= Date: Wed, 4 Feb 2026 19:21:54 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] hung_task: Increment the global counter immediately Content-Language: en-US To: Petr Mladek 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 References: <20260125135848.3356585-1-atomlin@atomlin.com> <20260125135848.3356585-2-atomlin@atomlin.com> <45c17b93-a6f1-45e0-8b25-20665a281949@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2026/2/4 19:04, Petr Mladek wrote: > 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@linux.dev > Signed-off-by: Petr Mladek > --- Cool! Looks good to me: 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 = sysctl_hung_task_check_count; > unsigned long last_break = jiffies; > struct task_struct *g, *t; > - unsigned long total_count, this_round_count; > + unsigned long this_round_count; > int need_warning = sysctl_hung_task_warnings; > unsigned long si_mask = hung_task_si_mask; > > - /* > - * The counter might get reset. Remember the initial value. > - * Acquire prevents reordering task checks before this point. > - */ > - total_count = 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) > } > > 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; > > - /* > - * 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 |= SYS_INFO_LOCKS; >