public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* btrfs_tree_lock & trylock
@ 2008-09-08 11:10 Andi Kleen
  2008-09-08 13:47 ` Chris Mason
  0 siblings, 1 reply; 18+ messages in thread
From: Andi Kleen @ 2008-09-08 11:10 UTC (permalink / raw)
  To: linux-btrfs


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?

---

Remove unneeded trylocking and unused return value in btrfs_tree_lock

Signed-off-by: Andi Kleen <ak@linux.intel.com>

diff -r 417d87e57364 locking.c
--- a/locking.c	Wed Aug 20 13:39:41 2008 -0400
+++ b/locking.c	Mon Sep 08 13:09:21 2008 +0200
@@ -25,20 +25,9 @@
 #include "extent_io.h"
 #include "locking.h"
 
-int btrfs_tree_lock(struct extent_buffer *eb)
+void btrfs_tree_lock(struct extent_buffer *eb)
 {
-	int i;
-
-	if (mutex_trylock(&eb->mutex))
-		return 0;
-	for (i = 0; i < 512; i++) {
-		cpu_relax();
-		if (mutex_trylock(&eb->mutex))
-			return 0;
-	}
-	cpu_relax();
 	mutex_lock_nested(&eb->mutex, BTRFS_MAX_LEVEL - btrfs_header_level(eb));
-	return 0;
 }
 
 int btrfs_try_tree_lock(struct extent_buffer *eb)
diff -r 417d87e57364 locking.h
--- a/locking.h	Wed Aug 20 13:39:41 2008 -0400
+++ b/locking.h	Mon Sep 08 13:09:21 2008 +0200
@@ -19,7 +19,7 @@
 #ifndef __BTRFS_LOCKING_
 #define __BTRFS_LOCKING_
 
-int btrfs_tree_lock(struct extent_buffer *eb);
+void btrfs_tree_lock(struct extent_buffer *eb);
 int btrfs_tree_unlock(struct extent_buffer *eb);
 int btrfs_tree_locked(struct extent_buffer *eb);
 int btrfs_try_tree_lock(struct extent_buffer *eb);

-- 
ak@linux.intel.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2008-09-08 23:28 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-08 11:10 btrfs_tree_lock & trylock Andi Kleen
2008-09-08 13:47 ` Chris Mason
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox