From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Joshua Hahn <joshua.hahnjy@gmail.com>, Harry Yoo <harry@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.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>, Mel Gorman <mgorman@techsingularity.net>,
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: Wed, 2 Dec 2026 20:11:30 +0100 [thread overview]
Message-ID: <e0ebb1a8-459e-420b-b831-e1ad9cc3a16a@kernel.org> (raw)
In-Reply-To: <20261202182114.2250433-1-joshua.hahnjy@gmail.com>
On 12/2/26 19:32, Joshua Hahn wrote:
> On Wed, Dec 02, 2026 at 03:24:16AM +0000, Harry Yoo wrote:
>> On Tue, Dec 01, 2026 at 11:53:48PM +0000, Harry Yoo wrote:
>> > On Tue, Dec 01, 2026 at 02:05:57PM -0800, Joshua Hahn wrote:
>> > > > > 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.
>> > >
>> > > Hey Harry, so I did some quick prototyping with AI (diff at the end).
>> >
>> > We don't need pcpu_task_pin()/unpin() if we disable IRQs
>>
>> Sorry this is not exactly something we've had in the past, so I need to
>> describe it further.
>>
>> > and so the
>> > regression might be overestimated as we disable migration AND IRQs.
>>
>> It's not "overestimated" in terms of measuring performance of the
>> revert... but it's still silly to disable both preemption and IRQs
>> and we can probably do better here.
>>
>> pcp_spin_trylock() on !RT should disable IRQs first and then call
>> spin_trylock().
>>
>> on RT it should disable migration and then call spin_trylock().
>>
>> This avoids allocating pages from a different CPU's PCP by mistake
>> due to task migration.
>
> Hi Harry,
>
> That makes a lot of sense, I tried the change the way you described, so
> on !RT pcp_spin_trylock() is just local_irq_save() and spin_trylock(),
> and on RT it's migrate_disable() and then spin_trylock().
>
> I ran the benchmarks again with the changes, this one is David's
> benchmark (alloc_pages() + __free_pages() on one CPU). The value is
> mean time it took in ns +- the standard deviation, across 50 runs:
>
> +---------+-------------+-------------+-------------+
> | | mm-new | revert | no-pin |
> +---------+-------------+-------------+-------------+
> | order-0 | 80.0 +- 0.9 | 85.2 +- 0.3 | 85.5 +- 0.5 |
> | order-1 | 79.7 +- 0.4 | 88.1 +- 0.4 | 87.0 +- 0.0 |
> | order-3 | 85.9 +- 0.9 | 95.5 +- 1.1 | 94.6 +- 0.7 |
> +---------+-------------+-------------+-------------+
>
> Unfortunately it seems like the majority of the cost comes from the IRQ,
> the pin is only about 1 ns compared to the revert only.
Wonder if we can have our cake and eat it too?
No irq disabling for the fast path, when we take or return a pcplist page
and don't need to refill or flush.
Relock with irq disabled for the refill/flush.
Always a risk something changes while we relock, but we already handle that
e.g. in the flushing with the periodic unlock you added a while ago.
Woud it be feasible?
> And this is the result for will-it-scale (process mode). Here the value
> is millions of faults per sec, also for mean +- standard deviation.
> So higher is better here. Across 5 runs I got:
>
> page_fault1:
> +-------+----------------+------------------------+------------------------+
> | tasks | mm-new | revert | no-pin |
> +-------+----------------+------------------------+------------------------+
> | 1 | 1.065 +- 0.021 | 1.060 +- 0.004 (-0.4%) | 1.077 +- 0.003 (+1.2%) |
> | 16 | 7.073 +- 0.379 | 7.170 +- 0.088 (+1.4%) | 7.452 +- 0.131 (+5.4%) |
> | 64 | 6.921 +- 0.262 | 6.897 +- 0.308 (-0.3%) | 7.091 +- 0.260 (+2.5%) |
> | 128 | 6.208 +- 0.159 | 6.154 +- 0.372 (-0.9%) | 6.334 +- 0.439 (+2.0%) |
> +-------+----------------+------------------------+------------------------+
>
> page_fault2:
> +-------+----------------+------------------------+------------------------+
> | tasks | mm-new | revert | no-pin |
> +-------+----------------+------------------------+------------------------+
> | 1 | 0.743 +- 0.036 | 0.728 +- 0.028 (-1.9%) | 0.765 +- 0.037 (+2.9%) |
> | 16 | 5.213 +- 0.044 | 5.267 +- 0.052 (+1.0%) | 5.249 +- 0.112 (+0.7%) |
> | 64 | 6.675 +- 0.077 | 6.467 +- 0.045 (-3.1%) | 6.748 +- 0.122 (+1.1%) |
> | 128 | 6.277 +- 0.193 | 6.330 +- 0.247 (+0.8%) | 6.306 +- 0.221 (+0.5%) |
> +-------+----------------+------------------------+------------------------+
>
> Compared to before, it seems like we get much better results this time,
> and this is probably more reflective of what we end up seeing in real
> workloads anyways. But note that the standard deviation looks pretty
> high and all the gains are within the standard deviation, so I wouldn't
> read too much into the + as a real win :p
>
> At least we know it isn't regressing too obviously.
>
> Everything considered I think this is:
> - Around 5-9 ns per alloc/free pair in a microbenchmark
> - No real difference to throughput in realistic workloads
prev parent reply other threads:[~2026-12-02 19:11 UTC|newest]
Thread overview: 13+ 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 ` [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
2026-12-01 22:05 ` Joshua Hahn
2026-12-01 23:53 ` Harry Yoo
2026-12-02 3:24 ` Harry Yoo
2026-12-02 18:32 ` Joshua Hahn
2026-12-02 19:11 ` Vlastimil Babka (SUSE) [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=e0ebb1a8-459e-420b-b831-e1ad9cc3a16a@kernel.org \
--to=vbabka@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=harry@kernel.org \
--cc=joshua.hahnjy@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@suse.com \
--cc=surenb@google.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