FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO
Hi,
Could we add FOP_DONTCACHE support when btrfs Direct IO fallback to buffered IO?
I noticed similar logic in zfs-2.4.0 too.
https://github.com/openzfs/zfs/releases/tag/zfs-2.4.0
Uncached IO: Direct IO fallback to a light-weight uncached IO when unaligned
Best Regards
Wang Yugui ([email protected])
2025/12/21
Hi,
Quoted 4 lines
Hi,
Could we add
FOP_DONTCACHEsupport when btrfs Direct IO fallback to buffered IO?
Quoted 8 lines
I noticed similar logic in zfs-2.4.0 too.
https://github.com/openzfs/zfs/releases/tag/zfs-2.4.0
Uncached IO: Direct IO fallback to a light-weight uncached IO when unalignedBest Regards
Wang Yugui ([email protected])
2025/12/21
The following dirty patch seems work here.
Best Regards
Wang Yugui ([email protected])
2025/12/22
fs/btrfs/direct-io.c +1 -0
@@ -881,6 +881,7 @@ ssize_t btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)*/ if (!(BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM )) {btrfs_inode_unlock (BTRFS_I (inode), ilock_flags); + iocb->ki_flags |=IOCB_DONTCACHE ; goto buffered; }
fs/btrfs/file.c +1 -1
@@ -3843,7 +3843,7 @@ const struct file_operations btrfs_file_operations = {#endif .remap_file_range = btrfs_remap_file_range, .uring_cmd = btrfs_uring_cmd, - .fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC, + .fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC | FOP_DONTCACHE, };int btrfs_fdatawrite_range (struct btrfs_inode *inode,loff_t start,loff_t end)
Quoted 27 lines · Wang Yugui
Hi,
Quoted 4 lines
Hi,
Could we add
FOP_DONTCACHEsupport when btrfs Direct IO fallback to buffered IO?Quoted 8 lines
I noticed similar logic in zfs-2.4.0 too.
https://github.com/openzfs/zfs/releases/tag/zfs-2.4.0
Uncached IO: Direct IO fallback to a light-weight uncached IO when unalignedBest Regards
Wang Yugui ([email protected])
2025/12/21The following dirty patch seems work here.
Best Regards
Wang Yugui ([email protected])
2025/12/22fs/btrfs/direct-io.c +0
-0
fs/btrfs/direct-io.c ssize_t btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from) · line 886
Quoted 6 lines
fs/btrfs/direct-io.c +1
-0@@ -881,6 +881,7 @@ ssize_t btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)*/ if (!(BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM )) {btrfs_inode_unlock (BTRFS_I (inode), ilock_flags); + iocb->ki_flags |=IOCB_DONTCACHE ; goto buffered; }
Nope, run the full fstest and you will crash.
The problem is how btrfs handling compression, the writeback range for compression will stay locked (thus async), and can be marked writeback at almost any time.
That's why we have all the extra per-block handling for writeback other than other fses' regular mark the full folio writeback.
Quoted 18 lines
fs/btrfs/file.c +1
-1@@ -3843,7 +3843,7 @@ const struct file_operations btrfs_file_operations = {#endif .remap_file_range = btrfs_remap_file_range, .uring_cmd = btrfs_uring_cmd, - .fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC, + .fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC | FOP_DONTCACHE, };int btrfs_fdatawrite_range (struct btrfs_inode *inode,loff_t start,loff_t end)