Re: [PATCH v23 8/9] sched: Add blocked_donor link to task for smarter mutex handoffs

From: John Stultz

Date: Tue Nov 11 2025 - 02:51:17 EST


On Thu, Oct 30, 2025 at 10:03 PM K Prateek Nayak <kprateek.nayak@xxxxxxx> wrote:
> On 10/30/2025 5:48 AM, John Stultz wrote:
> > @@ -958,7 +964,34 @@ static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigne
> >
> > raw_spin_lock_irqsave(&lock->wait_lock, flags);
> > debug_mutex_unlock(lock);
> > - if (!list_empty(&lock->wait_list)) {
> > +
> > + if (sched_proxy_exec()) {
> > + raw_spin_lock(&current->blocked_lock);
> > + /*
> > + * If we have a task boosting current, and that task was boosting
> > + * current through this lock, hand the lock to that task, as that
> > + * is the highest waiter, as selected by the scheduling function.
> > + */
> > + donor = current->blocked_donor;
> > + if (donor) {
>
> Any concerns on new waiters always appearing as donors and in-turn
> starving the long time waiters on the list?
>
Hey!
So I'm not sure I'm quite following the concern. The scheduler picks
"the most important task in that moment" to run and we just want to
try to to pass the lock off to the donor that was boosting the lock
owner.

Are you concerned that new waiters would somehow always be further
left on the rq and would be selected as donors before other waiters on
the rq? I can sort of see the argument that "new waiters" would be
running until they try to get the lock, so they may have timeslice
still available to make them attractive to the scheduler as a donor,
so maybe they would be re-selected as a donor right away. But I'm
assuming at some point the fairness is going to cycle any waiting
donors up to the front of the rq to act as a donor and then have the
lock handed off.

That said, I don't see how this would be very much different from
new/running optimistic spinners having a better chance at grabbing a
lock then waiting tasks that aren't running.

But let me know more about what you're thinking of, as I'd like to
better understand it and see if I could contrive a test to produce
this sort of concerning behavior.

thanks
-john