linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: send: sync splice buf size with kernel when proto 2
@ 2022-10-17  3:52 Wang Yugui
  2022-10-18 13:48 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Wang Yugui @ 2022-10-17  3:52 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Wang Yugui

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


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

* Re: [PATCH] btrfs-progs: send: sync splice buf size with kernel when proto 2
  2022-10-17  3:52 [PATCH] btrfs-progs: send: sync splice buf size with kernel when proto 2 Wang Yugui
@ 2022-10-18 13:48 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2022-10-18 13:48 UTC (permalink / raw)
  To: Wang Yugui; +Cc: linux-btrfs

On Mon, Oct 17, 2022 at 11:52:31AM +0800, Wang Yugui wrote:
> 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>

Added to devel, thanks.

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

Such define is missing from kernel, right? It's hidden in
btrfs_ioctl_send as

sctx->send_max_size = ALIGN(SZ_16K + BTRFS_MAX_COMPRESSED, PAGE_SIZE);

would be nice to have that as a separate define.

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

end of thread, other threads:[~2022-10-18 13:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-17  3:52 [PATCH] btrfs-progs: send: sync splice buf size with kernel when proto 2 Wang Yugui
2022-10-18 13:48 ` 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).