From: Eryu Guan <eguan@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: warnings complaining IOMAP_DELALLOC blocks in iomap_dio_actor from generic/446
Date: Tue, 25 Jul 2017 01:51:25 +0800 [thread overview]
Message-ID: <20170724175125.GH9167@eguan.usersys.redhat.com> (raw)
In-Reply-To: <20170724160551.GB4352@magnolia>
On Mon, Jul 24, 2017 at 09:05:51AM -0700, Darrick J. Wong wrote:
> On Mon, Jul 24, 2017 at 10:50:19PM +0800, Eryu Guan wrote:
> > Hi all,
> >
> > Currently generic/446 could trigger a warning in iomap_dio_actor()
> > easily, it's complaining about unexpected iomap->type (see the end for
> > full call trace).
> >
> > fs/iomap.c: iomap_dio_actor()
> > 859 default:
> > 860 WARN_ON_ONCE(1);
> > 861 return -EIO;
> >
> > It's due to the race between direct read and mmap write pagefault on the
> > same *sparse* file.
> >
> > direct read process mmap write process
> > xfs_file_dio_aio_read (take IOLOCK_SHARED)
> > iomap_dio_rw
> > iomap_apply
> > filemap_write_and_wait_range
> > invalidate_inode_pages2_range
> > iomap_apply
> > mmap
> > xfs_filemap_page_mkwrite (take MMAPLOCK_SHARED)
> > iomap_page_mkwrite
> > iomap_apply
> > xfs_file_iomap_begin
> > xfs_file_iomap_begin_delay (take ILOCK_EXCL)
> > (release ILOCK_EXCL)
> > ...
> > xfs_file_iomap_begin
> > (take ILOCK and read in bmap info)
> > iomap_dio_actor
> > ...
> >
> > The dio path and page_mkwrite path are taking different locks so they're
> > not serialized. So after dio read flushing the file range but before
> > taking ILOCK, the page faults from mmap write could fault in and update
> > the file map first with delalloc blocks. Then the dio reader sees this
> > delalloc block map unexpectedly.
> >
> > I'm not sure what's the best way to fix it, but a quick hack of
> > disabling delalloc in the write page fault path could do the work for
> > me, e.g.
> >
> > --- a/fs/xfs/xfs_iomap.c
> > +++ b/fs/xfs/xfs_iomap.c
> > @@ -981,7 +981,7 @@ xfs_file_iomap_begin(
> > if (XFS_FORCED_SHUTDOWN(mp))
> > return -EIO;
> >
> > - if (((flags & (IOMAP_WRITE | IOMAP_DIRECT)) == IOMAP_WRITE) &&
> > + if (((flags & (IOMAP_WRITE|IOMAP_DIRECT|IOMAP_FAULT)) == IOMAP_WRITE) &&
> > !IS_DAX(inode) && !xfs_get_extsz_hint(ip)) {
> > /* Reserve delalloc blocks for regular writeback. */
> > return xfs_file_iomap_begin_delay(inode, offset, length, flags,
> >
> > So that mmap write page fault brings in already allocated blocks, and
> > dio reader sees non-IOMAP_DELALLOC iomaps.
>
> But now we can't take advantage of delayed allocation for mmap writes
> even when the user isn't being evil by peppering us with dio reads.
That's true, so I called it a hack not fix :)
And I'm wondering what's the bigger problem of letting the dio path take
MMAPLOCK too to serialize against mmap page faults? e.g.
xfs_file_dio_aio_read() takes XFS_MMAPLOCK_SHRED and
xfs_filemap_page_mkwrite() takes XFS_MMAPLOCK_EXCL.
>
> > I know concurrent dio and mmap io are not recommended, so is this
> > something that doens't need a fix at all, and the test should filter out
> > the warning instead?
>
> XFS no longer BUG_ON, so I guess it's fine if the test filters out the
> warning.
OK.
>
> It looks like the end result of a dioread/mmapwrite collision is that
> the dio reader gets -EIO. Would it be better to return a short read?
Yes, right now dio read gets EIO in this case. I can't tell which one is
better, if the whole dio vs mmap is not recommended, EIO seems to be a
strong signal that indicates "don't do this " :)
Thanks,
Eryu
next prev parent reply other threads:[~2017-07-24 17:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-24 14:50 warnings complaining IOMAP_DELALLOC blocks in iomap_dio_actor from generic/446 Eryu Guan
2017-07-24 16:05 ` Darrick J. Wong
2017-07-24 17:51 ` Eryu Guan [this message]
2017-07-24 18:51 ` Darrick J. Wong
2017-07-24 22:02 ` Dave Chinner
2017-07-25 7:53 ` Eryu Guan
2017-07-25 23:43 ` Dave Chinner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170724175125.GH9167@eguan.usersys.redhat.com \
--to=eguan@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox