btrfs-progs: send: sync splice buf size with kernel when proto 2
PATCH 1/1 btrfs-progs: send: sync splice buf size with kernel when proto 2
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.
--- cmds/send.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
cmds/send.c +15 -2
@@ -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)
Signature · 1 line
2.36.2
Quoted 11 lines · 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.44sbigger 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 <[email protected]>
Added to devel, thanks.
Quoted 8 lines
cmds/send.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)cmds/send.c +0
-0
cmds/send.c line 42
Quoted 7 lines
cmds/send.c +3
-1@@ -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.