public inbox for linux-bcachefs@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Steve Smith <tarkasteve@gmail.com>, linux-bcachefs@vger.kernel.org
Subject: Re: [bug]: fiemap returns zero extents for all files
Date: Fri, 8 Dec 2023 07:22:37 -0500	[thread overview]
Message-ID: <ZXMKjclDEvhx/e3E@bfoster> (raw)
In-Reply-To: <20231206224209.d6xkiv6v3t2qbozg@moria.home.lan>

On Wed, Dec 06, 2023 at 05:42:09PM -0500, Kent Overstreet wrote:
> 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).
> 

Ok, thanks.

> 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.
> 

Yeah that sounds like a decent idea. I'd think we'd just need to merge
data seeks over holes in the btree and then we'd at least have accurate
hole vs. allocated ranges without having to sync.

One thing that still isn't clear is if/how to handle the case of
allocated blocks with dirty pagecache where the latter will COW at
writeback time. I ran a quick test on btrfs out of curiosity and I see
it does show delalloc similar to how XFS does, but also seems to handle
the overwrite case exactly how bcachefs does now. Which is to say the
extent data is subtly inaccurate until writeback (assuming cow mode). I
wonder if it would be preferable here to just treat this as delalloc and
as long as there is pending dirty data, report the extent exactly as if
it were delalloc over a hole...

Brian


      reply	other threads:[~2023-12-08 12:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  5:26 [bug]: fiemap returns zero extents for all files Steve Smith
2023-12-05 14:54 ` Brian Foster
2023-12-05 23:26   ` Steve Smith
2023-12-06 19:01     ` Brian Foster
2023-12-06 22:42       ` Kent Overstreet
2023-12-08 12:22         ` Brian Foster [this message]

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=ZXMKjclDEvhx/e3E@bfoster \
    --to=bfoster@redhat.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=tarkasteve@gmail.com \
    /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