Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1325997

Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation

From Waiman Long <waiman.long@hpe.com>
Newsgroups linux.kernel
Subject Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation
Date 2016-02-03 23:10 +0100
Message-ID <qYdMC-7MT-27@gated-at.bofh.it> (permalink)
References (6 earlier) <qUnUd-1Ui-1@gated-at.bofh.it> <qWe0r-OA-19@gated-at.bofh.it> <qWsmK-3ln-5@gated-at.bofh.it> <qXjAL-11X-7@gated-at.bofh.it> <qXQwG-BS-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 02/02/2016 04:19 PM, Davidlohr Bueso wrote:
> On Mon, 01 Feb 2016, Peter Zijlstra wrote:
>
>> Subject: locking/mutex: Avoid spinner vs waiter starvation
>> From: Peter Zijlstra <peterz@infradead.org>
>> Date: Fri, 22 Jan 2016 12:06:53 +0100
>>
>> Ding Tianhong reported that under his load the optimistic spinners
>> would totally starve a task that ended up on the wait list.
>>
>> Fix this by ensuring the top waiter also partakes in the optimistic
>> spin queue.
>>
>> There are a few subtle differences between the assumed state of
>> regular optimistic spinners and those already on the wait list, which
>> result in the @acquired complication of the acquire path.
>>
>> Most notable are:
>>
>> - waiters are on the wait list and need to be taken off
>> - mutex_optimistic_spin() sets the lock->count to 0 on acquire
>>   even though there might be more tasks on the wait list.
>
> Right, the main impact I see with these complications are that the
> window of when a waiter takes the lock via spinning and then acquires
> the wait_lock to remove itself from the list, will allow an unlock
> thread to set the lock as available in the fastpath which could in
> turn allow a third thread the steal the lock. With high contention,
> this window will be come obviously larger as we contend for the
> wait_lock.
>
> CPU-0                                  CPU-1            CPU-3
> __mutex_lock_common              mutex_optimistic_spin
>   (->count now 0)
>             __mutex_fastpath_unlock
>             (->count now 1)                 __mutex_fastpath_lock
>                                       (stolen)
>
> spin_lock_mutex(&lock->wait_lock, flags);
>
> But we've always been bad when it comes to counter and waiters.
>
> Thanks,
> Davidlohr

I don't quite get how that can happen. CPU0 cannot change the count to 0 
unless CPU1, the lock holder, does the unlock first. Once CPU0 sees a 
count of 1 and change it to 0, it is the lock holder and there can be no 
other CPU that can do the unlock.

Cheers,
Longman

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list  is not NULL. Peter Zijlstra <peterz@infradead.org> - 2016-01-29 11:00 +0100
  Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list  is not NULL. Ding Tianhong <dingtianhong@huawei.com> - 2016-01-30 02:20 +0100
    Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list  is not NULL. huang ying <huang.ying.caritas@gmail.com> - 2016-02-01 04:30 +0100
      Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. "Huang\, Ying" <ying.huang@intel.com> - 2016-02-01 04:40 +0100
    [PATCH] locking/mutex: Avoid spinner vs waiter starvation Peter Zijlstra <peterz@infradead.org> - 2016-02-01 11:10 +0100
      Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Davidlohr Bueso <dave@stgolabs.net> - 2016-02-02 22:20 +0100
        Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Ding Tianhong <dingtianhong@huawei.com> - 2016-02-03 08:20 +0100
          Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Davidlohr Bueso <dave@stgolabs.net> - 2016-02-03 20:30 +0100
            Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Ding Tianhong <dingtianhong@huawei.com> - 2016-02-04 02:30 +0100
        Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Waiman Long <waiman.long@hpe.com> - 2016-02-03 23:10 +0100
      Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Jason Low <jason.low2@hp.com> - 2016-02-04 02:40 +0100
        Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation huang ying <huang.ying.caritas@gmail.com> - 2016-02-04 10:00 +0100
          Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Jason Low <jason.low2@hp.com> - 2016-02-05 00:00 +0100

csiph-web