Re: [PATCH] mm/page_alloc: Occasionally relinquish zone lock in batch freeing
From: Andrew Morton
Date: Tue Aug 19 2025 - 17:44:34 EST
On Tue, 19 Aug 2025 08:18:45 -0700 Joshua Hahn <joshua.hahnjy@xxxxxxxxx> 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.
cond_resched() might help because it takes more CPU cycles and expands
the window. A udelay() would of course do this more nicely.
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.
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.