public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Low <jason.low2@hpe.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: jason.low2@hpe.com, Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	imre.deak@intel.com,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Waiman Long <Waiman.Long@hpe.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	terry.rudd@hpe.com, "Paul E. McKenney" <paulmck@us.ibm.com>,
	jason.low2@hp.com
Subject: Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled
Date: Wed, 17 Aug 2016 11:30:33 -0700	[thread overview]
Message-ID: <1471458633.4991.9.camel@j-VirtualBox> (raw)
In-Reply-To: <CANRm+CxLmkuzHWy9RrWbNBCkvacyvcx-_ez-kn_xSBDcepLgTQ@mail.gmail.com>

Hi Wanpeng,

On Wed, 2016-08-17 at 09:41 +0800, Wanpeng Li wrote:
> 2016-08-11 2:44 GMT+08:00 Jason Low <jason.low2@hpe.com>:
> > Imre reported an issue where threads are getting starved when trying
> > to acquire a mutex. Threads acquiring a mutex can get arbitrarily delayed
> > sleeping on a mutex because other threads can continually steal the lock
> > in the fastpath and/or through optimistic spinning.
> >
> > Waiman has developed patches that allow waiters to return to optimistic
> > spinning, thus reducing the probability that starvation occurs. However,
> > Imre still sees this starvation problem in the workloads when optimistic
> > spinning is disabled.
> >
> > This patch adds an additional boolean to the mutex that gets used in
> > the CONFIG_SMP && !CONFIG_MUTEX_SPIN_ON_OWNER cases. The flag signifies
> > whether or not other threads need to yield to a waiter and gets set
> > when a waiter spends too much time waiting for the mutex. The threshold
> > is currently set to 16 wakeups, and once the wakeup threshold is exceeded,
> > other threads must yield to the top waiter. The flag gets cleared
> > immediately after the top waiter acquires the mutex.
> 
> There is a subtle difference between this patch and Waiman's. Waiman's
> patch will boost any waiter-spinner which is woken up, however, this
> patch will boost the top waiter once the number of any waiter-spinners
> woken up reaches the threshold.

Correct, since when spinning is disabled, we still want to generally
allow other threads to steal the lock even if there are waiters in order
to keep performance good, and only yield the lock when a waiter is
getting 'starved'.

> We can't get any benefit if the
> resource holder which top waiter is waiting for still not release the
> resource.

If the resource holder does not release the resource, that sounds like
an issue with the lock holder.

Unless you're referring to how this doesn't provide immediate benefit to
the top waiter, in which case, I think that is okay since the goal of
the patch is to prevent starvation. We tried disabling 'lock stealing'
anytime there are waiters and that proved to reduce performance by quite
a bit in some workloads.

  reply	other threads:[~2016-08-17 18:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 18:44 [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled Jason Low
2016-08-10 20:00 ` kbuild test robot
2016-08-10 20:01 ` kbuild test robot
2016-08-16 20:19   ` Jason Low
2016-08-10 22:07 ` Jason Low
2016-08-11  2:30 ` Jason Low
2016-08-11 15:40 ` Waiman Long
2016-08-16 19:44   ` Jason Low
2016-08-17  1:41 ` Wanpeng Li
2016-08-17 18:30   ` Jason Low [this message]
2016-08-18  0:38     ` Wanpeng Li
2016-08-18 14:14 ` Peter Zijlstra
2016-08-18 15:22   ` Waiman Long
2016-08-18 14:27 ` Peter Zijlstra
2016-08-18 15:18   ` Peter Zijlstra
2016-08-18 15:30     ` Peter Zijlstra

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=1471458633.4991.9.camel@j-VirtualBox \
    --to=jason.low2@hpe.com \
    --cc=Waiman.Long@hpe.com \
    --cc=dave@stgolabs.net \
    --cc=imre.deak@intel.com \
    --cc=jason.low2@hp.com \
    --cc=kernellwp@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=terry.rudd@hpe.com \
    --cc=tim.c.chen@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