mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ionut Nechita (Wind River)" <ionut.nechita@windriver.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	linux-mm@kvack.org
Cc: "Vlastimil Babka" <vbabka@kernel.org>,
	"Michal Hocko" <mhocko@suse.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Brendan Jackman" <brendan.jackman@linux.dev>,
	"Zi Yan" <ziy@nvidia.com>, "David Hildenbrand" <david@kernel.org>,
	"Liam R . Howlett" <liam@infradead.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Huang Ying" <ying.huang@linux.alibaba.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Clark Williams" <clrkwllms@kernel.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	linux-rt-devel@lists.linux.dev, ionut_n2001@yahoo.com,
	sunlightlinux@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd
Date: Fri, 27 Nov 2026 13:46:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-237513@kernel.org> (raw)
In-Reply-To: <20261126134410.17447-2-ionut.nechita@windriver.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm: stale drain count and extra lock bounce in
  decay_pcp_high()
- [Low] mm: data race on pcp->high_min and pcp->batch in
  decay_pcp_high()
--

commit d20e26af9bbff82ca7f7d0c2d4fea5dc5d2bd609
Author: Ionut Nechita <ionut.nechita@windriver.com>

mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd

This commit makes vmstat_shepherd() remotely decay pcp->high and drain
excess per-CPU pages for isolated CPUs, acquiring pcp->lock while
adjusting pcp->high in decay_pcp_high().

> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index ce44b8fc45aaf..aa9904eaf6e62 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2586,8 +2586,13 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
>  	int high_min, to_drain, to_drain_batched, batch;
>  	bool todo = false;
>  
> -	high_min = READ_ONCE(pcp->high_min);
> -	batch = READ_ONCE(pcp->batch);
> +	/*
> +	 * pcp->lock is taken because the pageset may belong to a remote CPU,
> +	 * see decay_pcp_high_cpu().
> +	 */
> +	pcp_spin_lock_nopin(pcp);
> +	high_min = pcp->high_min;
> +	batch = pcp->batch;

[Severity: Low]
Should pcp->high_min and pcp->batch still be read with READ_ONCE() here?

pageset_update() updates pcp->batch and pcp->high_min with WRITE_ONCE()
under pcp_batch_high_lock without taking pcp->lock, so plain loads can
data race and allow the compiler to reload them across the comparisons
and max3() / min() calls below.

>  	/*
>  	 * Decrease pcp->high periodically to try to free possible
>  	 * idle PCP pages.  And, avoid to free too many pages to
> @@ -2601,6 +2606,7 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
>  	}
>  
>  	to_drain = pcp->count - pcp->high;
> +	pcp_spin_unlock_nopin(pcp);
>  	while (to_drain > 0) {
>  		to_drain_batched = min(to_drain, batch);
>  		pcp_spin_lock_nopin(pcp);

[Severity: Medium]
Can dropping pcp->lock before and between drain batches without
rechecking pcp->count - pcp->high over-drain the remote PCP list and
spin on pcp->lock and zone->lock?

When decay_pcp_high() runs remotely from vmstat_shepherd(), the isolated
CPU can allocate from PCP or drain its own PCP list in
free_frozen_page_commit() while pcp->lock is dropped.  Because the loop
keeps draining the stale to_drain count rather than re-evaluating
pcp->count - pcp->high under pcp->lock, it can drain the isolated CPU's
PCP cache down to 0, well below pcp->high:

CPU0 (vmstat_shepherd)            CPU1 (isolated)
decay_pcp_high_cpu(1)
  decay_pcp_high(zone, pcp)
    pcp_spin_lock_nopin(pcp)
    pcp->high = ...
    to_drain = pcp->count - pcp->high
    pcp_spin_unlock_nopin(pcp)
                                  rmqueue_pcplist() / free_frozen_page_commit()
                                    /* lowers pcp->count to <= pcp->high */
    while (to_drain > 0)
      pcp_spin_lock_nopin(pcp)
      free_pcppages_bulk(...)     <-- drains below pcp->high, down to 0
      pcp_spin_unlock_nopin(pcp)

Once pcp->count reaches 0 with to_drain > 0 remaining, the loop keeps
running every remaining batch iteration, taking the remote pcp->lock and
calling free_pcppages_bulk(), which unconditionally disables IRQs and
takes zone->lock even when count is clamped to 0.  Also, unlocking
pcp->lock right before the loop and immediately re-locking it for the
first batch adds an extra remote lock bounce when to_drain > 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126134410.17447-1-ionut.nechita@windriver.com?part=1

      reply	other threads:[~2026-11-27 13:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:44 [RFC PATCH 0/1] mm: pcp->high is never decayed on isolated CPUs Ionut Nechita (Wind River)
2026-11-26 13:44 ` [RFC PATCH 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd Ionut Nechita (Wind River)
2026-11-27 13:46   ` sashiko-bot [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=sashiko-outbox-237513@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=brendan.jackman@linux.dev \
    --cc=clrkwllms@kernel.org \
    --cc=david@kernel.org \
    --cc=frederic@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=ionut.nechita@windriver.com \
    --cc=ionut_n2001@yahoo.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mhocko@suse.com \
    --cc=mtosatti@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sunlightlinux@gmail.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.com \
    /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®