public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Low <jason.low2@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: jason.low2@hpe.com,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ding Tianhong <dingtianhong@huawei.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <Will.Deacon@arm.com>, Ingo Molnar <mingo@redhat.com>,
	imre.deak@intel.com, 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 v4] locking/mutex: Prevent lock starvation when spinning is disabled
Date: Thu, 18 Aug 2016 21:11:16 -0700	[thread overview]
Message-ID: <1471579876.4991.51.camel@j-VirtualBox> (raw)
In-Reply-To: <1471567197.4991.41.camel@j-VirtualBox>

On Thu, 2016-08-18 at 17:39 -0700, Jason Low wrote:
> 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.
> 
> This prevents waiters from getting starved without sacrificing much
> much performance, as lock stealing is still allowed and only
> temporarily disabled when it is detected that a waiter has been waiting
> for too long.

Changes from v3 (in peterz locking/core) -> v4:

1. Fixed patch title. It should be "Prevent lock starvation when spinning is
   disabled" instead of "when spinning is enabled".

2. Call clear_yield_to_waiter() when a top waiter exits in the 'err' case.

3. Only clear yield_to_waiter if the thread is the top waiter and not if it
   is a non-top waiter that received a signal.

  reply	other threads:[~2016-08-19  4:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19  0:39 [PATCH v4] locking/mutex: Prevent lock starvation when spinning is disabled Jason Low
2016-08-19  4:11 ` Jason Low [this message]
2016-08-19 12:13   ` Peter Zijlstra
2016-08-19 16:57 ` Waiman Long
2016-08-19 19:33   ` Peter Zijlstra
2016-08-19 19:45     ` Linus Torvalds
2016-08-23 12:45       ` 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=1471579876.4991.51.camel@j-VirtualBox \
    --to=jason.low2@hpe.com \
    --cc=Waiman.Long@hpe.com \
    --cc=Will.Deacon@arm.com \
    --cc=dave@stgolabs.net \
    --cc=dingtianhong@huawei.com \
    --cc=imre.deak@intel.com \
    --cc=jason.low2@hp.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=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