From: Chris Mason <chris.mason@oracle.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: btrfs_tree_lock & trylock
Date: Mon, 08 Sep 2008 09:47:46 -0400 [thread overview]
Message-ID: <1220881666.8537.3.camel@think.oraclecorp.com> (raw)
In-Reply-To: <20080908111059.GA8902@basil.nowhere.org>
On Mon, 2008-09-08 at 13:10 +0200, Andi Kleen wrote:
> I did some btrfs RTFS over the weeking and I have a hard time understanding
> what this code is attempting to do:
>
> 28 int btrfs_tree_lock(struct extent_buffer *eb)
> 29 {
> 30 int i;
> 31
> 32 if (mutex_trylock(&eb->mutex))
> 33 return 0;
> 34 for (i = 0; i < 512; i++) {
> 35 cpu_relax();
> 36 if (mutex_trylock(&eb->mutex))
> 37 return 0;
> 38 }
> 39 cpu_relax();
> 40 mutex_lock_nested(&eb->mutex, BTRFS_MAX_LEVEL - btrfs_header_level(e b));
> 41 return 0;
> 42 }
>
> The trylocks seem pretty pointless.
> I presume it can be all replaced with the mutex_lock_nested() in line 40.
> Also the return value seems pointless because noone checks it. Like
> in the appended patch. Or do I miss something?
The idea is to try to spin for a bit to avoid scheduling away, which is
especially important for the high levels. Most holders of the mutex
let it go very quickly.
-chris
next prev parent reply other threads:[~2008-09-08 13:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-08 11:10 btrfs_tree_lock & trylock Andi Kleen
2008-09-08 13:47 ` Chris Mason [this message]
2008-09-08 13:54 ` Andi Kleen
2008-09-08 14:02 ` Chris Mason
2008-09-08 14:20 ` Andi Kleen
2008-09-08 15:07 ` Stephen Hemminger
2008-09-08 15:28 ` Chris Mason
2008-09-08 23:26 ` Steve Long
2008-09-08 15:47 ` Andi Kleen
2008-09-08 15:50 ` Stephen Hemminger
2008-09-08 15:55 ` Chris Mason
2008-09-08 16:13 ` jim owens
2008-09-08 16:20 ` Chris Mason
2008-09-08 16:49 ` Stephen Hemminger
2008-09-08 17:17 ` Christoph Hellwig
2008-09-08 17:32 ` Ric Wheeler
2008-09-08 23:28 ` Steve Long
2008-09-08 17:16 ` adaptive mutexes, was " Christoph Hellwig
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=1220881666.8537.3.camel@think.oraclecorp.com \
--to=chris.mason@oracle.com \
--cc=andi@firstfloor.org \
--cc=linux-btrfs@vger.kernel.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