linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Skip some btrfs_cross_ref_exist() check in nocow path
@ 2018-05-16  8:28 Ethan Lien
  2018-05-16  8:31 ` Nikolay Borisov
  2018-05-16 15:11 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Ethan Lien @ 2018-05-16  8:28 UTC (permalink / raw)
  To: linux-btrfs; +Cc: 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.

Signed-off-by: Ethan Lien <ethanlien@synology.com>
---
 fs/btrfs/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d241285a0d2a..96927f2ccd4b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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.17.0


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

* Re: [PATCH] btrfs: Skip some btrfs_cross_ref_exist() check in nocow path
  2018-05-16  8:28 [PATCH] btrfs: Skip some btrfs_cross_ref_exist() check in nocow path Ethan Lien
@ 2018-05-16  8:31 ` Nikolay Borisov
  2018-05-16 15:11 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2018-05-16  8:31 UTC (permalink / raw)
  To: Ethan Lien, linux-btrfs



On 16.05.2018 11:28, Ethan Lien wrote:
> 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.
> 
> Signed-off-by: Ethan Lien <ethanlien@synology.com>

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



> ---
>  fs/btrfs/inode.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index d241285a0d2a..96927f2ccd4b 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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) {
> 

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

* Re: [PATCH] btrfs: Skip some btrfs_cross_ref_exist() check in nocow path
  2018-05-16  8:28 [PATCH] btrfs: Skip some btrfs_cross_ref_exist() check in nocow path Ethan Lien
  2018-05-16  8:31 ` Nikolay Borisov
@ 2018-05-16 15:11 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2018-05-16 15:11 UTC (permalink / raw)
  To: Ethan Lien; +Cc: linux-btrfs

On Wed, May 16, 2018 at 04:28:54PM +0800, Ethan Lien wrote:
> 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.
> 
> Signed-off-by: Ethan Lien <ethanlien@synology.com>
> ---
>  fs/btrfs/inode.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index d241285a0d2a..96927f2ccd4b 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -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;

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

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

end of thread, other threads:[~2018-05-16 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-16  8:28 [PATCH] btrfs: Skip some btrfs_cross_ref_exist() check in nocow path Ethan Lien
2018-05-16  8:31 ` Nikolay Borisov
2018-05-16 15:11 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).