* [PATCH 1/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a drain
2026-11-25 21:27 [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Joshua Hahn
@ 2026-11-25 21:27 ` Joshua Hahn
2026-11-26 21:27 ` sashiko-bot
2026-11-25 21:27 ` [PATCH 2/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a refill Joshua Hahn
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Joshua Hahn @ 2026-11-25 21:27 UTC (permalink / raw)
To: Andrew Morton
Cc: Vlastimil Babka, Johannes Weiner, Suren Baghdasaryan,
Michal Hocko, Brendan Jackman, Zi Yan, linux-mm, kernel-team
Commit 574907741599 ("mm/page_alloc: leave IRQs enabled for per-cpu page
allocations") stopped disabling IRQs under the pcp lock. A softirq that
interrupts the holder always fails pcp_spin_trylock() and falls back to
taking zone->lock for each page, since the pcp lock is still held by the
interrupted process.
This is common when zone->lock is contended. free_pcppages_bulk() spins
on it with IRQs disabled, so an interrupt is often pending when it
unlocks, and happens with the pcp lock still held.
Restore IRQs only after dropping the pcp lock, and return with the pcp
unlocked. PREEMPT_RT keeps IRQs enabled.
With zone->lock contended in a 128-vCPU guest, tlb_remove_table_rcu()
callbacks hitting the fallback went from 93% to 7%, and the average
callback duration dropped from 14ms to 1.5ms. Throughput was unchanged.
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
---
mm/page_alloc.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index aa1ed599c7c6b..bc272f8d8ec75 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -141,6 +141,18 @@ static DEFINE_MUTEX(pcp_batch_high_lock);
pcpu_task_unpin(); \
})
+/*
+ * Like pcp_spin_unlock(), for callers that disabled IRQs (except on PREEMPT_RT)
+ * before taking zone->lock. An interrupt that arrives in between runs only once
+ * the pcp lock is dropped, so its softirqs can use the pcp lists. Disable IRQs
+ * after taking the pcp lock as other holders may be waiting for an IPI.
+ */
+#define pcp_spin_unlock_irqrestore(ptr, flags) \
+({ \
+ spin_unlock_irqrestore(&(ptr)->lock, flags); \
+ pcpu_task_unpin(); \
+})
+
/*
* On CONFIG_SMP=n the UP implementation of spin_trylock() never fails and thus
* is not compatible with our locking scheme. However we do not need pcp for
@@ -153,6 +165,9 @@ static DEFINE_MUTEX(pcp_batch_high_lock);
#define pcp_spin_unlock(ptr) \
BUG_ON(1)
+
+#define pcp_spin_unlock_irqrestore(ptr, flags) \
+ BUG_ON(1)
#endif
/*
@@ -2846,8 +2861,8 @@ static int nr_pcp_high(struct per_cpu_pages *pcp, struct zone *zone,
* Tune pcp alloc factor and adjust count & free_count. Free pages to bring the
* pcp's watermarks below high.
*
- * May return a freed pcp, if during page freeing the pcp spinlock cannot be
- * reacquired. Return true if pcp is locked, false otherwise.
+ * May return with the pcp unlocked after freeing pages to the buddy allocator.
+ * Return true if pcp is locked, false otherwise.
*/
static bool free_frozen_page_commit(struct zone *zone,
struct per_cpu_pages *pcp, struct page *page, int migratetype,
@@ -2904,14 +2919,19 @@ static bool free_frozen_page_commit(struct zone *zone,
to_free = nr_pcp_free(pcp, batch, high, free_high);
while (to_free > 0 && pcp->count > 0) {
+ unsigned long flags = 0;
+
to_free_batched = min(to_free, batch);
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ local_irq_save(flags);
free_pcppages_bulk(zone, to_free_batched, pcp, pindex);
to_free -= to_free_batched;
+ pcp_spin_unlock_irqrestore(pcp, flags);
- if (to_free == 0 || pcp->count == 0)
+ if (!to_free) {
+ ret = false;
break;
-
- pcp_spin_unlock(pcp);
+ }
pcp = pcp_spin_trylock(zone->per_cpu_pageset);
if (!pcp) {
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a drain
2026-11-25 21:27 ` [PATCH 1/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a drain Joshua Hahn
@ 2026-11-26 21:27 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-26 21:27 UTC (permalink / raw)
To: Joshua Hahn, Andrew Morton
Cc: Vlastimil Babka, Johannes Weiner, Suren Baghdasaryan,
Michal Hocko, Brendan Jackman, Zi Yan, linux-mm, kernel-team
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mm/page_alloc: unused-but-set flags variable in
free_frozen_page_commit()
--
commit d66ecc1b75f6ab35dc480b529fcd4baafd313549
Author: Joshua Hahn <joshua.hahnjy@gmail.com>
mm/page_alloc: drop the pcp lock before enabling IRQs after a drain
This commit disables IRQs before calling free_pcppages_bulk() and
restores them only after dropping the pcp lock, returning with the pcp
unlocked after draining pages.
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index aa1ed599c7c6b..bc272f8d8ec75 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -153,6 +165,9 @@ static DEFINE_MUTEX(pcp_batch_high_lock);
>
> #define pcp_spin_unlock(ptr) \
> BUG_ON(1)
> +
> +#define pcp_spin_unlock_irqrestore(ptr, flags) \
> + BUG_ON(1)
> #endif
[ ... ]
> @@ -2904,14 +2919,19 @@ static bool free_frozen_page_commit(struct zone *zone,
>
> to_free = nr_pcp_free(pcp, batch, high, free_high);
> while (to_free > 0 && pcp->count > 0) {
> + unsigned long flags = 0;
> +
> to_free_batched = min(to_free, batch);
> + if (!IS_ENABLED(CONFIG_PREEMPT_RT))
> + local_irq_save(flags);
> free_pcppages_bulk(zone, to_free_batched, pcp, pindex);
> to_free -= to_free_batched;
> + pcp_spin_unlock_irqrestore(pcp, flags);
[Severity: Low]
Does this trigger a -Wunused-but-set-variable warning on flags when built
with CONFIG_SMP=n, CONFIG_TRACE_IRQFLAGS=n, and W=1? With
CONFIG_TRACE_IRQFLAGS=n, local_irq_save(flags) only writes to flags, and
the !CONFIG_SMP definition of pcp_spin_unlock_irqrestore(ptr, flags) does
not evaluate flags.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125212730.1128631-1-joshua.hahnjy@gmail.com?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a refill
2026-11-25 21:27 [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Joshua Hahn
2026-11-25 21:27 ` [PATCH 1/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a drain Joshua Hahn
@ 2026-11-25 21:27 ` Joshua Hahn
2026-11-25 21:27 ` [PATCH 3/3] mm/page_alloc: disable IRQs around the remaining pcp drains Joshua Hahn
2026-12-01 1:40 ` [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Harry Yoo
3 siblings, 0 replies; 8+ messages in thread
From: Joshua Hahn @ 2026-11-25 21:27 UTC (permalink / raw)
To: Andrew Morton
Cc: Vlastimil Babka, Johannes Weiner, Suren Baghdasaryan,
Michal Hocko, Brendan Jackman, Zi Yan, linux-mm, kernel-team
rmqueue_pcplist() refills an empty pcp list with rmqueue_bulk(), which
spins on zone->lock with IRQs disabled. An interrupt that comes in
the meantime will run while the pcp lock is held, meaning the softirqs
fall back to taking zone->lock for each page.
When the list is empty, disable IRQs before the refill and restore them
only after dropping the pcp lock. PREEMPT_RT keeps IRQs enabled.
With zone->lock contended in a 128-vCPU guest, tlb_remove_table_rcu()
callbacks hitting the fallback went from 7% to 1.5% and the average
callback duration from 1.5ms to 0.6ms (the previous commit brought
these down from 93% and 14ms, respectively).
Note that alloc_pages_bulk_noprof() still refills with IRQs enabled
under the pcp lock. This one needs a different fix as it keeps the
lock across prep_new_page(), so leave this for future work.
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
---
mm/page_alloc.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index bc272f8d8ec75..0e669e206d371 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3405,6 +3405,8 @@ static struct page *rmqueue_pcplist(struct zone *preferred_zone,
struct per_cpu_pages *pcp;
struct list_head *list;
struct page *page;
+ unsigned long flags;
+ bool refill;
/* spin_trylock may fail due to a parallel drain or IRQ reentrancy. */
pcp = pcp_spin_trylock(zone->per_cpu_pageset);
@@ -3418,8 +3420,15 @@ static struct page *rmqueue_pcplist(struct zone *preferred_zone,
*/
pcp->free_count >>= 1;
list = &pcp->lists[order_to_pindex(migratetype, order)];
+ /* Refilling takes zone->lock, see pcp_spin_unlock_irqrestore() */
+ refill = !IS_ENABLED(CONFIG_PREEMPT_RT) && list_empty(list);
+ if (refill)
+ local_irq_save(flags);
page = __rmqueue_pcplist(zone, order, migratetype, alloc_flags, pcp, list);
- pcp_spin_unlock(pcp);
+ if (refill)
+ pcp_spin_unlock_irqrestore(pcp, flags);
+ else
+ pcp_spin_unlock(pcp);
if (page) {
__count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order);
zone_statistics(preferred_zone, zone, 1);
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/3] mm/page_alloc: disable IRQs around the remaining pcp drains
2026-11-25 21:27 [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Joshua Hahn
2026-11-25 21:27 ` [PATCH 1/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a drain Joshua Hahn
2026-11-25 21:27 ` [PATCH 2/3] mm/page_alloc: drop the pcp lock before enabling IRQs after a refill Joshua Hahn
@ 2026-11-25 21:27 ` Joshua Hahn
2026-12-01 1:40 ` [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Harry Yoo
3 siblings, 0 replies; 8+ messages in thread
From: Joshua Hahn @ 2026-11-25 21:27 UTC (permalink / raw)
To: Andrew Morton
Cc: Vlastimil Babka, Johannes Weiner, Suren Baghdasaryan,
Michal Hocko, Brendan Jackman, Zi Yan, linux-mm, kernel-team
decay_pcp_high(), drain_zone_pages(), and drain_pages_zone() also call
free_pcppages_bulk() under the pcp lock, so an interrupt can happen
with the lock still held.
Disable IRQs after taking the pcp lock and restore them after dropping
it. Note that we can't use spin_lock_irqsave() here since
drain_pages_zone() takes remote CPUs' pcp locks, whose holders keep
IRQs enabled and may be waiting for this CPU to answer an IPI.
PREEMPT_RT keeps IRQs enabled.
With zone->lock contended in a 128-vCPU guest, tlb_remove_table_rcu()
callbacks hitting the fallback went from 1.5% to 0.1% (the two previous
commits brought it down from 93% to 7% and then to 1.5%).
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
---
mm/page_alloc.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0e669e206d371..f2cbc820f24b7 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -178,6 +178,9 @@ static DEFINE_MUTEX(pcp_batch_high_lock);
spin_lock(&(ptr)->lock)
#define pcp_spin_unlock_nopin(ptr) \
spin_unlock(&(ptr)->lock)
+/* Like pcp_spin_unlock_irqrestore(), for callers that did not pin */
+#define pcp_spin_unlock_nopin_irqrestore(ptr, flags) \
+ spin_unlock_irqrestore(&(ptr)->lock, flags)
#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
DEFINE_PER_CPU(int, numa_node);
@@ -2599,6 +2602,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
{
int high_min, to_drain, to_drain_batched, batch;
+ unsigned long flags = 0;
bool todo = false;
high_min = READ_ONCE(pcp->high_min);
@@ -2619,8 +2623,10 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
while (to_drain > 0) {
to_drain_batched = min(to_drain, batch);
pcp_spin_lock_nopin(pcp);
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ local_irq_save(flags);
free_pcppages_bulk(zone, to_drain_batched, pcp, 0);
- pcp_spin_unlock_nopin(pcp);
+ pcp_spin_unlock_nopin_irqrestore(pcp, flags);
todo = true;
to_drain -= to_drain_batched;
@@ -2637,14 +2643,17 @@ bool decay_pcp_high(struct zone *zone, struct per_cpu_pages *pcp)
*/
void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
{
+ unsigned long flags = 0;
int to_drain, batch;
batch = READ_ONCE(pcp->batch);
to_drain = min(pcp->count, batch);
if (to_drain > 0) {
pcp_spin_lock_nopin(pcp);
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ local_irq_save(flags);
free_pcppages_bulk(zone, to_drain, pcp, 0);
- pcp_spin_unlock_nopin(pcp);
+ pcp_spin_unlock_nopin_irqrestore(pcp, flags);
}
}
#endif
@@ -2655,10 +2664,13 @@ void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
static void drain_pages_zone(unsigned int cpu, struct zone *zone)
{
struct per_cpu_pages *pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu);
+ unsigned long flags = 0;
int count;
do {
pcp_spin_lock_nopin(pcp);
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ local_irq_save(flags);
count = pcp->count;
if (count) {
int to_drain = min(count,
@@ -2667,7 +2679,7 @@ static void drain_pages_zone(unsigned int cpu, struct zone *zone)
free_pcppages_bulk(zone, to_drain, pcp, 0);
count -= to_drain;
}
- pcp_spin_unlock_nopin(pcp);
+ pcp_spin_unlock_nopin_irqrestore(pcp, flags);
} while (count);
}
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs
2026-11-25 21:27 [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Joshua Hahn
` (2 preceding siblings ...)
2026-11-25 21:27 ` [PATCH 3/3] mm/page_alloc: disable IRQs around the remaining pcp drains Joshua Hahn
@ 2026-12-01 1:40 ` Harry Yoo
2026-12-01 16:24 ` Joshua Hahn
3 siblings, 1 reply; 8+ messages in thread
From: Harry Yoo @ 2026-12-01 1:40 UTC (permalink / raw)
To: Joshua Hahn
Cc: Andrew Morton, Vlastimil Babka, Johannes Weiner,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
linux-mm, kernel-team
Hi Joshua!
On Wed, Nov 25, 2026 at 01:27:24PM -0800, Joshua Hahn wrote:
> When the zone lock needs to be acquired from within the pcp lock
> (due to refills or drains), IRQs are disabled to prevent deadlocks
> with the IRQ handler. Today it looks like this:
>
> pcp lock
> IRQ disabled
> zone lock
> zone unlock
> IRQ enabled
> pcp unlock
>
> So any interrupt that queues during the IRQ disabled section fires
> before the pcp unlock. This is not a rare operation; the zone lock
> remains one of the most contended locks on large systems.
>
> Together, those two observations mean that any IRQ handler that requires
> taking the pcp lock will fire before the interrupted task can let go of
> the pcp lock, and the handler will always fall back to the already
> contended zone lock.
Interestingly, this was anticipated when it was converted to a
spin_trylock without disabling IRQs.
[1] https://lore.kernel.org/all/20221118101714.19590-1-mgorman@techsingularity.net
"Demote the lock to pcp_spin_lock avoids an IRQ disable/enable in the common
case at the cost of some IRQ allocations taking a slower path. If the PCP
lists need to be refilled, the zone lock still needs to disable IRQs but
that will only happen on PCP refill and drain. If an IRQ is raised when
a PCP allocation is in progress, the trylock will fail and fallback to
using the buddy lists directly. Note that this may not be a universal win
if an interrupt-intensive workload also allocates heavily from interrupt
context and contends heavily on the zone->lock as a result."
Apparenlty back then it was considered to be a corner case...
> In Meta production workloads, we've seen softlockups on large machines
> where one CPU spent 23s in an RCU softirq freeing page tables, and
> taking zone->lock once per page because it had interrupted a task
> already holding the pcp lock.
But now it has become easer to hit by freeing page tables by RCU ([2]
has a good summary of this)
[2] https://lore.kernel.org/linux-mm/20260925-rcu-pagetable-freeing-v5-0-31e91065fea4@kernel.org
> Instead, keep the IRQ disabled until the pcp unlock, so that interrupt
> handlers can have a better chance at taking the pcp lock and relieving
> contention on the zone lock:
>
> pcp lock
> IRQ disabled
> zone lock
> zone unlock
> pcp unlock
> IRQ enabled
The PCP lock is already complicated and now we're trying to add more
complexity only to avoid disabling and enabling IRQ around the PCP
lock in the common path.
We should probably revisit the tradeoff made in [1] instead of adding
more complexity, what do you think?
> This series was tested on a 128-vCPU KVM guest, where every vCPU faults
> in and MADV_DONTNEEDs in a loop. The "pcp fallbacks" (taking the zone
> lock instead of the pcp lock) and long softirqs were summed across 6
> runs of 30 seconds each.
>
> +----------+---------------+-------------------+-----------------+
> | | pcp fallbacks | callback avg (ms) | softirqs > 65ms |
> +----------+---------------+-------------------+-----------------+
> | mm-new | 135590 | 14 | 832 |
> | +patch 1 | 10481 | 1.5 | 116 |
> | +patch 2 | 2327 | 0.6 | 55 |
> | +patch 3 | 190 | 0.6 | 10 |
> +----------+---------------+-------------------+-----------------+
>
> Running the same tests with PROVE_LOCKING, DEBUG_VM, and DEBUG_PREEMPT
> also raised no concerns.
>
> Joshua Hahn (3):
> mm/page_alloc: drop the pcp lock before enabling IRQs after a drain
> mm/page_alloc: drop the pcp lock before enabling IRQs after a refill
> mm/page_alloc: disable IRQs around the remaining pcp drains
>
> mm/page_alloc.c | 59 +++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 50 insertions(+), 9 deletions(-)
>
>
> base-commit: 9f004372ebeb18fdeb699f9880a0e472df90135b
> --
> 2.53.1-Meta
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs
2026-12-01 1:40 ` [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Harry Yoo
@ 2026-12-01 16:24 ` Joshua Hahn
2026-12-01 16:56 ` Harry Yoo
0 siblings, 1 reply; 8+ messages in thread
From: Joshua Hahn @ 2026-12-01 16:24 UTC (permalink / raw)
To: Harry Yoo
Cc: Andrew Morton, Vlastimil Babka, Johannes Weiner,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
Mel Gorman, linux-mm, kernel-team
On Tue, Dec 01, 2026 at 01:40:08AM +0000, Harry Yoo wrote:
> Hi Joshua!
Hi Harry, I hope you're doing well, thanks for taking a look at this!
> On Wed, Nov 25, 2026 at 01:27:24PM -0800, Joshua Hahn wrote:
> > When the zone lock needs to be acquired from within the pcp lock
> > (due to refills or drains), IRQs are disabled to prevent deadlocks
> > with the IRQ handler. Today it looks like this:
> >
> > pcp lock
> > IRQ disabled
> > zone lock
> > zone unlock
> > IRQ enabled
> > pcp unlock
> >
> > So any interrupt that queues during the IRQ disabled section fires
> > before the pcp unlock. This is not a rare operation; the zone lock
> > remains one of the most contended locks on large systems.
> >
> > Together, those two observations mean that any IRQ handler that requires
> > taking the pcp lock will fire before the interrupted task can let go of
> > the pcp lock, and the handler will always fall back to the already
> > contended zone lock.
>
> Interestingly, this was anticipated when it was converted to a
> spin_trylock without disabling IRQs.
>
> [1] https://lore.kernel.org/all/20221118101714.19590-1-mgorman@techsingularity.net
>
> "Demote the lock to pcp_spin_lock avoids an IRQ disable/enable in the common
> case at the cost of some IRQ allocations taking a slower path. If the PCP
> lists need to be refilled, the zone lock still needs to disable IRQs but
> that will only happen on PCP refill and drain. If an IRQ is raised when
> a PCP allocation is in progress, the trylock will fail and fallback to
> using the buddy lists directly. Note that this may not be a universal win
> if an interrupt-intensive workload also allocates heavily from interrupt
> context and contends heavily on the zone->lock as a result."
>
> Apparenlty back then it was considered to be a corner case...
Ah I see, thanks for the context.
> > In Meta production workloads, we've seen softlockups on large machines
> > where one CPU spent 23s in an RCU softirq freeing page tables, and
> > taking zone->lock once per page because it had interrupted a task
> > already holding the pcp lock.
>
> But now it has become easer to hit by freeing page tables by RCU ([2]
> has a good summary of this)
>
> [2] https://lore.kernel.org/linux-mm/20260925-rcu-pagetable-freeing-v5-0-31e91065fea4@kernel.org
Yup, it seems like that is the case. I do think both of the series make
sense and it wouldn't have been entirely obvious to find the interaction
at the time.
> > Instead, keep the IRQ disabled until the pcp unlock, so that interrupt
> > handlers can have a better chance at taking the pcp lock and relieving
> > contention on the zone lock:
> >
> > pcp lock
> > IRQ disabled
> > zone lock
> > zone unlock
> > pcp unlock
> > IRQ enabled
>
> The PCP lock is already complicated and now we're trying to add more
> complexity only to avoid disabling and enabling IRQ around the PCP
> lock in the common path.
>
> We should probably revisit the tradeoff made in [1] instead of adding
> more complexity, what do you think?
Yeah, I think this is very reasonable :p It does seem like a lot to
remember about when the IRQ is enabled / disabled and who needs to
remember what... I also did not really like the fact that the locking
and IRQ toggling wouldn't be FILO if we switched the order of the
pcp unlock and IRQ enabling.
Anyways, let me do some benchmarking to revisit the cost and the
tradeoffs. It would essentially be a revert of Mel's commit but I think
there's been a lot of changes on top of it over the years, it might
be a bit more plumbing than a simple revert.
I've also CCed Mel here, in case he has any thoughts on this : -)
Thanks for going through and gathering all the context for this Harry.
I hope you have a great day!
Joshua
> > This series was tested on a 128-vCPU KVM guest, where every vCPU faults
> > in and MADV_DONTNEEDs in a loop. The "pcp fallbacks" (taking the zone
> > lock instead of the pcp lock) and long softirqs were summed across 6
> > runs of 30 seconds each.
> >
> > +----------+---------------+-------------------+-----------------+
> > | | pcp fallbacks | callback avg (ms) | softirqs > 65ms |
> > +----------+---------------+-------------------+-----------------+
> > | mm-new | 135590 | 14 | 832 |
> > | +patch 1 | 10481 | 1.5 | 116 |
> > | +patch 2 | 2327 | 0.6 | 55 |
> > | +patch 3 | 190 | 0.6 | 10 |
> > +----------+---------------+-------------------+-----------------+
> >
> > Running the same tests with PROVE_LOCKING, DEBUG_VM, and DEBUG_PREEMPT
> > also raised no concerns.
> >
> > Joshua Hahn (3):
> > mm/page_alloc: drop the pcp lock before enabling IRQs after a drain
> > mm/page_alloc: drop the pcp lock before enabling IRQs after a refill
> > mm/page_alloc: disable IRQs around the remaining pcp drains
> >
> > mm/page_alloc.c | 59 +++++++++++++++++++++++++++++++++++++++++--------
> > 1 file changed, 50 insertions(+), 9 deletions(-)
> >
> >
> > base-commit: 9f004372ebeb18fdeb699f9880a0e472df90135b
> > --
> > 2.53.1-Meta
>
> --
> Cheers,
> Harry / Hyeonggon
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs
2026-12-01 16:24 ` Joshua Hahn
@ 2026-12-01 16:56 ` Harry Yoo
0 siblings, 0 replies; 8+ messages in thread
From: Harry Yoo @ 2026-12-01 16:56 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka, Johannes Weiner,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
Mel Gorman, linux-mm, kernel-team, rientjes
On Tue, Dec 01, 2026 at 08:24:31AM -0800, Joshua Hahn wrote:
> On Tue, Dec 01, 2026 at 01:40:08AM +0000, Harry Yoo wrote:
> > Hi Joshua!
>
> Hi Harry, I hope you're doing well, thanks for taking a look at this!
No problem :-)
> > On Wed, Nov 25, 2026 at 01:27:24PM -0800, Joshua Hahn wrote:
> Anyways, let me do some benchmarking to revisit the cost and the
> tradeoffs.
Thanks a lot Joshua!
Let's see where it goes.
There is a page allocator benchmark [1] posted recently from David Rientjes
[1] https://lore.kernel.org/linux-mm/20261129212551.1812084-2-rientjes@google.com
which could be helpful here.
It might add few tens of CPU cycles but IMHO in this case some
regression in microbenchmark isn't that critical...
Looking at commit messages from Mel apparently there are a couple of his
favourite macrobenchmarks in mmtests [2] that would be more useful to
measure a bit more realistsic performance impact of this.
[2] https://github.com/gormanm/mmtests
It might slightly impact performance but likely it'd be in (IMHO)
a acceptable range in terms of justifying complexity.
... of course we don't know before actually measuring it :P
> It would essentially be a revert of Mel's commit but I think
> there's been a lot of changes on top of it over the years, it might
> be a bit more plumbing than a simple revert.
Yeah I can imagine that... :) again thanks for working on this!
I'm happy to review further development of this.
> Thanks for going through and gathering all the context for this Harry.
> I hope you have a great day!
Have a nice day too Joshua, thanks.
> Joshua
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 8+ messages in thread