Skip to contentSkip to conversation

btrfs: Skip some btrfs_cross_ref_exist() check in nocow path

PATCH Superseded Ethan Lien 3 participants 3 messages May 16, 2018 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ethan Lien

author
#0 lore raw

PATCH 1/1 btrfs: Skip some btrfs_cross_ref_exist() check in nocow path

In nocow path, we check if the extent is snapshotted in btrfs_cross_ref_exist(). We can do the similar check earlier and avoid unnecessary search into extent tree.

---
 fs/btrfs/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/inode.c +7 -0
index d241285a0d2a..96927f2ccd4b 100644
@@ -1373,6 +1373,9 @@ static noinline int run_delalloc_nocow(struct inode *inode,
 			    btrfs_file_extent_encryption(leaf, fi) ||
 			    btrfs_file_extent_other_encoding(leaf, fi))
 				goto out_check;
+			if (btrfs_file_extent_generation(leaf, fi) <=
+			    btrfs_root_last_snapshot(&root->root_item))
+				goto out_check;
 			if (extent_type == BTRFS_FILE_EXTENT_REG && !force)
 				goto out_check;
 			if (btrfs_extent_readonly(fs_info, disk_bytenr))
@@ -7368,6 +7371,10 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
 	    btrfs_file_extent_other_encoding(leaf, fi))
 		goto out;
 
+	if (btrfs_file_extent_generation(leaf, fi) <=
+	    btrfs_root_last_snapshot(&root->root_item))
+		goto out;
+
 	backref_offset = btrfs_file_extent_offset(leaf, fi);
 
 	if (orig_start) {
Signature · 1 line
2.17.0
#1 lore raw
Quoted 5 lines · Ethan Lien

In nocow path, we check if the extent is snapshotted in btrfs_cross_ref_exist(). We can do the similar check earlier and avoid unnecessary search into extent tree.

If this is supposed to be a performance improvement do you have any measurements that prove that this is indeed the case?

Quoted 30 lines
---
 fs/btrfs/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/inode.c +7 -0
index d241285a0d2a..96927f2ccd4b 100644
@@ -1373,6 +1373,9 @@ static noinline int run_delalloc_nocow(struct inode *inode,
 			    btrfs_file_extent_encryption(leaf, fi) ||
 			    btrfs_file_extent_other_encoding(leaf, fi))
 				goto out_check;
+			if (btrfs_file_extent_generation(leaf, fi) <=
+			    btrfs_root_last_snapshot(&root->root_item))
+				goto out_check;
 			if (extent_type == BTRFS_FILE_EXTENT_REG && !force)
 				goto out_check;
 			if (btrfs_extent_readonly(fs_info, disk_bytenr))
@@ -7368,6 +7371,10 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
 	    btrfs_file_extent_other_encoding(leaf, fi))
 		goto out;
 
+	if (btrfs_file_extent_generation(leaf, fi) <=
+	    btrfs_root_last_snapshot(&root->root_item))
+		goto out;
+
 	backref_offset = btrfs_file_extent_offset(leaf, fi);
 
 	if (orig_start) {
#2 lore raw
In reply to Ethan Lien
Quoted 24 lines · Ethan Lien

In nocow path, we check if the extent is snapshotted in btrfs_cross_ref_exist(). We can do the similar check earlier and avoid unnecessary search into extent tree.

---
 fs/btrfs/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/btrfs/inode.c +3 -0
index d241285a0d2a..96927f2ccd4b 100644
@@ -1373,6 +1373,9 @@ static noinline int run_delalloc_nocow(struct inode *inode,
 			    btrfs_file_extent_encryption(leaf, fi) ||
 			    btrfs_file_extent_other_encoding(leaf, fi))
 				goto out_check;
+			if (btrfs_file_extent_generation(leaf, fi) <=
+			    btrfs_root_last_snapshot(&root->root_item))
+				goto out_check;
 			if (extent_type == BTRFS_FILE_EXTENT_REG && !force)
 				goto out_check;
 			if (btrfs_extent_readonly(fs_info, disk_bytenr))

fs/btrfs/inode.c noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, · line 7376

Quoted 6 lines
fs/btrfs/inode.c +3 -0
@@ -7368,6 +7371,10 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
 	    btrfs_file_extent_other_encoding(leaf, fi))
 		goto out;
 
+	if (btrfs_file_extent_generation(leaf, fi) <=
+	    btrfs_root_last_snapshot(&root->root_item))
+		goto out;

Please add some brief comment why we're taking a shortcut here, thanks.