Re: [RFC PATCH 1/1] mm/vmstat: decay pcp->high of isolated CPUs from vmstat_shepherd
From: sashiko-bot
Date: Fri Nov 27 2026 - 08:46:24 EST
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@xxxxxxxxxxxxx>
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@xxxxxxxxxxxxx?part=1