From: Davidlohr Bueso <dave@stgolabs.net>
To: Waiman Long <waiman.long@hp.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
linux-kernel@vger.kernel.org, Jason Low <jason.low2@hp.com>,
Scott J Norton <scott.norton@hp.com>,
Douglas Hatch <doug.hatch@hp.com>
Subject: Re: [PATCH v3] locking/rwsem: reduce spinlock contention in wakeup after up_read/up_write
Date: Thu, 30 Apr 2015 07:12:03 -0700 [thread overview]
Message-ID: <1430403123.2011.16.camel@stgolabs.net> (raw)
In-Reply-To: <554137EC.4030700@hp.com>
On Wed, 2015-04-29 at 15:58 -0400, Waiman Long wrote:
> A write lock can also be acquired by a spinning writer in
> rwsem_try_write_lock_unqueued() where wait_lock isn't used. With
> multiple down_read's, it is possible that the first exiting reader wakes
> up a writer who acquires the write lock while the other readers are
> waiting for acquiring the wait_lock.
Except that readers that do the wakeup do not call __rwsem_do_wake() if
there is an active writer:
/* If there are no active locks, wake the front queued process(es).
*
* If there are no writers and we are first in the queue,
* wake our own waiter to join the existing active readers !
*/
if (count == RWSEM_WAITING_BIAS ||
(count > RWSEM_WAITING_BIAS &&
adjustment != -RWSEM_ACTIVE_READ_BIAS))
sem = __rwsem_do_wake(sem, RWSEM_WAKE_ANY);
And for the reader part, your rwsem_has_active_writer() check, while
avoiding the counter atomic update, would break current semantics in
that we still do the next reader grant -- also note the unlikely()
predictor ;) And this is done with the counter, so by using the owner,
you would have a race between the cmpxchg and rwsem_set_owner(). Yes,
its a small window (specially after commit 7a215f89), but there
nonetheless and could cause even more bogus wakeups. Again, I simply do
not like mixing these two -- we get away with it with the optimistic
spinning because we just iterate again, but this is not the case.
Ultimately, is this really an issue? Do you have numbers that could
justify such a change? I suspect all the benchmark results you posted in
the patch are from reducing the spinlock contention, not from this.
Thanks,
Davidlohr
next prev parent reply other threads:[~2015-04-30 14:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-24 17:54 [PATCH v3] locking/rwsem: reduce spinlock contention in wakeup after up_read/up_write Waiman Long
2015-04-24 20:39 ` Davidlohr Bueso
2015-04-27 20:25 ` Waiman Long
2015-04-28 18:17 ` Davidlohr Bueso
2015-04-29 19:58 ` Waiman Long
2015-04-30 14:12 ` Davidlohr Bueso [this message]
2015-04-30 20:25 ` Waiman Long
2015-04-28 16:52 ` Peter Zijlstra
2015-04-28 17:17 ` Peter Zijlstra
2015-04-28 17:50 ` Jason Low
2015-04-28 17:59 ` Jason Low
2015-04-28 18:05 ` Davidlohr Bueso
2015-04-30 21:34 ` 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=1430403123.2011.16.camel@stgolabs.net \
--to=dave@stgolabs.net \
--cc=doug.hatch@hp.com \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hp.com \
--cc=waiman.long@hp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.