linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wang Yugui <wangyugui@e16-tech.com>
To: linux-btrfs@vger.kernel.org
Cc: Wang Yugui <wangyugui@e16-tech.com>
Subject: [PATCH] btrfs-progs: send: sync splice buf size with kernel when proto 2
Date: Mon, 17 Oct 2022 11:52:31 +0800	[thread overview]
Message-ID: <20221017035231.51112-1-wangyugui@e16-tech.com> (raw)

When 'btrfs send --proto 2', the max buffer in kernel is changed from
BTRFS_SEND_BUF_SIZE_V1(SZ_64K) to (SZ_16K + BTRFS_MAX_COMPRESSED).

The performance is improved when we use the same buf size in btrfs-progs.
without this patch: 57.96s
with this patch: 48.44s

bigger buf size(SZ_512K) is tested too. but it help 'btrfs send --proto 2' /
'btrfs send --proto 1' just little. so we will not use bigger buffer.

Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
---
 cmds/send.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/cmds/send.c b/cmds/send.c
index ec61aaf4..d18a31a1 100644
--- a/cmds/send.c
+++ b/cmds/send.c
@@ -37,7 +37,10 @@
 #include "cmds/commands.h"
 #include "ioctl.h"
 
-#define SEND_BUFFER_SIZE	SZ_64K
+#define BTRFS_SEND_BUF_SIZE_V1	(SZ_64K)
+#define BTRFS_MAX_COMPRESSED	(SZ_128K)
+#define BTRFS_SEND_BUF_SIZE_V2	(SZ_16K + BTRFS_MAX_COMPRESSED)
+
 
 struct btrfs_send {
 	int send_fd;
@@ -201,11 +204,18 @@ static void *read_sent_data(void *arg)
 	struct btrfs_send *sctx = (struct btrfs_send*)arg;
 
 	while (1) {
+		size_t splice_buf_size = BTRFS_SEND_BUF_SIZE_V1;
 		ssize_t sbytes;
 
+		if(sctx->proto > 1){
+			splice_buf_size = BTRFS_SEND_BUF_SIZE_V2;
+
+			/* try to change pipe buffer size */
+			fcntl(sctx->dump_fd, F_SETPIPE_SZ, splice_buf_size);
+		}
 		/* Source is a pipe, output is either file or stdout */
 		sbytes = splice(sctx->send_fd, NULL, sctx->dump_fd,
-				NULL, SEND_BUFFER_SIZE, SPLICE_F_MORE);
+				NULL, splice_buf_size, SPLICE_F_MORE);
 		if (sbytes < 0) {
 			ret = -errno;
 			error("failed to read stream from kernel: %m");
@@ -261,6 +271,9 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
 		 */
 		io_send.version = send->proto;
 		io_send.flags |= BTRFS_SEND_FLAG_VERSION;
+
+		fcntl(pipefd[0], F_SETPIPE_SZ, BTRFS_SEND_BUF_SIZE_V2);
+		fcntl(pipefd[1], F_SETPIPE_SZ, BTRFS_SEND_BUF_SIZE_V2);
 	}
 
 	if (!ret)
-- 
2.36.2


             reply	other threads:[~2022-10-17  3:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17  3:52 Wang Yugui [this message]
2022-10-18 13:48 ` [PATCH] btrfs-progs: send: sync splice buf size with kernel when proto 2 David Sterba

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=20221017035231.51112-1-wangyugui@e16-tech.com \
    --to=wangyugui@e16-tech.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).