Re: Any way to ensure minimal folio size and alignment for iomap based direct IO?

Qu Wenruo
2025-09-15T23:21:08Z

在 2025/9/16 08:35, Matthew Wilcox 写道:
> On Tue, Sep 16, 2025 at 07:16:48AM +0930, Qu Wenruo wrote:
>>> Is it very difficult to add multi-shot checksum calls for a data block
>>> in btrfs? Does it break certain reliability guarantees?
>>
>> I'd say it's not impossible, but still not an easy thing to do.
>>
>> E.g. at data read time we need to verify the checksum. Currently we're able
>> to do the checksum for one block in one go, then advance the bio iter.
>>
>> But with multi-shot one, we have to update the shash several times before we
>> can determine if the result is correct.
>>
>> There is even compression algorithm which can not support multi-shot
>> interface, lzo.
>>
>> Thankfully compression is only possible for buffered IO, so it's not
>> involved in this case.
>
> Would it be acceptable to vmap() the pages and do the checksum on the
> virtual address?

That may not be any better than multi-shot runs, as we still need to
advance the iter by a sub-block sized length and mapping them.

Considering we need to do sub-block handling anyway, I'll just come up
with a helper to handle the iteration.

>
>> However then the problem is why the read iov_iter passes the alignment
>> check, but we still get the bio not meeting the large folio requirement?
>
> The virtual address _is_ aligned. It's just not backed with large
> folios, for whatever reason.
>

Oh, that explains the problem.

So even if we do the extra checks to ensure all the pages of the iter is
backed by large folios inside btrfs, it will still be very problematic
for user space programs.

As they have no control on the underlying page layouts, and will hit
random DIO failure or fallback, which is not acceptable for end users.

Thanks a lot for the determining answer,
Qu