From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 2132829A1 for ; Mon, 26 Jan 2026 05:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769404992; cv=none; b=fXYnPV4Y84NsZNlxIMlcpuJNMT2WJEiHubSDnh2gj6mYx792kbNwvlXQU0AWnv9ARkrPWvGyTgdc4y9hzydyRuARUsF3YsHcnUvw3nga1NfPMNmNCp5h5aLwm6Ukof7XWZGfKsSbxbIIn7+eHKCDessFcdQvCRccyBWfjSWs9Aw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769404992; c=relaxed/simple; bh=dz3k+DIWjetLOraCcgKKPESif+NFlcuQHm49FxF5/lY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ptzy5gCttm4fXot+YdRd51duySf0cEjHD+f1NAfwy280MFpOtli2gQZmyRM6wlnrZbrSV6WT7+1XBL0NwWw+7HDds6xkW0XEAh/YDFGnbQOA29nxNzC3rR9U5zvZsllSVCw0Sgf+IS+rEnA13zHFJyxckG0AvxRZ+4VC9CrS1IY= 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=va20u8Ic; arc=none smtp.client-ip=91.218.175.189 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="va20u8Ic" Message-ID: <4db98cdc-132b-4034-a6f1-25a3df6d0d01@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1769404987; 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=DvYyzDuF/xyyfPkIsAqx2jWy3dP9b+b4VVYkzfs3uCY=; b=va20u8Icv/yX5/k5o+KGlwSHmC3qF/45qDNmd0lVWn/pl53urcBg8XyNJAExHxPfq6JgSa 0OeBovjcbSOla480wTVYmALv/pjExdpXVqHPkBaEbUTOLMeFsWQn38QC3N3p3hvvfXaU9l r5rxVIqdhs1Xufpupzle95KWFUKWcro= Date: Mon, 26 Jan 2026 13:23:01 +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: Skip scan on idle systems To: Aaron Tomlin Cc: neelx@suse.com, sean@ashe.io, pmladek@suse.com, mhiramat@kernel.org, akpm@linux-foundation.org, joel.granados@kernel.org, mproche@gmail.com, chjohnst@gmail.com, nick.lange@gmail.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org References: <20260126034539.3407903-1-atomlin@atomlin.com> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20260126034539.3407903-1-atomlin@atomlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Hi Aaron, Keep one patch or series under review at a time, especially in the same subsystem ... Maintainers/Reviewers have limited bandwidth and can focus better on one thing at a time. Please, be patient! Just wait for it to be merged or rejected before sending the next. On 2026/1/26 11:45, Aaron Tomlin wrote: > At present, the hung task detector behaves in an unoptimised manner: it > wakes up periodically (every check_interval_secs, defaulting to 120 > seconds) and performs an O(N) scan of the entire process list, > regardless of the system's actual state. On idle embedded devices, > virtual machines, or large servers with no activity, this behaviour > unnecessarily consumes CPU cycles and memory bandwidth, hindering > power-saving states. > > To rectify this, this patch introduces an adaptive "green" polling > mechanism. The detector will now verify whether the system is > effectively idle before committing to a full process scan. > > To implement this, we utilise the standard get_avenrun() API to verify > the global system load. Tasks in the TASK_UNINTERRUPTIBLE (D) state > explicitly contribute to the system load average; consequently, if the > 1-minute load average is zero, we can confidently infer that no tasks > are currently hung, allowing us to bypass the expensive process scan. > > Crucially, we invoke get_avenrun(load, 0, 0) with both the offset and > shift parameters set to zero. This configuration is deliberate and > necessary for safety: > > 1. Zero Offset: Prevents the application of any artificial > rounding bias usually intended for human-readable display. > > 2. Zero Shift: Retrieves the raw fixed-point value (where 1.0 > load = 2048) rather than shifting it down to an integer. > > This ensures maximum sensitivity: even a microscopic fractional load > (e.g., a single task entering D state momentarily) will register as a > non-zero raw value. This guarantees that we never encounter a false > negative where a valid hung task is ignored due to integer truncation or > rounding errors. > > This heuristic significantly minimises the detector's footprint on > healthy systems whilst maintaining robust reliability for genuine hangs. > > Signed-off-by: Aaron Tomlin > --- > kernel/hung_task.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/kernel/hung_task.c b/kernel/hung_task.c > index d2254c91450b..7b9f5c1bd35e 100644 > --- a/kernel/hung_task.c > +++ b/kernel/hung_task.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -503,6 +504,7 @@ static int watchdog(void *dummy) > for ( ; ; ) { > unsigned long timeout = sysctl_hung_task_timeout_secs; > unsigned long interval = sysctl_hung_task_check_interval_secs; > + unsigned long load[3]; > long t; > > if (interval == 0) > @@ -511,8 +513,12 @@ static int watchdog(void *dummy) > t = hung_timeout_jiffies(hung_last_checked, interval); > if (t <= 0) { > if (!atomic_xchg(&reset_hung_task, 0) && > - !hung_detector_suspended) > - check_hung_uninterruptible_tasks(timeout); > + !hung_detector_suspended) { > + /* Check 1-min load to detect idle system */ > + get_avenrun(load, 0, 0); > + if (load[0] > 0) > + check_hung_uninterruptible_tasks(timeout); The optimization is not worth the trouble. I don't think the assumption that "load[0] == 0 means no hung tasks" is 100% correct. So that would miss actual hung tasks - a false negative, which is worse than the "wasted scan" you're trying to avoid. Also, I don't *really* care about optimizing something that runs once every 120 seconds :) Nacked-by: Lance Yang