mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Longlong Xia <xialonglong2025@163.com>, frederic@kernel.org
Cc: frederic@kernel.org, neeraj.upadhyay@kernel.org,
	joelagnelf@nvidia.com, josh@joshtriplett.org, boqun@kernel.org,
	urezki@gmail.com, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com,
	qiang.zhang@linux.dev, vineeth@bitbyteword.org,
	joel@joelfernandes.org, rcu@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Longlong Xia <xialonglong@kylinos.cn>
Subject: Re: [PATCH 1/1] rcu: fix shrink budget underflow in lazy_rcu_shrink_scan
Date: Thu, 27 Aug 2026 10:55:57 -0700	[thread overview]
Message-ID: <2dfd3f5c-0a06-4353-a9bf-ea9f9100a4ca@paulmck-laptop> (raw)
In-Reply-To: <20260824133142.2293426-1-xialonglong2025@163.com>

On Mon, Aug 24, 2026 at 09:31:42PM +0800, Longlong Xia wrote:
> From: Longlong Xia <xialonglong@kylinos.cn>
> 
> The lazy RCU shrinker decremented sc->nr_to_scan (unsigned long)
> and then tested the result with <= 0.  When a single CPU's lazy
> callback count exceeds the remaining budget, the subtraction wraps
> to a large positive value and the <= 0 comparison, which is
> equivalent to == 0 for an unsigned type, never fires again.  The
> scan loop then iterates through every nocb CPU instead of honouring
> the reclaim budget.
> 
> Reorder the logic to compare _count against nr_to_scan before
> subtracting, so the loop exits as soon as the budget is met.
> 
> Fixes: c945b4da7a448 ("rcu: Shrinker for lazy rcu")
> Assisted-by: Zcode:GLM-5.2
> Signed-off-by: Longlong Xia <xialonglong@kylinos.cn>

Good catch, and plausible fix.  Queued for further review and testing.

Frederic, thoughts?

							Thanx, Paul

> ---
>  kernel/rcu/tree_nocb.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
> index 19bb42672baf..afc3ab84cc47 100644
> --- a/kernel/rcu/tree_nocb.h
> +++ b/kernel/rcu/tree_nocb.h
> @@ -1332,10 +1332,11 @@ lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
>  		rcu_nocb_try_flush_bypass(rdp, jiffies);
>  		rcu_nocb_unlock_irqrestore(rdp, flags);
>  		wake_nocb_gp(rdp);
> -		sc->nr_to_scan -= _count;
>  		count += _count;
> -		if (sc->nr_to_scan <= 0)
> +
> +		if (_count >= sc->nr_to_scan)
>  			break;
> +		sc->nr_to_scan -= _count;
>  	}
>  
>  	mutex_unlock(&rcu_state.nocb_mutex);
> -- 
> 2.43.0
> 

      reply	other threads:[~2026-08-27 17:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 13:31 Longlong Xia
2026-08-27 17:55 ` Paul E. McKenney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2dfd3f5c-0a06-4353-a9bf-ea9f9100a4ca@paulmck-laptop \
    --to=paulmck@kernel.org \
    --cc=boqun@kernel.org \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=urezki@gmail.com \
    --cc=vineeth@bitbyteword.org \
    --cc=xialonglong2025@163.com \
    --cc=xialonglong@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®