From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 C2CD73BB57 for ; Tue, 3 Feb 2026 03:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770088125; cv=none; b=lqfj8oh+59v7axwvpUIWJ2RSlCFZnMTaynSiAQMX32cZthZnSysLx64tX3krKbYgfA/jVN16IXZCKB1XVUya/zPbVgZnSiJ2b+yB+Ek3jUkczdgNVQyPnlTAcVxQWKbG61YtBOOsNliL5TJm24E8h0qQdnqMx+uPZxXCTx8lVOE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770088125; c=relaxed/simple; bh=d2QXGT1C2B/JYhWb5pj3x/3tCS6la0ha+oHLQ1abiHM=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=cd6ZGePHk48spgDDg32PQTnFD7yOcudv+LihSjIHIHXqy/758fqGt0lQ1MxZsMIzCpWOaaUuMJtQtTrjhSpJliCpLThHtOhUkhu33gEHjodAtgmn00gwGrhZaOzFJ7G3TpFaRb0T4drVUQJJbxfeFsWK07NIuQLlHjjn3szsSSU= 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=FFmyQFql; arc=none smtp.client-ip=91.218.175.171 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="FFmyQFql" Message-ID: <45c17b93-a6f1-45e0-8b25-20665a281949@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770088121; 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=suJD+X5ZILyglGaUgSK0Fdojev1IGPDGpz+32Reg+n4=; b=FFmyQFqlO0huGqcE5T7whfwiY+XNxlnrM5prxlXfuK/3EpoVIyMXHw1VMYLOnMhP1MiQFv 1bKPyIxfbx9l2j9OLjw9ZNfr2bVmFADzS4iZKWKD5MxCVG/lE5dp7clSzCIFj4FeR6n3iz 2W2gX7yvuNungc84BI2P2tMGQIqXQHc= Date: Tue, 3 Feb 2026 11:08:33 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [v7 PATCH 1/2] hung_task: Refactor detection logic and atomicise detection count Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang To: Aaron Tomlin Cc: 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, pmladek@suse.com, gregkh@linuxfoundation.org References: <20260125135848.3356585-1-atomlin@atomlin.com> <20260125135848.3356585-2-atomlin@atomlin.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2026/2/3 11:05, Lance Yang wrote: > > > On 2026/1/25 21:58, Aaron Tomlin wrote: >> 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. >> >> 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 = 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 = >> ATOMIC_LONG_INIT(0); >>   /* >>    * Limit number of tasks checked in a batch. >> @@ -223,31 +223,29 @@ static inline void debug_show_blocker(struct >> task_struct *task, unsigned long ti >>   } >>   #endif >> -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++; > > Previously, the global detect count updated immediately when a hung task > was found. BUT now, it only updates after the full scan finishes ... > > Ideally, the count should update as soon as possible, so that userspace > can react in time :) > > For example, by migrating critical containers away from the node before > the situation gets worse - something we already do. Sorry, I should have said that earlier - just realized it ...