[PATCH v2 0/8] mm: use spinlock guards for zone lock

Dmitry Ilvokhin posted 8 patches 5 days, 21 hours ago
mm/page_alloc.c     | 53 ++++++++++++-----------------------
mm/page_isolation.c | 67 +++++++++++++++++++--------------------------
2 files changed, 45 insertions(+), 75 deletions(-)
[PATCH v2 0/8] mm: use spinlock guards for zone lock
Posted by Dmitry Ilvokhin 5 days, 21 hours ago
This series uses spinlock guard for zone lock across several mm
functions to replace explicit lock/unlock patterns with automatic
scope-based cleanup.

This simplifies the control flow by removing 'flags' variables, goto
labels, and redundant unlock calls.

Patches are ordered by decreasing value. The first six patches simplify
the control flow by removing gotos, multiple unlock paths, or 'ret'
variables. The last two are simpler lock/unlock pair conversions that
only remove 'flags' and can be dropped if considered unnecessary churn.

Based on mm-stable.

Suggested-by: Steven Rostedt <rostedt@goodmis.org>

v1 -> v2:

- Andrew Morton raised concerns about binary size increase in v1.
  Peter Zijlstra has since fixed the underlying issue in the guards
  infrastructure in tip [1]. Note: the fix is not yet in mm-stable, so
  it needs to be applied first to reproduce these results. With that
  fix, bloat-o-meter on x86 defconfig shows a net decrease of 49 bytes
  (-0.12%) for page_alloc.o.
- Rebased on mm-stable, since the patch this series depended on was
  dropped from mm-new.
- Converted guard(zone_lock_irqsave)(zone) to
  guard(spinlock_irqsave)(&zone->lock).
- Dropped redundant braces in unreserve_highatomic_pageblock()
  (Steven Rostedt)

v1: https://lore.kernel.org/all/cover.1772811429.git.d@ilvokhin.com/

[1]: https://lore.kernel.org/all/20260309164516.GE606826@noisy.programming.kicks-ass.net/

Dmitry Ilvokhin (8):
  mm: use zone lock guard in reserve_highatomic_pageblock()
  mm: use zone lock guard in unset_migratetype_isolate()
  mm: use zone lock guard in unreserve_highatomic_pageblock()
  mm: use zone lock guard in set_migratetype_isolate()
  mm: use zone lock guard in take_page_off_buddy()
  mm: use zone lock guard in put_page_back_buddy()
  mm: use zone lock guard in free_pcppages_bulk()
  mm: use zone lock guard in __offline_isolated_pages()

 mm/page_alloc.c     | 53 ++++++++++++-----------------------
 mm/page_isolation.c | 67 +++++++++++++++++++--------------------------
 2 files changed, 45 insertions(+), 75 deletions(-)

-- 
2.52.0
Re: [PATCH v2 0/8] mm: use spinlock guards for zone lock
Posted by Andrew Morton 5 days, 17 hours ago
On Fri, 27 Mar 2026 16:14:40 +0000 Dmitry Ilvokhin <d@ilvokhin.com> wrote:

> This series uses spinlock guard for zone lock across several mm
> functions to replace explicit lock/unlock patterns with automatic
> scope-based cleanup.
> 
> This simplifies the control flow by removing 'flags' variables, goto
> labels, and redundant unlock calls.
> 
> Patches are ordered by decreasing value. The first six patches simplify
> the control flow by removing gotos, multiple unlock paths, or 'ret'
> variables. The last two are simpler lock/unlock pair conversions that
> only remove 'flags' and can be dropped if considered unnecessary churn.

Thanks, you've been busy.

I'm not wanting to move new, non-fix, non-speedup things into mm.git
until after -rc1 so there's your target.  But now is a good time to be
sending out material for people to look at.  Let's not have a gigantic
flood of new stuff the day after -rc1!

I think progress here is totally dependent on whether those who
regularly work on this code want guard() in there.  A
preference/familiarity/style choice, mainly.  At present the adoption
of guard() in mm/*.c is very small.
Re: [PATCH v2 0/8] mm: use spinlock guards for zone lock
Posted by Dmitry Ilvokhin 2 days, 21 hours ago
On Fri, Mar 27, 2026 at 01:11:20PM -0700, Andrew Morton wrote:
> On Fri, 27 Mar 2026 16:14:40 +0000 Dmitry Ilvokhin <d@ilvokhin.com> wrote:
> 
> > This series uses spinlock guard for zone lock across several mm
> > functions to replace explicit lock/unlock patterns with automatic
> > scope-based cleanup.
> > 
> > This simplifies the control flow by removing 'flags' variables, goto
> > labels, and redundant unlock calls.
> > 
> > Patches are ordered by decreasing value. The first six patches simplify
> > the control flow by removing gotos, multiple unlock paths, or 'ret'
> > variables. The last two are simpler lock/unlock pair conversions that
> > only remove 'flags' and can be dropped if considered unnecessary churn.
> 
> Thanks, you've been busy.
> 
> I'm not wanting to move new, non-fix, non-speedup things into mm.git
> until after -rc1 so there's your target.  But now is a good time to be
> sending out material for people to look at.  Let's not have a gigantic
> flood of new stuff the day after -rc1!
> 
> I think progress here is totally dependent on whether those who
> regularly work on this code want guard() in there.  A
> preference/familiarity/style choice, mainly.  At present the adoption
> of guard() in mm/*.c is very small.
> 

Thanks for taking a look, Andrew.

I'm not aiming for any particular merge window here. I had some time to
revisit the previous version and rework it, so I sent this now mainly to
keep the discussion going.

I agree this probably comes down to whether people are comfortable with
using guard() in this code. It'd be great to hear what others working in
mm, and in page_alloc in particular, think.