mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Robert White" <rwhite@casabyte.com>
To: "David Woodhouse" <dwmw2@infradead.org>, <ptb@it.uc3m.es>
Cc: "William Lee Irwin III" <wli@holomorphy.com>,
	"Martin J. Bligh" <mbligh@aracnet.com>,
	<linux-kernel@vger.kernel.org>
Subject: RE: recursive spinlocks. Shoot.
Date: Mon, 19 May 2003 20:12:15 -0700	[thread overview]
Message-ID: <PEEPIDHAKMCGHDBJLHKGGEENCMAA.rwhite@casabyte.com> (raw)
In-Reply-To: <1053297297.28446.18.camel@imladris.demon.co.uk>

Er..

The gnome wields a morality stick, the morality stick wields itself to the
gnome's hand...
---more---
The gnome hits you... you feel better...


Your "moral position"...

(quote) I want them to either learn to comprehend locking _properly_, or
take up gardening instead. (unquote)

...is critically flawed.

In point of fact, "proper" locking, when combined with "proper" definitions
of an interface dictate that recursive locking is "better".  Demanding that
a call_EE_ know what locks a call_ER_ (and all antecedents of caller) will
have taken is not exactly good design.

Oh, don't get me wrong, I appreciate that in intimately interlocking code
you have to do some of this, but remember that "a lock" is "morally" a
declaration of need at the module interface level of abstraction.

(for instance) The current kernel design requires that (the editorial) we
need to know what locks are held when our file system hooks are called.
Statements about how some particular lock (let's call him "bob") will be
already held by the kernel when routine X is called are "bad" because they
lead to all sorts of problems when that statement becomes false later.

In the most "morally erect" interface design, the implementer of a module
would never have to worry about locking anything, or at least about the
current lock-state of anything.  In the morally perfect universe, the
declarative statement "lock that thing there" would be a smart operator that
would know what all locks, in what dependency orders, needed to be acquired
to "lock that thing there" and the system could execute that pathway of
locking automagically.

Of course, in such a world, the domestic swine would be useful as a bulk
passenger carrier because of the easy way it traverses the sky...

In the current design "we" demand that each designer learn and know what is
locked and what is not.  "We" have documents about how in version X the duty
to lock thing Y has been shifted from outside routine Z to inside.

Recursive locks (and a well defined resource allocation order, but who am I
kidding) would actually be a benefit to all on both sides of most _info and
_op structures, they would insulate design changes and improve portability.

A design where I lock things for only as long as I need them is optimal for
that contention.

If my caller does the same, regardless of my actions then his code is
optimal for those contentions too.

If neither is concerned with the other's needs then the lock intervals are
demand based and will tend to allow the bodies of code to be improved on a
"purely local" basis.

To achieve that, you need recursive locking.

I don't think for an instant that we are going to get recursive locking, but
it does make the specification of interfaces better.

It's only real down side is that it lets the lazy and the sloppy get away
with too much before getting burned.  Recursive locking plus a "lock
everything I *might* touch because my callees wont care" mentality leads to
overlocking and hard-to-find deadlocks.  Everything looks and works find for
a while until everybody, willing to pre-reserve facilities for all their
callees, starts building pool-straddling devices (USB Hard Drives, Network
Extensible File Systems, etc) and only finding their deadlocks late in the
game when things get tangled.

so we wont get recursive locking because of the 02% people who can't be
trusted with it.

But that doesn't make the recursive locking facility anything less than
superior for defining and implementing superior interfaces.

Rob.

-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org]On Behalf Of David Woodhouse
Sent: Sunday, May 18, 2003 3:35 PM
To: ptb@it.uc3m.es
Cc: William Lee Irwin III; Martin J. Bligh; linux-kernel@vger.kernel.org
Subject: Re: recursive spinlocks. Shoot.


On Sun, 2003-05-18 at 18:24, Peter T. Breuer wrote:
> The second method is used by programmers who aren't aware that some
> obscure subroutine takes a spinlock, and who recklessly take a lock
> before calling a subroutine (the very thought sends shivers down my
> spine ...).  A popular scenario involves not /knowing/ that your routine
> is called by the kernel with some obscure lock already held, and then
> calling a subroutine that calls the same obscure lock.  The request
> function is one example, but that's hardly obscure (and in 2.5 the
> situation has eased there!).

