[Virtio-fs] [PATCH v6 2/2] virtiofsd: use fuse_buf_writev to replace fuse_buf_write for better performance

Dr. David Alan Gilbert dgilbert at redhat.com
Fri Aug 16 15:52:23 UTC 2019


* piaojun (piaojun at huawei.com) wrote:
> 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 at huawei.com>
> Suggested-by: Dr. David Alan Gilbert <dgilbert at redhat.com>
> Suggested-by: Stefan Hajnoczi <stefanha at redhat.com>
> ---
>  contrib/virtiofsd/buffer.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/contrib/virtiofsd/buffer.c b/contrib/virtiofsd/buffer.c
> index 0ed284f..072b5dc 100644
> --- a/contrib/virtiofsd/buffer.c
> +++ b/contrib/virtiofsd/buffer.c
> @@ -322,11 +322,26 @@ 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 copied = 0;
> +	size_t copied = 0, i;
> 
>  	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->count == 1) &&
> +	    (dstv->idx == 0) &&
> +	    (dstv->buf[0].flags & FUSE_BUF_IS_FD)) {
> +		dstv->buf[0].pos += dstv->off;
> +		return fuse_buf_writev(req, &dstv->buf[0], srcv);
> +	}
> +

OK, thanks, I think that's actually a strong enough check, so I'll merge
these now.


Reviewed-by: Dr. David Alan Gilbert <dgilbert at redhat.com>

>  	for (;;) {
>  		const struct fuse_buf *src = fuse_bufvec_current(srcv);
>  		const struct fuse_buf *dst = fuse_bufvec_current(dstv);
> -- 
--
Dr. David Alan Gilbert / dgilbert at redhat.com / Manchester, UK




More information about the Virtio-fs mailing list