在 2025/2/3 19:10, hch@xxxxxxxxxxxxx 写道:
On Mon, Feb 03, 2025 at 07:06:15PM +1030, Qu Wenruo wrote:
Thus my current plan to fix it is to make btrfs to skip csum for direct IO.
This will make btrfs to align with EXT4/XFS behavior, without the complex
AS_STABLE_FLAGS passing (and there is no way for user space to probe that
flag IIRC).
But that will break the current per-inode level NODATASUM setting, and will
cause some incompatibility (a new incompat flag needed, extra handling if no
data csum found, extra fsck support etc).
I don't think simply removing the checksums when using direct I/O is
a good idea as it unexpectedly reduces the protection envelope. The
best (or least bad) fix would be to simply not support actually direct
I/O without NODATASUM and fall back to buffered I/O (preferably the new
uncached variant from Jens) unless explicitly overridden.
That always falling-back-to-buffered-IO sounds pretty good.
(For NODATASUM inodes, we do not need to fallback though).
The only concern is performance.
I guess even for the uncached write it still involves some extra folio
copy, thus not completely the same performance level of direct IO?
And always falling back (for inodes with datacsum) may also sound a
little overkilled.
If the program is properly coded, and no contents change halfway, we
always pay the performance penalty but without really any extra benefit.
I guess it really depends on the performance of uncached writes.
(And I really hope it's not obviously slower than direct IO)
Thanks,
Qu