From: Imre Deak <imre.deak@intel.com>
To: Jason Low <jason.low2@hpe.com>, Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Chris Wilson <chris@chris-wilson.co.uk>,
Daniel Vetter <daniel.vetter@intel.com>,
Ville Syrj??l?? <ville.syrjala@linux.intel.com>,
Waiman Long <Waiman.Long@hpe.com>,
Davidlohr Bueso <dave@stgolabs.net>,
jason.low2@hp.com
Subject: Re: [RFC] locking/mutex: Fix starvation of sleeping waiters
Date: Tue, 19 Jul 2016 19:53:25 +0300 [thread overview]
Message-ID: <1468947205.31332.40.camel@intel.com> (raw)
In-Reply-To: <1468864069.2367.21.camel@j-VirtualBox>
On ma, 2016-07-18 at 10:47 -0700, Jason Low wrote:
> On Mon, 2016-07-18 at 19:15 +0200, Peter Zijlstra wrote:
> > On Mon, Jul 18, 2016 at 07:16:47PM +0300, Imre Deak wrote:
> > > Currently a thread sleeping on a mutex wait queue can be delayed
> > > indefinitely by other threads managing to steal the lock, that is
> > > acquiring the lock out-of-order before the sleepers. I noticed
> > > this via
> > > a testcase (see the Reference: below) where one CPU was unlocking
> > > /
> > > relocking a mutex in a tight loop while another CPU was delayed
> > > indefinitely trying to wake up and get the lock but losing out to
> > > the
> > > first CPU and going back to sleep:
> > >
> > > CPU0: CPU1:
> > > mutex_lock->acquire
> > > mutex_lock->sleep
> > > mutex_unlock->wake CPU1
> > > wakeup
> > > mutex_lock->acquire
> > > trylock fail->sleep
> > > mutex_unlock->wake CPU1
> > > wakeup
> > > mutex_lock->acquire
> > > trylock fail->sleep
> > > ... ...
> > >
> > > To fix this we can make sure that CPU1 makes progress by avoiding
> > > the
> > > fastpath locking, optimistic spinning and trylocking if there is
> > > any
> > > waiter on the list. The corresponding check can be done without
> > > holding
> > > wait_lock, since the goal is only to make sure sleepers make
> > > progress
> > > and not to guarantee that the locking will happen in FIFO order.
> >
> > I think we went over this before, that will also completely destroy
> > performance under a number of workloads.
>
> Yup, once a thread becomes a waiter, all other threads will need to
> follow suit, so this change would effectively disable optimistic
> spinning in some workloads.
>
> A few months ago, we worked on patches that allow the waiter to
> return
> to optimistic spinning to help reduce starvation. Longman sent out a
> version 3 patch set, and it sounded like we were fine with the
> concept.
Thanks, with v4 he just sent I couldn't trigger the above problem.
However this only works if mutex spinning is enabled, if it's disabled
I still hit the problem due to the other forms of lock stealing. So
could we prevent these if mutex spinning is anyway disabled?
--Imre
next prev parent reply other threads:[~2016-07-19 16:53 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-18 16:16 [RFC] locking/mutex: Fix starvation of sleeping waiters Imre Deak
2016-07-18 17:15 ` Peter Zijlstra
2016-07-18 17:47 ` Jason Low
2016-07-19 16:53 ` Imre Deak [this message]
2016-07-19 22:57 ` Jason Low
2016-07-19 23:04 ` [RFC] Avoid mutex starvation when optimistic spinning is disabled Jason Low
2016-07-20 4:39 ` Jason Low
2016-07-20 13:29 ` Imre Deak
2016-07-21 20:57 ` Jason Low
2016-07-22 17:55 ` Waiman Long
2016-07-22 18:03 ` Davidlohr Bueso
2016-07-22 18:29 ` Imre Deak
2016-07-22 19:26 ` Davidlohr Bueso
2016-07-22 19:53 ` Imre Deak
2016-07-20 18:37 ` Waiman Long
2016-07-21 22:29 ` Jason Low
2016-07-22 9:34 ` Imre Deak
2016-07-22 18:44 ` Jason Low
2016-07-22 18:01 ` 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=1468947205.31332.40.camel@intel.com \
--to=imre.deak@intel.com \
--cc=Waiman.Long@hpe.com \
--cc=chris@chris-wilson.co.uk \
--cc=daniel.vetter@intel.com \
--cc=dave@stgolabs.net \
--cc=jason.low2@hp.com \
--cc=jason.low2@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=ville.syrjala@linux.intel.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).