From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [PATCH v3 4/8] xfs: flush eof folio before insert range size update
Date: Mon, 9 Mar 2026 14:24:18 -0400 [thread overview]
Message-ID: <aa8QUlEHNu0C01zF@bfoster> (raw)
In-Reply-To: <20260309173213.GN6033@frogsfrogsfrogs>
On Mon, Mar 09, 2026 at 10:32:13AM -0700, Darrick J. Wong wrote:
> On Mon, Mar 09, 2026 at 09:45:02AM -0400, Brian Foster wrote:
> > The flush in xfs_buffered_write_iomap_begin() for zero range over a
> > data fork hole fronted by COW fork prealloc is primarily designed to
> > provide correct zeroing behavior in particular pagecache conditions.
> > As it turns out, this also partially masks some odd behavior in
> > insert range (via zero range via setattr).
> >
> > Insert range bumps i_size the length of the new range, flushes,
> > unmaps pagecache and cancels COW prealloc, and then right shifts
> > extents from the end of the file back to the target offset of the
> > insert. Since the i_size update occurs before the pagecache flush,
> > this creates a transient situation where writeback around EOF can
> > behave differently.
> >
> > This appears to be corner case situation, but if happens to be
> > fronted by COW fork speculative preallocation and a large, dirty
> > folio that contains at least one full COW block beyond EOF, the
>
> How do we get a large dirty folio with at least one full cow block
> beyond i_size? If we did a pagecache write to the file, then at least
> the incore isize should have been boosted out far enough that the block
> will now be inside EOF, right?
>
It's been quite some time since I first reproduced and diagnosed this so
I'm going from memory, but IIRC it was some odd case like a failure to
split a large folio fully within EOF on a truncate down across it due to
being dirty. I originally thought the large folio thing was actually the
issue, but I don't recall seeing anything that prevents it in this
particular situation. So my understanding from that is that it's more
unexpected in that we wouldn't create a large folio directly in this
situation, but it's still technically possible through oddball fsx
sequences.
From there, we can run into the insert situation described above where
the i_size update -> flush -> extent shift behavior creates a transient
situation where a post-eof block is temporarily within eof.
Brian
> --D
>
> > writeback after i_size is bumped may remap that COW fork block into
> > the data fork within EOF. The block is zeroed and then shifted back
> > out to post-eof, but this is unexpected in that it leads to a
> > written post-eof data fork block. This can cause a zero range
> > warning on a subsequent size extension, because we should never find
> > blocks that require physical zeroing beyond i_size.
> >
> > To avoid this quirk, flush the EOF folio before the i_size update
> > during insert range. The entire range will be flushed, unmapped and
> > invalidated anyways, so this should be relatively unnoticeable.
> >
> > Signed-off-by: Brian Foster <bfoster@redhat.com>
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > ---
> > fs/xfs/xfs_file.c | 17 +++++++++++++++++
> > 1 file changed, 17 insertions(+)
> >
> > diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> > index 6246f34df9fd..48d812b99282 100644
> > --- a/fs/xfs/xfs_file.c
> > +++ b/fs/xfs/xfs_file.c
> > @@ -1263,6 +1263,23 @@ xfs_falloc_insert_range(
> > if (offset >= isize)
> > return -EINVAL;
> >
> > + /*
> > + * Let writeback clean up EOF folio state before we bump i_size. The
> > + * insert flushes before it starts shifting and under certain
> > + * circumstances we can write back blocks that should technically be
> > + * considered post-eof (and thus should not be submitted for writeback).
> > + *
> > + * For example, a large, dirty folio that spans EOF and is backed by
> > + * post-eof COW fork preallocation can cause block remap into the data
> > + * fork. This shifts back out beyond EOF, but creates an expectedly
> > + * written post-eof block. The insert is going to flush, unmap and
> > + * cancel prealloc across this whole range, so flush EOF now before we
> > + * bump i_size to provide consistent behavior.
> > + */
> > + error = filemap_write_and_wait_range(inode->i_mapping, isize, isize);
> > + if (error)
> > + return error;
> > +
> > error = xfs_falloc_setsize(file, isize + len);
> > if (error)
> > return error;
> > --
> > 2.52.0
> >
> >
>
next prev parent reply other threads:[~2026-03-09 18:24 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 13:44 [PATCH v3 0/8] iomap, xfs: improve zero range flushing and lookup Brian Foster
2026-03-09 13:44 ` [PATCH v3 1/8] xfs: fix iomap hole map reporting for zoned zero range Brian Foster
2026-03-09 17:11 ` Darrick J. Wong
2026-03-09 18:18 ` Brian Foster
2026-03-10 14:47 ` Darrick J. Wong
2026-03-10 6:45 ` Christoph Hellwig
2026-03-09 13:45 ` [PATCH v3 2/8] xfs: flush dirty pagecache over hole in zoned mode " Brian Foster
2026-03-09 17:22 ` Darrick J. Wong
2026-03-09 18:19 ` Brian Foster
2026-03-10 6:47 ` Christoph Hellwig
2026-03-10 14:48 ` Darrick J. Wong
2026-03-10 6:45 ` Christoph Hellwig
2026-03-09 13:45 ` [PATCH v3 3/8] iomap, xfs: lift zero range hole mapping flush into xfs Brian Foster
2026-03-09 17:40 ` Darrick J. Wong
2026-03-10 6:47 ` Christoph Hellwig
2026-03-09 13:45 ` [PATCH v3 4/8] xfs: flush eof folio before insert range size update Brian Foster
2026-03-09 17:32 ` Darrick J. Wong
2026-03-09 18:24 ` Brian Foster [this message]
2026-03-09 13:45 ` [PATCH v3 5/8] xfs: look up cow fork extent earlier for buffered iomap_begin Brian Foster
2026-03-09 13:45 ` [PATCH v3 6/8] xfs: only flush when COW fork blocks overlap data fork holes Brian Foster
2026-03-09 17:47 ` Darrick J. Wong
2026-03-09 13:45 ` [PATCH v3 7/8] xfs: replace zero range flush with folio batch Brian Foster
2026-03-09 17:48 ` Darrick J. Wong
2026-03-09 13:45 ` [PATCH v3 8/8] xfs: report cow mappings with dirty pagecache for iomap zero range Brian Foster
2026-03-09 17:56 ` Darrick J. Wong
2026-03-09 18:31 ` Brian Foster
2026-03-09 18:38 ` Darrick J. Wong
2026-03-10 6:50 ` Christoph Hellwig
2026-03-10 14:52 ` Darrick J. Wong
2026-03-10 14:59 ` Christoph Hellwig
2026-03-10 6:49 ` Christoph Hellwig
2026-03-10 6:45 ` [PATCH v3 0/8] iomap, xfs: improve zero range flushing and lookup Christoph Hellwig
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=aa8QUlEHNu0C01zF@bfoster \
--to=bfoster@redhat.com \
--cc=djwong@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