[Virtio-fs] [PATCH] virtiofsd: do fallocate for setupmapping requests with write flag

Stefan Hajnoczi stefanha at redhat.com
Wed May 15 15:10:05 UTC 2019


On Tue, May 07, 2019 at 01:58:40PM +0800, Liu Bo wrote:
> We'll have to make sure filesystem has allocated space for the dax
> mapping, otherwise, guest writes from virtiofs may hang since write
> page fault is not able to be resolved if host fs is full
> (->page_mkwrite() return -ENOSPC).

The issues I see with fallocate are:

1. Space is now reserved for anything that is mapped with the write bit,
   even pages that are never written.  This defeats sparseness, which is
   often relied on by applications and users to minimize space usage.

2. The setupmapping performance suffers from the fallocate overhead.

I tend to think that KVM's fault handling should be fixed to check
return values so that the infinite loop is avoided.  The root cause is
in kvm.ko, not in virtiofsd, and fallocate is a workaround rather than a
full fix.

Vivek: Do you have code that stops the async pagefault infinite loop in
kvm.ko?

> Signed-off-by: Liu Bo <bo.liu at linux.alibaba.com>
> ---
>  contrib/virtiofsd/passthrough_ll.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/contrib/virtiofsd/passthrough_ll.c b/contrib/virtiofsd/passthrough_ll.c
> index f14f471..1ddb68f 100644
> --- a/contrib/virtiofsd/passthrough_ll.c
> +++ b/contrib/virtiofsd/passthrough_ll.c
> @@ -1897,12 +1897,28 @@ static void lo_setupmapping(fuse_req_t req, fuse_ino_t ino, uint64_t foffset,
>  
>  	}
>  
> +        if (flags & O_WRONLY) {
> +                /* this may allocate more space than we need. */
> +                ret = fallocate(fd, FALLOC_FL_KEEP_SIZE, foffset, len);
> +                if (ret < 0) {
> +                        ret = errno;
> +                        fprintf(stderr, "%s: fallocate fail (ino=%" PRId64 "fd=%d foffset=0x%" PRIx64 ")\n",
> +                                __func__, ino, fi ? (int)fi->fh : lo_fd(req, ino), foffset);
> +                        goto err;
> +                }
> +
> +                if (lo_debug(req))
> +                        fprintf(stderr, "fallocate (foffset=%" PRIx64 "moffset=%" PRIx64 ")\n",
> +                                foffset, moffset);
> +        }
> +
>          if (fuse_virtio_map(req, &msg, fd)) {
>                  fprintf(stderr, "%s: map over virtio failed (ino=%" PRId64 "fd=%d moffset=0x%" PRIx64 ")\n",
>                          __func__, ino, fi ? (int)fi->fh : lo_fd(req, ino), moffset);
>                  ret = EINVAL;
>          }
>  
> +err:
>  	if (!fi)
>  		close(fd);
>  	fuse_reply_err(req, ret);
> -- 
> 1.8.3.1
> 
> _______________________________________________
> Virtio-fs mailing list
> Virtio-fs at redhat.com
> https://www.redhat.com/mailman/listinfo/virtio-fs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virtio-fs/attachments/20190515/772fd23e/attachment.sig>


More information about the Virtio-fs mailing list