linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: send, apply asynchronous page cache readahead to enhance page read
@ 2017-09-15  8:47 peterh
  2017-09-25 12:12 ` Nikolay Borisov
  0 siblings, 1 reply; 2+ messages in thread
From: peterh @ 2017-09-15  8:47 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Kuanling Huang

From: Kuanling Huang <peterh@synology.com>

By analyzing the perf on btrfs send, we found it take large
amount of cpu time on page_cache_sync_readahead. This effort
can be reduced after switching to asynchronous one. Overall
performance gain on HDD and SSD were 9 and 15 percent if
simply send a large file.

Signed-off-by: Kuanling Huang <peterh@synology.com>
---
 fs/btrfs/send.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 63a6152..7a5eb66 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -4475,16 +4475,27 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
 	/* initial readahead */
 	memset(&sctx->ra, 0, sizeof(struct file_ra_state));
 	file_ra_state_init(&sctx->ra, inode->i_mapping);
-	btrfs_force_ra(inode->i_mapping, &sctx->ra, NULL, index,
-		       last_index - index + 1);
 
 	while (index <= last_index) {
 		unsigned cur_len = min_t(unsigned, len,
 					 PAGE_CACHE_SIZE - pg_offset);
-		page = find_or_create_page(inode->i_mapping, index, GFP_NOFS);
+		page = find_lock_page(inode->i_mapping, index);
 		if (!page) {
-			ret = -ENOMEM;
-			break;
+			page_cache_sync_readahead(inode->i_mapping,
+				&sctx->ra, NULL, index,
+				last_index + 1 - index);
+
+			page = find_or_create_page(inode->i_mapping, index, GFP_KERNEL);
+			if (!page) {
+				ret = -ENOMEM;
+				break;
+			}
+		}
+
+		if (PageReadahead(page)) {
+			page_cache_async_readahead(inode->i_mapping,
+				&sctx->ra, NULL, page, index,
+				last_index + 1 - index);
 		}
 
 		if (!PageUptodate(page)) {
-- 
1.9.1


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

* Re: [PATCH] Btrfs: send, apply asynchronous page cache readahead to enhance page read
  2017-09-15  8:47 [PATCH] Btrfs: send, apply asynchronous page cache readahead to enhance page read peterh
@ 2017-09-25 12:12 ` Nikolay Borisov
  0 siblings, 0 replies; 2+ messages in thread
From: Nikolay Borisov @ 2017-09-25 12:12 UTC (permalink / raw)
  To: peterh, linux-btrfs



On 15.09.2017 11:47, peterh wrote:
> From: Kuanling Huang <peterh@synology.com>
> 
> By analyzing the perf on btrfs send, we found it take large
> amount of cpu time on page_cache_sync_readahead. This effort
> can be reduced after switching to asynchronous one. Overall
> performance gain on HDD and SSD were 9 and 15 percent if
> simply send a large file.
> 
> Signed-off-by: Kuanling Huang <peterh@synology.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/send.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
> index 63a6152..7a5eb66 100644
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -4475,16 +4475,27 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
>  	/* initial readahead */
>  	memset(&sctx->ra, 0, sizeof(struct file_ra_state));
>  	file_ra_state_init(&sctx->ra, inode->i_mapping);
> -	btrfs_force_ra(inode->i_mapping, &sctx->ra, NULL, index,
> -		       last_index - index + 1);
>  
>  	while (index <= last_index) {
>  		unsigned cur_len = min_t(unsigned, len,
>  					 PAGE_CACHE_SIZE - pg_offset);
> -		page = find_or_create_page(inode->i_mapping, index, GFP_NOFS);
> +		page = find_lock_page(inode->i_mapping, index);
>  		if (!page) {
> -			ret = -ENOMEM;
> -			break;
> +			page_cache_sync_readahead(inode->i_mapping,
> +				&sctx->ra, NULL, index,
> +				last_index + 1 - index);
> +
> +			page = find_or_create_page(inode->i_mapping, index, GFP_KERNEL);
> +			if (!page) {
> +				ret = -ENOMEM;
> +				break;
> +			}
> +		}
> +
> +		if (PageReadahead(page)) {
> +			page_cache_async_readahead(inode->i_mapping,
> +				&sctx->ra, NULL, page, index,
> +				last_index + 1 - index);
>  		}
>  
>  		if (!PageUptodate(page)) {
> 

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

end of thread, other threads:[~2017-09-25 12:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-15  8:47 [PATCH] Btrfs: send, apply asynchronous page cache readahead to enhance page read peterh
2017-09-25 12:12 ` Nikolay Borisov

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).