* [Virtio-fs] [PATCH v5 1/2] virtiofsd: add definition of fuse_buf_writev()
2019-08-15 0:54 [Virtio-fs] [PATCH v5 0/2] virtiofsd: Improve io bandwidth by replacing pwrite with pwritev piaojun
@ 2019-08-15 0:57 ` piaojun
2019-08-15 0:59 ` [Virtio-fs] [PATCH v5 2/2] virtiofsd: use fuse_buf_writev to replace fuse_buf_write for better performance piaojun
1 sibling, 0 replies; 3+ messages in thread
From: piaojun @ 2019-08-15 0:57 UTC (permalink / raw)
To: virtio-fs
Define fuse_buf_writev() which use pwritev and writev to improve io
bandwidth.
Signed-off-by: Jun Piao <piaojun@huawei.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
---
contrib/virtiofsd/buffer.c | 31 +++++++++++++++++++++++++++++++
contrib/virtiofsd/seccomp.c | 2 ++
2 files changed, 33 insertions(+)
diff --git a/contrib/virtiofsd/buffer.c b/contrib/virtiofsd/buffer.c
index 655be137..cec762f 100644
--- a/contrib/virtiofsd/buffer.c
+++ b/contrib/virtiofsd/buffer.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <errno.h>
#include <assert.h>
+#include <stdlib.h>
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
{
@@ -71,6 +72,36 @@ static ssize_t fuse_buf_write(const struct fuse_buf *dst, size_t dst_off,
return copied;
}
+static ssize_t fuse_buf_writev(fuse_req_t req,
+ struct fuse_buf *out_buf,
+ struct fuse_bufvec *in_buf)
+{
+ ssize_t res, i;
+ size_t iovcnt = in_buf->count;
+ struct iovec * iov;
+ int fd = out_buf->fd;
+
+ iov = calloc(iovcnt, sizeof(struct iovec));
+ if (!iov)
+ return -ENOMEM;
+
+ for (i = 0; i < iovcnt; i++) {
+ iov[i].iov_base = in_buf->buf[i].mem;
+ iov[i].iov_len = in_buf->buf[i].size;
+ }
+
+ if (out_buf->flags & FUSE_BUF_FD_SEEK)
+ res = pwritev(fd, iov, iovcnt, out_buf->pos);
+ else
+ res = writev(fd, iov, iovcnt);
+
+ if (res == -1)
+ res = -errno;
+
+ free(iov);
+ return res;
+}
+
static ssize_t fuse_buf_read(const struct fuse_buf *dst, size_t dst_off,
const struct fuse_buf *src, size_t src_off,
size_t len)
diff --git a/contrib/virtiofsd/seccomp.c b/contrib/virtiofsd/seccomp.c
index 5f1c873..4bba30b 100644
--- a/contrib/virtiofsd/seccomp.c
+++ b/contrib/virtiofsd/seccomp.c
@@ -60,6 +60,7 @@ static const int syscall_whitelist[] = {
SCMP_SYS(ppoll),
SCMP_SYS(prctl), /* TODO restrict to just PR_SET_NAME? */
SCMP_SYS(preadv),
+ SCMP_SYS(pwritev),
SCMP_SYS(pwrite64),
SCMP_SYS(read),
SCMP_SYS(readlinkat),
@@ -78,6 +79,7 @@ static const int syscall_whitelist[] = {
SCMP_SYS(unlinkat),
SCMP_SYS(utimensat),
SCMP_SYS(write),
+ SCMP_SYS(writev),
};
/* Syscalls used when --syslog is enabled */
--
^ permalink raw reply related [flat|nested] 3+ messages in thread* [Virtio-fs] [PATCH v5 2/2] virtiofsd: use fuse_buf_writev to replace fuse_buf_write for better performance
2019-08-15 0:54 [Virtio-fs] [PATCH v5 0/2] virtiofsd: Improve io bandwidth by replacing pwrite with pwritev piaojun
2019-08-15 0:57 ` [Virtio-fs] [PATCH v5 1/2] virtiofsd: add definition of fuse_buf_writev() piaojun
@ 2019-08-15 0:59 ` piaojun
1 sibling, 0 replies; 3+ messages in thread
From: piaojun @ 2019-08-15 0:59 UTC (permalink / raw)
To: virtio-fs
fuse_buf_writev() only handles the normal write in which src is buffer
and dest is fd. Specially if src buffer represents guest physical
address that can't be mapped by the daemon process, IO must be bounced
back to the VMM to do it by fuse_buf_copy().
Signed-off-by: Jun Piao <piaojun@huawei.com>
Suggested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
---
contrib/virtiofsd/buffer.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/contrib/virtiofsd/buffer.c b/contrib/virtiofsd/buffer.c
index cec762f..ee28367 100644
--- a/contrib/virtiofsd/buffer.c
+++ b/contrib/virtiofsd/buffer.c
@@ -318,11 +318,23 @@ static int fuse_bufvec_advance(struct fuse_bufvec *bufv, size_t len)
ssize_t fuse_buf_copy(fuse_req_t req, struct fuse_bufvec *dstv, struct fuse_bufvec *srcv,
enum fuse_buf_copy_flags flags)
{
+ size_t i;
size_t copied = 0;
if (dstv == srcv)
return fuse_buf_size(dstv);
+ /* use writev to improve bandwidth when all the
+ * src buffers already mapped by the daemon
+ * process */
+ for (i = 0; i < srcv->count; i++) {
+ if ((srcv->buf[i].flags & FUSE_BUF_PHYS_ADDR) ||
+ (srcv->buf[i].flags & FUSE_BUF_IS_FD))
+ break;
+ }
+ if ((i == srcv->count) && (dstv->buf[0].flags & FUSE_BUF_IS_FD))
+ return fuse_buf_writev(req, &dstv->buf[0], srcv);
+
for (;;) {
const struct fuse_buf *src = fuse_bufvec_current(srcv);
const struct fuse_buf *dst = fuse_bufvec_current(dstv);
--
^ permalink raw reply related [flat|nested] 3+ messages in thread