To be honest, if any programmer is capable of committing this error and
not finding and fixing it for themselves, then they're also capable, and
arguably _likely_, to introduce subtle lock ordering discrepancies which
will cause deadlock once in a blue moon.

I don't _want_ you to make life easier for this hypothetical programmer.

I want them to either learn to comprehend locking _properly_, or take up
gardening instead.

--
dwmw2


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  parent reply	other threads:[~2003-05-20  2:59 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-18  9:21 Peter T. Breuer
2003-05-18 16:30 ` Martin J. Bligh
2003-05-18 16:35   ` William Lee Irwin III
2003-05-18 16:49     ` Arjan van de Ven
2003-05-18 16:54       ` William Lee Irwin III
2003-05-18 17:14         ` Martin J. Bligh
2003-05-18 17:24     ` Peter T. Breuer
2003-05-18 22:34       ` David Woodhouse
2003-05-19 13:37         ` Peter T. Breuer
2003-05-19 13:45           ` Jens Axboe
2003-05-19 13:47           ` Arjan van de Ven
     [not found]           ` <mailman.1053352200.24653.linux-kernel2news@redhat.com>
2003-05-19 23:54             ` Pete Zaitcev
2003-05-20  0:03               ` viro
2003-05-20  0:03               ` Johannes Erdfelt
2003-05-20  3:12         ` Robert White [this message]
2003-05-20 11:59           ` Helge Hafting
2003-05-20 12:23             ` Richard B. Johnson
2003-05-20 21:05               ` Robert White
2003-05-20 21:42                 ` Richard B. Johnson
2003-05-20 23:06                   ` Robert White
2003-05-21 14:01                     ` Richard B. Johnson
2003-05-21 21:56                       ` Robert White
2003-05-22  0:13                         ` viro
2003-05-22  0:32                           ` Robert White
2003-05-22  0:46                         ` Carl-Daniel Hailfinger
2003-05-21  5:48                   ` Nikita Danilov
2003-05-22  1:00           ` Rik van Riel
2003-05-22  3:11             ` Robert White
2003-05-22  4:04               ` Nick Piggin
2003-05-22  4:42                 ` Peter T. Breuer
2003-05-22  5:09                   ` Nick Piggin
2003-05-23  0:19                 ` Robert White
2003-05-23  7:22                   ` Nikita Danilov
2003-05-23  9:07                     ` Helge Hafting
2003-05-23 12:18                     ` William Lee Irwin III
2003-05-24  2:39                       ` Robert White
2003-05-28 16:50                         ` Timothy Miller
2003-05-19  2:05       ` Kevin O'Connor
2003-05-19  6:19       ` Jan Hudec
2003-05-19 10:29       ` Helge Hafting
2003-05-19 11:37         ` Nikita Danilov
2003-05-22  1:21           ` Daniel Phillips
2003-05-19 14:28       ` Martin J. Bligh
2003-05-18 18:13 ` Davide Libenzi
     [not found] <20030518182010$0541@gated-at.bofh.it>
2003-05-18 19:09 ` Peter T. Breuer
2003-05-18 19:31   ` Davide Libenzi
2003-05-18 19:49     ` Peter T. Breuer
2003-05-18 20:13       ` Davide Libenzi
2003-05-19 20:47   ` Jan Hudec
     [not found] <20030518202013$5297@gated-at.bofh.it>
2003-05-18 23:15 ` Peter T. Breuer
2003-05-18 23:26   ` Davide Libenzi
2003-05-19 12:48     ` Peter T. Breuer
2003-05-19 17:15       ` Davide Libenzi
2003-05-19 17:27         ` Peter T. Breuer
2003-05-19 17:57           ` Alan Cox
2003-05-19 19:51         ` Peter T. Breuer
2003-05-19 20:22   ` Robert White
     [not found] <20030520231013$3d77@gated-at.bofh.it>
2003-05-21 14:16 ` Peter T. Breuer

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=PEEPIDHAKMCGHDBJLHKGGEENCMAA.rwhite@casabyte.com \
    --to=rwhite@casabyte.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbligh@aracnet.com \
    --cc=ptb@it.uc3m.es \
    --cc=wli@holomorphy.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

all inboxes | Powered by JetHome®