linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iomap: Fix direct I/O write consistency check
@ 2020-09-03 16:56 Andreas Gruenbacher
  2020-09-03 21:12 ` Eric Sandeen
  2020-09-07  7:07 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Andreas Gruenbacher @ 2020-09-03 16:56 UTC (permalink / raw)
  To: Christoph Hellwig, Darrick J. Wong
  Cc: linux-xfs, linux-fsdevel, linux-kernel, cluster-devel,
	Andreas Gruenbacher

When a direct I/O write falls back to buffered I/O entirely, dio->size
will be 0 in iomap_dio_complete.  Function invalidate_inode_pages2_range
will try to invalidate the rest of the address space.  If there are any
dirty pages in that range, the write will fail and a "Page cache
invalidation failure on direct I/O" error will be logged.

On gfs2, this can be reproduced as follows:

  xfs_io \
    -c "open -ft foo" -c "pwrite 4k 4k" -c "close" \
    -c "open -d foo" -c "pwrite 0 4k"

Fix this by recognizing 0-length writes.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/iomap/direct-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index c1aafb2ab990..c9d6b4eecdb7 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -108,7 +108,7 @@ static ssize_t iomap_dio_complete(struct iomap_dio *dio)
 	 * ->end_io() when necessary, otherwise a racing buffer read would cache
 	 * zeros from unwritten extents.
 	 */
-	if (!dio->error &&
+	if (!dio->error && dio->size &&
 	    (dio->flags & IOMAP_DIO_WRITE) && inode->i_mapping->nrpages) {
 		int err;
 		err = invalidate_inode_pages2_range(inode->i_mapping,
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iomap: Fix direct I/O write consistency check
  2020-09-03 16:56 [PATCH] iomap: Fix direct I/O write consistency check Andreas Gruenbacher
@ 2020-09-03 21:12 ` Eric Sandeen
  2020-09-03 21:47   ` Andreas Gruenbacher
  2020-09-07  7:07 ` Christoph Hellwig
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Sandeen @ 2020-09-03 21:12 UTC (permalink / raw)
  To: Andreas Gruenbacher, Christoph Hellwig, Darrick J. Wong
  Cc: linux-xfs, linux-fsdevel, linux-kernel, cluster-devel, linux-ext4

On 9/3/20 11:56 AM, Andreas Gruenbacher wrote:
> When a direct I/O write falls back to buffered I/O entirely, dio->size
> will be 0 in iomap_dio_complete.  Function invalidate_inode_pages2_range
> will try to invalidate the rest of the address space.

(Because if ->size == 0 and offset == 0, then invalidating up to (0+0-1) will
invalidate the entire range.)


                err = invalidate_inode_pages2_range(inode->i_mapping,
                                offset >> PAGE_SHIFT,
                                (offset + dio->size - 1) >> PAGE_SHIFT);

so I guess this behavior is unique to writing to a hole at offset 0?

FWIW, this same test yields the same results on ext3 when it falls back to
buffered.

-Eric

