Skip to contentSkip to conversation

Btrfs: remove unnecessary tree search when logging inode

PATCH Superseded Filipe David Borba Manana 1 participant 2 messages Oct 1, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: remove unnecessary tree search when logging inode

In tree-log.c:btrfs_log_inode(), we keep calling btrfs_search_forward() until it returns a key whose objectid is higher than our inode or until the key's type is higher than our maximum allowed type.

At the end of the loop, we increment our mininum search key's objectid and type regardless of our desired target objectid and maximum desired type, which causes another loop iteration that will call again btrfs_search_forward() just to figure out we've gone beyond our maximum key and exit the loop. Therefore while incrementing our minimum key, don't do it blindly and exit the loop immiediately if the next search key's objectid or type is beyond what we seek.

---
 fs/btrfs/tree-log.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/tree-log.c +1 -3
index 79f057c..cbc8156 100644
@@ -3771,10 +3771,8 @@ next_slot:
 
 		if (min_key.offset < (u64)-1)
 			min_key.offset++;
-		else if (min_key.type < (u8)-1)
+		else if (min_key.type < max_key.type)
 			min_key.type++;
-		else if (min_key.objectid < (u64)-1)
-			min_key.objectid++;
 		else
 			break;
 	}
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/1 Btrfs: remove unnecessary tree search when logging inode

In tree-log.c:btrfs_log_inode(), we keep calling btrfs_search_forward() until it returns a key whose objectid is higher than our inode or until the key's type is higher than our maximum allowed type.

At the end of the loop, we increment our mininum search key's objectid and type regardless of our desired target objectid and maximum desired type, which causes another loop iteration that will call again btrfs_search_forward() just to figure out we've gone beyond our maximum key and exit the loop. Therefore while incrementing our minimum key, don't do it blindly and exit the loop immiediately if the next search key's objectid or type is beyond what we seek.

Also after incrementing the type, set the key's offset to 0, which was missing and could make us loose some of the inode's items.

---

V2: Reset key offset to 0 after incrementing its type field.

 fs/btrfs/tree-log.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/tree-log.c +5 -5
index 79f057c..7ae9e7d 100644
@@ -3769,14 +3769,14 @@ next_slot:
 		}
 		btrfs_release_path(path);
 
-		if (min_key.offset < (u64)-1)
+		if (min_key.offset < (u64)-1) {
 			min_key.offset++;
-		else if (min_key.type < (u8)-1)
+		} else if (min_key.type < max_key.type) {
 			min_key.type++;
-		else if (min_key.objectid < (u64)-1)
-			min_key.objectid++;
-		else
+			min_key.offset = 0;
+		} else {
 			break;
+		}
 	}
 	if (ins_nr) {
 		ret = copy_items(trans, inode, dst_path, src, ins_start_slot,
Signature · 1 line
1.7.9.5