Skip to contentSkip to conversation

end_bbio_data_read is strange

DISCUSSION Matthew Wilcox 2 participants 3 messages Sep 16, 2024 – Sep 17, 2024 Btrfs file system

lore
Share & tools
lore
#0 lore raw

I was looking at usage of folio_index() in filesystems (none should need it) and I started looking at end_bbio_data_read(). This function has some things which don't make sense to me, and I think it's an artefact of the "block size is page size" code being converted to support multiple blocks per page without, perhaps, a larger rethink.

The biggest thing that strikes me as strange is the zeroing of the part of the folio past the EOF. Most filesystems do this at I/O submission time when we're still in process context. btrfs is choosing to do this at I/O completion time which might well be in hard or soft interrupt context (and so we're robbing some other process of its timeslice and possibly hot cache).

There are other things that don't make sense to me, but it may just be unfamiliarity with how btrfs handles block size < PAGE_SIZE. This one seems like a genuine problem that should be fixed by someone with a greater understanding of the btrfs code base than me.

#1 lore raw
Quoted 2 lines · Matthew Wilcox

I was looking at usage of folio_index() in filesystems (none should need it) and I started looking at end_bbio_data_read().

I thought folio_index() is no different than folio_pos(), or it has something we should know but didn't?

Quoted 11 lines

This function has
some things which don't make sense to me, and I think it's an artefact of the "block size is page size" code being converted to support multiple blocks per page without, perhaps, a larger rethink.

The biggest thing that strikes me as strange is the zeroing of the part of the folio past the EOF. Most filesystems do this at I/O submission time when we're still in process context. btrfs is choosing to do this at I/O completion time which might well be in hard or soft interrupt context (and so we're robbing some other process of its timeslice and possibly hot cache).

end_bbio_data_read() is always called either in wq context (IO submitted) or the caller's context (not submitted, error path).

The details are inside the real per-device bio handling functions, e.g. btrfs_simple_end_io() for single device IO, which queue btrfs_end_bio_work() into wq.

As btrfs has extra bbio layer to do the multi-device handling and csum verification, so the real endio function is only called after all those handling and it's done in wq context, never directly in irq context.

We may change the timing of zeroing folio just for the sake of consistency, but that will be slow after tons of tests, to avoid unexpected data corruption.

Quoted 6 lines

There are other things that don't make sense to me, but it may just be unfamiliarity with how btrfs handles block size < PAGE_SIZE. This one seems like a genuine problem that should be fixed by someone with a greater understanding of the btrfs code base than me.

For example? I know you're not happy with the extra per block lock/checked/ordered flags.

But for lock flags, it will be there until we change how we submit compressed writes.
Checked and ordered will also be moved to per-folio other than per-sector. But that will be after the block perfect compression support.

What else you're not happy with?

Thanks,
Qu

#2 lore raw
Quoted 6 lines · Qu Wenruo
Quoted 2 lines · Matthew Wilcox

I was looking at usage of folio_index() in filesystems (none should need it) and I started looking at end_bbio_data_read().

I thought folio_index() is no different than folio_pos(), or it has something we should know but didn't?

I put a lot of effort into writing documentation. Why do you not read it? This isn't the first time you've insisted on a personal explanation of something that I'd previously documented, and I don't appreciate it.