From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>, Chris Mason <clm@fb.com>,
Vlastimil Babka <vbabka@suse.cz>,
Suren Baghdasaryan <surenb@gogle.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <jackmanb@google.com>, Zi Yan <ziy@nvidia.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com, Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH] mm/page_alloc: Occasionally relinquish zone lock in batch freeing
Date: Wed, 20 Aug 2025 06:20:32 -0700 [thread overview]
Message-ID: <20250820132033.1267317-1-joshua.hahnjy@gmail.com> (raw)
In-Reply-To: <20250819144421.7a52f8df3f0fe5c315f90aa2@linux-foundation.org>
On Tue, 19 Aug 2025 14:44:21 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> On Tue, 19 Aug 2025 08:18:45 -0700 Joshua Hahn <joshua.hahnjy@gmail.com> wrote:
>
> > > Pretty this isn't.
> > >
> > > Sigh, we do so much stuff here and in __free_one_page().
> > >
> > > What sort of guarantee do we have that the contending task will be able
> > > to get in and grab the spinlock in that tiny time window?
> >
> > Thank you for pointing this out -- I don't think there is any guarantee.
> > Kiryl suggested that I put a cond_resched() here, in order to guarantee that
> > the contending tasks will be able to grab the spinlock. I think that's a great
> > idea -- I'll make this change in v2.
Hello Andrew, thank you for your review!
> cond_resched() might help because it takes more CPU cycles and expands
> the window. A udelay() would of course do this more nicely.
I was wondering if we could rely on the spinlock implementation here in order
to allow some fairness in who grabs the lock. From what I have gathered, on
a lot of architectures, the default implementation for spin locks use a
queued spin lock (on x86 and arm64, among others, just by doing a quick
grep for "select ARCH_USE_QUEUED_SPINLOCKS"). This means that whoever was
waiting the longest for the spin lock will be able to grab it, guaranteeing
that this function doesn't immediately lock again.
With that said, I understand that the solution should be generic and work for
all architectures. I wonder if it would make sense to change the zone lock
into an explicit queued spin lock?
> But the contending task is already in state TASK_RUNNING so a
> cond_resched() won't have any effect on it?
>
> Also, callers hold pcp->lock, so cond_resched() cannot be called.
Ah yes, that makes sense.
> Sigh, I dunno, it's all very nasty. I have vague memories of there
> being a way of relinquishing a lock to some other task which is
> spinning on that lock. Or at least, a proposal. Or I dreamed it.
> peterz would be a good person to ask.
Cc-ing Peter, please let us know if you have any thoughts about all of this!
Thank you Andrew, I hope you have a great day!
Joshua
next prev parent reply other threads:[~2025-08-20 13:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 18:58 [PATCH] mm/page_alloc: Occasionally relinquish zone lock in batch freeing Joshua Hahn
2025-08-19 0:13 ` Andrew Morton
2025-08-19 15:18 ` Joshua Hahn
2025-08-19 21:44 ` Andrew Morton
2025-08-20 13:20 ` Joshua Hahn [this message]
2025-08-19 9:15 ` Kiryl Shutsemau
2025-08-19 15:28 ` Joshua Hahn
2025-08-19 17:15 ` Shakeel Butt
2025-08-20 12:58 ` Kiryl Shutsemau
2025-08-19 15:34 ` Joshua Hahn
2025-08-20 1:29 ` Hillf Danton
2025-08-20 15:13 ` Joshua Hahn
2025-08-21 1:03 ` Hillf Danton
2025-08-20 5:41 ` Andrew Morton
2025-08-20 15:48 ` Joshua Hahn
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=20250820132033.1267317-1-joshua.hahnjy@gmail.com \
--to=joshua.hahnjy@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=clm@fb.com \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=peterz@infradead.org \
--cc=surenb@gogle.com \
--cc=vbabka@suse.cz \
--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;
as well as URLs for NNTP newsgroup(s).