From: Dave Chinner <david@fromorbit.com>
To: Andreas Gruenbacher <agruenba@redhat.com>
Cc: cluster-devel@redhat.com, linux-fsdevel@vger.kernel.org,
linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org,
"Darrick J . Wong" <darrick.wong@oracle.com>,
Christoph Hellwig <hch@lst.de>,
Lukas Czerner <lczerner@redhat.com>
Subject: Re: [Q] gfs2: mmap write vs. punch_hole consistency
Date: Sat, 7 Sep 2019 07:27:58 +1000 [thread overview]
Message-ID: <20190906212758.GO1119@dread.disaster.area> (raw)
In-Reply-To: <20190906205241.2292-1-agruenba@redhat.com>
On Fri, Sep 06, 2019 at 10:52:41PM +0200, Andreas Gruenbacher wrote:
> Hi,
>
> I've just fixed a mmap write vs. truncate consistency issue on gfs on
> filesystems with a block size smaller that the page size [1].
>
> It turns out that the same problem exists between mmap write and hole
> punching, and since xfstests doesn't seem to cover that,
AFAIA, fsx exercises it pretty often. Certainly it's found problems
with XFS in the past w.r.t. these operations.
> I've written a
> new test [2].
I suspect that what we really want is a test that runs
_test_generic_punch using mmap rather than pwrite...
> Ext4 and xfs both pass that test; they both apparently
> mark the pages that have a hole punched in them as read-only so that
> page_mkwrite is called before those pages can be written to again.
XFS invalidates the range being hole punched (see
xfs_flush_unmap_range() under XFS_MMAPLOCK_EXCL, which means any
attempt to fault that page back in will block on the MMAPLOCK until
the hole punch finishes.
> gfs2 fails that: for some reason, the partially block-mapped pages are
> not marked read-only on gfs2, and so page_mkwrite is not called for the
> partially block-mapped pages, and the hole is not filled in correctly.
>
> The attached patch fixes the problem, but this really doesn't look right
> as neither ext4 nor xfs require this kind of hack. So what am I
> overlooking, how does this work on ext4 and xfs?
XFS uses XFS_MMAPLOCK_* to serialise page faults against extent
manipulations (shift, hole punch, truncate, swap, etc) and ext4 uses
a similar locking mechanism to do the same thing. Fundamentally, the
page cache does not provide the necessary mechanisms to detect and
prevent invalidation races inside EOF....
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
> fs/gfs2/bmap.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
> index 9ef543dd38e2..e677e813be4c 100644
> --- a/fs/gfs2/bmap.c
> +++ b/fs/gfs2/bmap.c
> @@ -2475,6 +2475,13 @@ int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length)
> if (error)
> goto out;
> }
> + /*
> + * If the first or last page partially lies in the hole, mark
> + * the page read-only so that memory-mapped writes will trigger
> + * page_mkwrite.
> + */
> + pagecache_isize_extended(inode, offset, inode->i_size);
> + pagecache_isize_extended(inode, offset + length, inode->i_size);
See xfs_flush_unmap_range(), which is run under XFS_MMAPLOCK_EXCL
to serialise against incoming page faults...
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2019-09-06 21:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-06 20:52 [Q] gfs2: mmap write vs. punch_hole consistency Andreas Gruenbacher
2019-09-06 21:27 ` Dave Chinner [this message]
2019-09-06 21:48 ` Andreas Gruenbacher
2019-09-06 23:15 ` Dave Chinner
2019-09-09 9:19 ` Jan Kara
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=20190906212758.GO1119@dread.disaster.area \
--to=david@fromorbit.com \
--cc=agruenba@redhat.com \
--cc=cluster-devel@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=hch@lst.de \
--cc=lczerner@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).