From: Balbir Singh <balbir@linux.vnet.ibm.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jens Axboe <jens.axboe@oracle.com>, Nick Piggin <npiggin@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
Linux Memory Management List <linux-mm@kvack.org>
Subject: Re: [patch] splice mmap_sem deadlock
Date: Mon, 01 Oct 2007 23:49:36 +0530 [thread overview]
Message-ID: <47013A38.2090700@linux.vnet.ibm.com> (raw)
In-Reply-To: <alpine.LFD.0.999.0710010905070.3579@woody.linux-foundation.org>
Linus Torvalds wrote:
>
> On Mon, 1 Oct 2007, Balbir Singh wrote:
>> Sounds very similar to the problems we had with CPU hotplug earlier.
>> It's a rwlock locking anti-pattern. I know that recursive locks
>> have been frowned upon earlier, but I wonder if there is a case here.
>> Of-course recursive locks would not be *fair*.
>
> The problem with recursive locks is that they are inevitably done wrong.
>
> For example, the "natural" way to do them is to just save the process ID
> or something like that. Which is utter crap. Yet, people do it *every*
> single time (yes, I've done it too, I admit).
>
Yes, I've done that too, I guess we learn what's bad by doing it.
> The thing is, "recursive" doesn't mean "same CPU" or "same process" or
> "same thread" or anything like that. It means "same *dependency-chain*".
> With the very real implication that you literally have to pass the "lock
> instance" (whether that is a cookie or anything else) around, and thus
> really generate the proper chain.
>
> For example, in CPU hotplug, the dependency chain really did end up moving
> between different execution contexts, iirc (eg from process context into
> kernel workqueues).
>
I agree with whatever you've said so far. The original intention of
every lock is to protect data not code. In the example mentioned before
and in the case of CPU hotplug, what we intend to do, is to prevent
the writer from causing a deadlock. We create a deadlock, as a
side-effect of the locking is fair.
I guess what we might need is a variant of unfair locks. Tracking owners
is one way of eliminating deadlocks that occur, specially since the
reader-writer lock does not allow readers to provide fair locking.
I think this is where RCU excels, it allows readers/writers to proceed
almost independently.
> So we could add some kind of recursive interface that maintained a list of
> ownership or whatever, but the fact remains that after 16 years, we still
> haven't really needed it, except for code that is so ugly and broken that
> pretty much everybody really feels it should be rewritten (and generally
> for *other* reasons) anyway.
>
Recursive mutexes are meant for a special purpose. Uncontrolled use of
recursive locks would be really bad.
> So I'm not categorically against nesting, but I'm certainly down on it,
> and I think it's almost always done wrong.
>
Yes, recursive locking needs to be designed with care and usage reviewed
with a lot of attention.
--
Warm Regards,
Balbir Singh
Linux Technology Center
IBM, ISTL
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-10-01 18:20 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-28 16:00 Nick Piggin
2007-09-28 17:31 ` Jens Axboe
2007-09-28 18:10 ` Linus Torvalds
2007-09-28 18:15 ` Jens Axboe
2007-09-28 18:23 ` Linus Torvalds
2007-09-28 19:30 ` Jens Axboe
2007-09-28 20:02 ` Linus Torvalds
2007-09-28 20:08 ` Linus Torvalds
2007-09-29 6:37 ` Jens Axboe
2007-10-01 12:03 ` Jens Axboe
2007-10-01 15:11 ` Linus Torvalds
2007-10-01 15:45 ` Balbir Singh
2007-10-01 16:11 ` Linus Torvalds
2007-10-01 18:19 ` Balbir Singh [this message]
2007-10-01 17:33 ` Jens Axboe
2007-09-29 13:10 ` Nick Piggin
2007-09-30 6:46 ` Jens Axboe
2007-09-30 12:07 ` Nick Piggin
2007-09-30 20:05 ` Jens Axboe
2007-09-30 20:12 ` Nick Piggin
2007-09-29 13:08 ` Nick Piggin
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=47013A38.2090700@linux.vnet.ibm.com \
--to=balbir@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=jens.axboe@oracle.com \
--cc=linux-mm@kvack.org \
--cc=npiggin@suse.de \
--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