<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Jan Kara <<a href="mailto:jack@suse.cz">jack@suse.cz</a>> schrieb am Mo., 26. Juli 2021, 19:21:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri 23-07-21 22:58:38, Andreas Gruenbacher wrote:<br>
> In __iomap_dio_rw, when iomap_apply returns an -EFAULT error, complete the<br>
> request synchronously and reset the iterator to the start position.  This<br>
> allows callers to deal with the failure and retry the operation.<br>
> <br>
> In gfs2, we need to disable page faults while we're holding glocks to prevent<br>
> deadlocks.  This patch is the minimum solution I could find to make<br>
> iomap_dio_rw work with page faults disabled.  It's still expensive because any<br>
> I/O that was carried out before hitting -EFAULT needs to be retried.<br>
> <br>
> A possible improvement would be to add an IOMAP_DIO_FAULT_RETRY or similar flag<br>
> that would allow iomap_dio_rw to return a short result when hitting -EFAULT.<br>
> Callers could then retry only the rest of the request after dealing with the<br>
> page fault.<br>
> <br>
> Asynchronous requests turn into synchronous requests up to the point of the<br>
> page fault in any case, but they could be retried asynchronously after dealing<br>
> with the page fault.  To make that work, the completion notification would have<br>
> to include the bytes read or written before the page fault(s) as well, and we'd<br>
> need an additional iomap_dio_rw argument for that.<br>
> <br>
> Signed-off-by: Andreas Gruenbacher <<a href="mailto:agruenba@redhat.com" target="_blank" rel="noreferrer">agruenba@redhat.com</a>><br>
> ---<br>
>  fs/iomap/direct-io.c | 9 +++++++++<br>
>  1 file changed, 9 insertions(+)<br>
> <br>
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c<br>
> index cc0b4bc8861b..b0a494211bb4 100644<br>
> --- a/fs/iomap/direct-io.c<br>
> +++ b/fs/iomap/direct-io.c<br>
> @@ -561,6 +561,15 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,<br>
>               ret = iomap_apply(inode, pos, count, iomap_flags, ops, dio,<br>
>                               iomap_dio_actor);<br>
>               if (ret <= 0) {<br>
> +                     if (ret == -EFAULT) {<br>
> +                             /*<br>
> +                              * To allow retrying the request, fail<br>
> +                              * synchronously and reset the iterator.<br>
> +                              */<br>
> +                             wait_for_completion = true;<br>
> +                             iov_iter_revert(dio->submit.iter, dio->size);<br>
> +                     }<br>
> +<br>
<br>
Hum, OK, but this means that if userspace submits large enough write, GFS2<br>
will livelock trying to complete it? While other filesystems can just<br>
submit multiple smaller bios constructed in iomap_apply() (paging in<br>
different parts of the buffer) and thus complete the write?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">No. First, this affects reads but not writes. We cannot just blindly repeat writes; when a page fault occurs in the middle of a write, the result will be a short write. For reads, the plan is to ads a flag to allow iomap_dio_rw to return a partial result when a page fault occurs. (Currently, it fails the entire request.) Then we can handle the page fault and complete the rest of the request.</div><div dir="auto"><br></div><div dir="auto">The changes needed for that are simple on the iomap side, but we need to go through some gymnastics for handling the page fault without giving up the glock in the non-contended case. There will still be the potential for losing the lock and having to re-acquire it, in which case we'll actually have to repeat the entire read.</div><div dir="auto"><br></div><div dir="auto">Thanks,</div><div dir="auto">Andreas</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                                                                Honza<br>
<br>
>                       /* magic error code to fall back to buffered I/O */<br>
>                       if (ret == -ENOTBLK) {<br>
>                               wait_for_completion = true;<br>
> -- <br>
> 2.26.3<br>
> <br>
-- <br>
Jan Kara <<a href="mailto:jack@suse.com" target="_blank" rel="noreferrer">jack@suse.com</a>><br>
SUSE Labs, CR<br>
</blockquote></div></div></div>