From: Steven Rostedt <rostedt@goodmis.org>
To: Howard Chu <hyc@symas.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
davids@webmaster.com, Nick Piggin <nickpiggin@yahoo.com.au>
Subject: Re: pthread_mutex_unlock (was Re: sched_yield() makes OpenLDAP slow)
Date: Thu, 26 Jan 2006 23:27:50 -0500 [thread overview]
Message-ID: <1138336070.7814.35.camel@localhost.localdomain> (raw)
In-Reply-To: <43D94595.4030002@symas.com>
On Thu, 2006-01-26 at 13:56 -0800, Howard Chu wrote:
> Nick Piggin wrote:
> >>
> >> But why does A take the mutex in the first place? Presumably because
> >> it is about to execute a critical section. And also presumably, A
> >> will not release the mutex until it no longer has anything critical
> >> to do; certainly it could hold it longer if it needed to.
> >>
> >> If A still needed the mutex, why release it and reacquire it, why not
> >> just hold onto it? The fact that it is being released is significant.
> >>
> >
> > Regardless of why, that is just the simplest scenario I could think
> > of that would give us a test case. However...
> >
> > Why not hold onto it? We sometimes do this in the kernel if we need
> > to take a lock that is incompatible with the lock already being held,
> > or if we discover we need to take a mutex which nests outside our
> > currently held lock in other paths. Ie to prevent deadlock.
>
> In those cases, A cannot retake the mutex anyway. I.e., you just said
> that you released the first mutex because you want to acquire a
> different one. So those cases don't fit this example very well.
Lets say you have two locks X and Y. Y nests inside of X. To do block1
you need to have lock Y and to do block2 you need to have both locks X
and Y, and block 1 must be done first without holding lock X.
func()
{
again:
mutex_lock(Y);
block1();
if (!mutex_try_lock(X)) {
mutex_unlock(Y);
mutex_lock(X);
mutex_lock(Y);
if (block1_has_changed()) {
mutex_unlock(Y);
mutex_unlock(X);
goto again;
}
}
block2();
mutex_unlock(X);
mutex_unlock(Y);
}
Stuff like the above actually is done (it's done in the kernel). So you
can see here that Y can be released and reacquired right away. If
another task was waiting on Y (of lower priority) we don't want to give
up the lock, since we would then block and the chances of
block1_has_changed goes up even more.
>
> > Another reason might be because we will be running for a very long
> > time without requiring the lock.
>
> And again in this case, A should not be immediately reacquiring the lock
> if it doesn't actually need it.
I'm not sure what Nick means here, but I'm sure he didn't mean it to
come out that way ;)
>
> > Or we might like to release it because
> > we expect a higher priority process to take it.
>
> And in this case, the expected behavior is the same as I've been pursuing.
But you can't know if a higher or lower priority process is waiting.
Sure it works like what you say when a higher priority process is
waiting, but it doesn't when it's a lower priority process waiting.
-- Steve
next prev parent reply other threads:[~2006-01-27 4:28 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-24 22:59 e100 oops on resume Stefan Seyfried
2006-01-24 23:21 ` Mattia Dongili
2006-01-25 9:02 ` Olaf Kirch
2006-01-25 12:11 ` Olaf Kirch
2006-01-25 13:51 ` sched_yield() makes OpenLDAP slow Howard Chu
2006-01-25 14:38 ` Robert Hancock
2006-01-25 17:49 ` Christopher Friesen
2006-01-25 18:26 ` pthread_mutex_unlock (was Re: sched_yield() makes OpenLDAP slow) Howard Chu
2006-01-25 18:59 ` Nick Piggin
2006-01-25 19:32 ` Howard Chu
2006-01-26 8:51 ` Nick Piggin
2006-01-26 14:15 ` Kyle Moffett
2006-01-26 14:43 ` Howard Chu
2006-01-26 19:57 ` David Schwartz
2006-01-26 20:27 ` Howard Chu
2006-01-26 20:46 ` Nick Piggin
2006-01-26 21:32 ` Howard Chu
2006-01-26 21:41 ` Nick Piggin
2006-01-26 21:56 ` Howard Chu
2006-01-26 22:24 ` Nick Piggin
2006-01-27 8:08 ` Howard Chu
2006-01-27 19:25 ` Philipp Matthias Hahn
2006-02-01 12:31 ` Nick Piggin
2006-01-27 4:27 ` Steven Rostedt [this message]
2006-01-26 21:58 ` Christopher Friesen
2006-01-27 4:13 ` Steven Rostedt
2006-01-27 2:16 ` David Schwartz
2006-01-27 8:19 ` Howard Chu
2006-01-27 19:50 ` David Schwartz
2006-01-27 20:13 ` Howard Chu
2006-01-27 21:05 ` David Schwartz
2006-01-27 21:23 ` Howard Chu
2006-01-27 23:31 ` David Schwartz
2006-01-30 8:28 ` Helge Hafting
2006-01-26 10:38 ` Nikita Danilov
2006-01-30 8:35 ` Helge Hafting
2006-01-30 11:13 ` Nikita Danilov
2006-01-31 23:18 ` David Schwartz
2006-01-25 21:06 ` Lee Revell
2006-01-25 22:14 ` Howard Chu
2006-01-26 0:16 ` Robert Hancock
2006-01-26 0:49 ` Howard Chu
2006-01-26 1:04 ` Lee Revell
2006-01-26 1:31 ` Howard Chu
2006-01-26 2:05 ` David Schwartz
2006-01-26 2:48 ` Mark Lord
2006-01-26 3:30 ` David Schwartz
2006-01-26 3:49 ` Samuel Masham
2006-01-26 4:02 ` Samuel Masham
2006-01-26 4:53 ` Lee Revell
2006-01-26 6:14 ` Samuel Masham
2006-01-26 8:54 ` Nick Piggin
2006-01-26 14:24 ` Howard Chu
2006-01-26 14:54 ` Nick Piggin
2006-01-26 15:23 ` Howard Chu
2006-01-26 15:51 ` Nick Piggin
2006-01-26 16:44 ` Howard Chu
2006-01-26 17:34 ` linux-os (Dick Johnson)
2006-01-26 19:00 ` Nick Piggin
2006-01-26 19:14 ` linux-os (Dick Johnson)
2006-01-26 21:12 ` Nick Piggin
2006-01-26 21:31 ` linux-os (Dick Johnson)
2006-01-27 7:06 ` Valdis.Kletnieks
2006-01-30 8:44 ` Helge Hafting
2006-01-30 8:50 ` Howard Chu
2006-01-30 15:33 ` Kyle Moffett
2006-01-30 13:28 ` linux-os (Dick Johnson)
2006-01-30 15:15 ` Helge Hafting
2006-01-26 10:44 ` Nikita Danilov
2006-01-26 0:08 ` Robert Hancock
2006-01-26 1:07 ` sched_yield() makes OpenLDAP slow David Schwartz
2006-01-26 8:30 ` Helge Hafting
2006-01-26 9:01 ` Nick Piggin
2006-01-26 10:50 ` Nikita Danilov
2006-01-25 19:37 ` e100 oops on resume Jesse Brandeburg
2006-01-25 20:14 ` Olaf Kirch
2006-01-25 22:28 ` Jesse Brandeburg
2006-01-26 0:28 ` Jesse Brandeburg
2006-01-26 9:32 ` Pavel Machek
2006-01-26 19:02 ` Stefan Seyfried
2006-01-26 19:09 ` Olaf Kirch
2006-01-28 11:53 ` Mattia Dongili
2006-01-28 19:53 ` Jesse Brandeburg
2006-02-07 6:57 ` Jeff Garzik
[not found] ` <BAY108-DAV111F6EF46F6682FEECCC1593140@phx.gbl>
[not found] ` <4807377b0601271404w6dbfcff6s4de1c3f785dded9f@mail.gmail.com>
2006-01-30 17:25 ` Can I do a regular read to simulate prefetch instruction? John Smith
-- strict thread matches above, loose matches on Subject: below --
2006-01-30 22:01 pthread_mutex_unlock (was Re: sched_yield() makes OpenLDAP slow) linux
2006-01-30 23:37 linux
2006-02-01 17:06 Lee Schermerhorn
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=1138336070.7814.35.camel@localhost.localdomain \
--to=rostedt@goodmis.org \
--cc=davids@webmaster.com \
--cc=hyc@symas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nickpiggin@yahoo.com.au \
/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