All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harry Yoo <harry@kernel.org>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 Vlastimil Babka <vbabka@kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	 Brendan Jackman <brendan.jackman@linux.dev>,
	Zi Yan <ziy@nvidia.com>,
	linux-mm@kvack.org,  kernel-team@meta.com
Subject: Re: [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs
Date: Tue, 1 Dec 2026 01:40:08 +0000	[thread overview]
Message-ID: <aw4XIYgoOCDA0ND8@minisforum> (raw)
In-Reply-To: <20261125212730.1128631-1-joshua.hahnjy@gmail.com>

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


  parent reply	other threads:[~2026-12-01  1:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-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
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 [this message]
2026-12-01 16:24   ` [PATCH 0/3] mm/page_alloc: drop the pcp lock before re-enabling IRQs Joshua Hahn
2026-12-01 16:56     ` Harry Yoo
2026-12-01 22:05     ` Joshua Hahn
2026-12-01 23:53       ` Harry Yoo
2026-12-02  3:24         ` Harry Yoo

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=aw4XIYgoOCDA0ND8@minisforum \
    --to=harry@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.jackman@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.