public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ding Tianhong <dingtianhong@huawei.com>,
	Jason Low <jason.low2@hpe.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	"Paul E. McKenney" <paulmck@us.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <Will.Deacon@arm.com>,
	Tim Chen <tim.c.chen@linux.intel.com>
Subject: Re: [PATCH v3 2/3] locking/mutex: Enable optimistic spinning of woken task in wait queue
Date: Thu, 31 Mar 2016 16:37:40 -0400	[thread overview]
Message-ID: <56FD8A94.9050807@hpe.com> (raw)
In-Reply-To: <20160329153935.GL3408@twins.programming.kicks-ass.net>

On 03/29/2016 11:39 AM, Peter Zijlstra wrote:
> On Tue, Mar 22, 2016 at 01:46:43PM -0400, Waiman Long wrote:
>> Ding Tianhong reported a live-lock situation where a constant stream
>> of incoming optimistic spinners blocked a task in the wait list from
>> getting the mutex.
>>
>> This patch attempts to fix this live-lock condition by enabling the
>> woken task in the wait queue to enter into an optimistic spinning
>> loop itself in parallel with the regular spinners in the OSQ. This
>> should prevent the live-lock condition from happening.
> I would very much like a few words on how fairness is preserved.
>
> Because while the waiter remains on the wait_list while it spins, and
> therefore unlock()s will only wake it, and we'll only contend with the
> one waiter, the fact that we have two spinners is not fair or starvation
> proof at all.
>
> By adding the waiter to the OSQ we get only a single spinner and force
> 'fairness' by queuing.
>
> I say 'fairness' because the OSQ (need_resched) cancellation can still
> take the waiter out again and let even more new spinners in.
>

In my v1 patch, I added a flag in the mutex structure to signal that the 
waiter is spinning and the OSQ spinner should yield to address this 
fairness issue. I took it out in my later patchs as you said you want to 
make the patch simpler.

Yes, I do agree that it is not guaranteed that the waiter spinner will 
have a decent chance to get the lock, but I think it is still better 
than queuing at the end of the OSQ as the time slice may expire before 
the waiter bubbles up to the beginning of the queue. This can be 
especially problematic if the waiter has lower priority which means 
shorter time slice.

What do you think about the idea of adding a flag as in my v1 patch? For 
64-bit systems, there is a 4-byte hole below osq and so it won't 
increase the structure size. There will be a 4-byte increase in size for 
32-bit systems, though.

Alternatively, I can certainly add a bit more comments to explain the 
situation and the choice that we made.

>> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
>> index 5dd6171..5c0acee 100644
>> --- a/kernel/locking/mutex.c
>> +++ b/kernel/locking/mutex.c
>> @@ -538,6 +538,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
>>   	struct task_struct *task = current;
>>   	struct mutex_waiter waiter;
>>   	unsigned long flags;
>> +	bool  acquired = false;	/* True if the lock is acquired */
> Superfluous space there.

OK, will remove that.

Cheers,
Longman

  parent reply	other threads:[~2016-03-31 20:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22 17:46 [PATCH v3 0/3] locking/mutex: Enable optimistic spinning of lock waiter Waiman Long
2016-03-22 17:46 ` [PATCH v3 1/3] locking/mutex: Add waiter parameter to mutex_optimistic_spin() Waiman Long
2016-03-22 17:46 ` [PATCH v3 2/3] locking/mutex: Enable optimistic spinning of woken task in wait queue Waiman Long
2016-03-29 15:39   ` Peter Zijlstra
2016-03-29 16:42     ` Peter Zijlstra
2016-03-31 20:40       ` Waiman Long
2016-03-31 20:37     ` Waiman Long [this message]
2016-03-22 17:46 ` [PATCH v3 3/3] locking/mutex: Avoid missed wakeup of mutex waiter Waiman Long
2016-03-29 16:36   ` Peter Zijlstra
2016-03-31 20:39     ` Waiman Long
2016-07-18 17:59 ` [PATCH v3 0/3] locking/mutex: Enable optimistic spinning of lock waiter Jason Low
2016-07-18 20:50   ` Waiman Long

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=56FD8A94.9050807@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=Will.Deacon@arm.com \
    --cc=dave@stgolabs.net \
    --cc=dingtianhong@huawei.com \
    --cc=jason.low2@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    /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