From: Linus Torvalds <torvalds@linux-foundation.org>
To: William Allen Simpson <william.allen.simpson@gmail.com>
Cc: Stephen Hemminger <shemminger@vyatta.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Linux Kernel Developers <linux-kernel@vger.kernel.org>,
Linux Kernel Network Developers <netdev@vger.kernel.org>,
Eric Dumazet <eric.dumazet@gmail.com>
Subject: Re: [PATCH v2] Documentation: rw_lock lessons learned
Date: Thu, 12 Nov 2009 07:40:30 -0800 (PST) [thread overview]
Message-ID: <alpine.LFD.2.01.0911120726430.31845@localhost.localdomain> (raw)
In-Reply-To: <4AFBEC44.9030409@gmail.com>
On Thu, 12 Nov 2009, William Allen Simpson wrote:
>
> In recent weeks, two different network projects erroneously
> strayed down the rw_lock path. Update the Documentation
> based upon comments by Eric Dumazet and Paul E. McKenney in
> those threads.
This still retains some pretty old and bogus language. For example, that
file still talks about spinlocks being "faster than a global interrupt
lock", which is kind of amusing - because we've not done that global
interrupt lock thing for the last ten years or so.
So I certainly agree with discouraging rwlocks - I don't think we've ever
really found a situation where they are useful except for some really
special cases - but I suspect the thing needs a bigger overhaul.
I also suspect somebody should actually take a look at our _users_ of
rwlocks. We have a few fairly central ones like 'tasklist_lock', and it
may be an example of a _good_ case of rwlocks, but for a very non-obvious
reason.
In the case of 'tasklist_lock', the magic subtle reason that makes it a
good idea is that that lock is commonly taken for reading in _interrupts_.
And the way rwlocks are defined, that means that you can take it for
reading without doing the *_irq() or *_irqsave() versions, because rwlocks
are not fair, so an active reader will never block a new reader even if
there is a blocked writer pending.
So for tasklist_lock, raw rwlocks are still slower than raw spinlocks, but
because of the rwlock semantics the common case doesn't need to disable
and enable interrupts, so for the common case the comparison is not "raw
rwlock vs raw spinlock", but "raw rwlock vs interrupt-disabling spinlock",
and then it turns out rwlocks tend to win again.
(Of course, lock_write() needs to disable interrupts for tasklist_lock,
but that tends to be the uncommon case).
Ho humm..
Linus
next prev parent reply other threads:[~2009-11-12 15:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-10 19:55 [PATCH resent] Documentation: rw_lock lessons learned William Allen Simpson
2009-11-10 21:22 ` Paul E. McKenney
2009-11-11 2:06 ` Stephen Hemminger
2009-11-11 17:08 ` William Allen Simpson
2009-11-11 17:37 ` Stephen Hemminger
2009-11-12 11:06 ` [PATCH v2] " William Allen Simpson
2009-11-12 15:40 ` Linus Torvalds [this message]
2009-11-12 17:04 ` Stephen Hemminger
2009-11-12 19:13 ` Stephen Clark
2009-11-12 23:00 ` Stephen Hemminger
2009-11-13 8:59 ` Stefan Richter
2009-11-13 16:15 ` William Allen Simpson
2009-12-11 17:01 ` [PATCH v2] " William Allen Simpson
2009-12-11 21:07 ` Jarek Poplawski
2009-12-12 10:36 ` William Allen Simpson
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=alpine.LFD.2.01.0911120726430.31845@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=shemminger@vyatta.com \
--cc=william.allen.simpson@gmail.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