On Wed, Dec 06, 2023 at 02:01:02PM -0500, Brian Foster wrote:
> On Wed, Dec 06, 2023 at 10:26:14AM +1100, Steve Smith wrote:
> > Hi Brian,
> > 
> > Thanks for the suggestion. Yes, the ioctl call that xfs_io makes is
> > basically identical to the one the test makes, except it has the SYNC
> > flag set. Adding this flag (or calling fsync) results in expected
> > behaviour (mapped_extents > 0).
> > 
> 
> Ah..
> 
> > I assume that the bcachefs fiemap impl ignores unwritten data and only
> > responds with flushed extents? I'm not sure if this is correct; for
> > comparison, XFS, Btfs, zfs, and ext4, all return the extent map
> > immediately after write without syncing.
> > 
> 
> Ok, thanks for digging into the difference. I can reproduce what you
> observe by just removing the sync flag from the xfs_io command.

Whoops, yes, this is missing.

> 
> I know that XFS basically looks up extents in the in-core extent tree,
> which will include things like delayed allocation (i.e. buffered writes
> that have not yet been physically allocated and flushed to disk). It
> looks like bcachefs fiemap just walks the extents btree for associated
> inode keys. I suspect the buffered write path is just not updating the
> tree in any way, which means fiemap won't see extents until dirty data
> is flushed out. FWIW, this can also be observed by doing buffered
> overwrites and observing that the underlying block range does not change
> until the file data is flushed.

Correct - the only place dirty data can be found is in the pagecache
(which means the buffered write path doesn't have any other data
structures to update).

Don't know if it'll be useful, but the lseek() (SEEK_DATA, SEEK_HOLE)
also has to do this "check both the extents btree and the pagecache at
the same time" thing - might be worth looking at that to see if any of
that code can be abstracted/reused.

Reply via email to