> If there are any
> dirty pages in that range, the write will fail and a "Page cache
> invalidation failure on direct I/O" error will be logged.
> 
> On gfs2, this can be reproduced as follows:
> 
>   xfs_io \
>     -c "open -ft foo" -c "pwrite 4k 4k" -c "close" \
>     -c "open -d foo" -c "pwrite 0 4k"
> 
> Fix this by recognizing 0-length writes.
> 
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
>  fs/iomap/direct-io.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index c1aafb2ab990..c9d6b4eecdb7 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -108,7 +108,7 @@ static ssize_t iomap_dio_complete(struct iomap_dio *dio)
>  	 * ->end_io() when necessary, otherwise a racing buffer read would cache
>  	 * zeros from unwritten extents.
>  	 */
> -	if (!dio->error &&
> +	if (!dio->error && dio->size &&
>  	    (dio->flags & IOMAP_DIO_WRITE) && inode->i_mapping->nrpages) {
>  		int err;
>  		err = invalidate_inode_pages2_range(inode->i_mapping,
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iomap: Fix direct I/O write consistency check
  2020-09-03 21:12 ` Eric Sandeen
@ 2020-09-03 21:47   ` Andreas Gruenbacher
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Gruenbacher @ 2020-09-03 21:47 UTC (permalink / raw)
  To: Eric Sandeen
  Cc: Christoph Hellwig, Darrick J. Wong, linux-xfs, linux-fsdevel,
	LKML, cluster-devel, linux-ext4

On Thu, Sep 3, 2020 at 11:12 PM Eric Sandeen <sandeen@sandeen.net> wrote:
> On 9/3/20 11:56 AM, Andreas Gruenbacher wrote:
> > When a direct I/O write falls back to buffered I/O entirely, dio->size
> > will be 0 in iomap_dio_complete.  Function invalidate_inode_pages2_range
> > will try to invalidate the rest of the address space.
>
> (Because if ->size == 0 and offset == 0, then invalidating up to (0+0-1) will
> invalidate the entire range.)
>
>
>                 err = invalidate_inode_pages2_range(inode->i_mapping,
>                                 offset >> PAGE_SHIFT,
>                                 (offset + dio->size - 1) >> PAGE_SHIFT);
>
> so I guess this behavior is unique to writing to a hole at offset 0?
>
> FWIW, this same test yields the same results on ext3 when it falls back to
> buffered.

That's interesting. An ext3 formatted filesystem will invoke
dio_warn_stale_pagecache and thus log the error message, but the error
isn't immediately reported by the "pwrite 0 4k". It takes adding '-c
"fsync"' to the xfs_io command or similar to make it fail.

An ext4 formatted filesystem doesn't show any of these problems.

Thanks,
Andreas

> -Eric
>
> > If there are any
> > dirty pages in that range, the write will fail and a "Page cache
> > invalidation failure on direct I/O" error will be logged.
> >
> > On gfs2, this can be reproduced as follows:
> >
> >   xfs_io \
> >     -c "open -ft foo" -c "pwrite 4k 4k" -c "close" \
> >     -c "open -d foo" -c "pwrite 0 4k"
> >
> > Fix this by recognizing 0-length writes.
> >
> > Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> > ---
> >  fs/iomap/direct-io.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> > index c1aafb2ab990..c9d6b4eecdb7 100644
> > --- a/fs/iomap/direct-io.c
> > +++ b/fs/iomap/direct-io.c
> > @@ -108,7 +108,7 @@ static ssize_t iomap_dio_complete(struct iomap_dio *dio)
> >        * ->end_io() when necessary, otherwise a racing buffer read would cache
> >        * zeros from unwritten extents.
> >        */
> > -     if (!dio->error &&
> > +     if (!dio->error && dio->size &&
> >           (dio->flags & IOMAP_DIO_WRITE) && inode->i_mapping->nrpages) {
> >               int err;
> >               err = invalidate_inode_pages2_range(inode->i_mapping,
> >
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iomap: Fix direct I/O write consistency check
  2020-09-03 16:56 [PATCH] iomap: Fix direct I/O write consistency check Andreas Gruenbacher
  2020-09-03 21:12 ` Eric Sandeen
@ 2020-09-07  7:07 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-09-07  7:07 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: Christoph Hellwig, Darrick J. Wong, linux-xfs, linux-fsdevel,
	linux-kernel, cluster-devel

On Thu, Sep 03, 2020 at 06:56:32PM +0200, Andreas Gruenbacher wrote:
> When a direct I/O write falls back to buffered I/O entirely, dio->size
> will be 0 in iomap_dio_complete.  Function invalidate_inode_pages2_range
> will try to invalidate the rest of the address space.  If there are any
> dirty pages in that range, the write will fail and a "Page cache
> invalidation failure on direct I/O" error will be logged.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-07  7:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 16:56 [PATCH] iomap: Fix direct I/O write consistency check Andreas Gruenbacher
2020-09-03 21:12 ` Eric Sandeen
2020-09-03 21:47   ` Andreas Gruenbacher
2020-09-07  7:07 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).