linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: peterh <peterh@synology.com>
To: linux-btrfs@vger.kernel.org
Cc: Kuanling Huang <peterh@synology.com>
Subject: [PATCH] Btrfs: incremental send, apply asynchronous page cache readahead
Date: Wed, 13 Sep 2017 14:38:49 +0800	[thread overview]
Message-ID: <1505284729-11844-1-git-send-email-peterh@synology.com> (raw)

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 respectively 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..ac67ff6 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_NOFS);
+			if (unlikely(!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


             reply	other threads:[~2017-09-13  6:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-13  6:38 peterh [this message]
2017-09-13  9:33 ` [PATCH] Btrfs: incremental send, apply asynchronous page cache readahead Pasi Kärkkäinen
2017-09-13  9:46   ` peterh
2017-09-13 10:45 ` Filipe Manana
2017-09-15  8:53   ` peterh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505284729-11844-1-git-send-email-peterh@synology.com \
    --to=peterh@synology.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).