* FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO
@ 2025-12-21 13:59 Wang Yugui
2025-12-22 15:07 ` Wang Yugui
0 siblings, 1 reply; 3+ messages in thread
From: Wang Yugui @ 2025-12-21 13:59 UTC (permalink / raw)
To: linux-btrfs
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 (wangyugui@e16-tech.com)
2025/12/21
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO
2025-12-21 13:59 FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO Wang Yugui
@ 2025-12-22 15:07 ` Wang Yugui
2025-12-22 19:49 ` Qu Wenruo
0 siblings, 1 reply; 3+ messages in thread
From: Wang Yugui @ 2025-12-22 15:07 UTC (permalink / raw)
To: linux-btrfs
Hi,
> 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 (wangyugui@e16-tech.com)
> 2025/12/21
The following dirty patch seems work here.
Best Regards
Wang Yugui (wangyugui@e16-tech.com)
2025/12/22
diff --git a/fs/btrfs/direct-io.c b/fs/btrfs/direct-io.c
index 802d4dbe5b38..2642dceb6911 100644
--- a/fs/btrfs/direct-io.c
+++ b/fs/btrfs/direct-io.c
@@ -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;
}
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index fa82def46e39..64eae7417242 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO
2025-12-22 15:07 ` Wang Yugui
@ 2025-12-22 19:49 ` Qu Wenruo
0 siblings, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2025-12-22 19:49 UTC (permalink / raw)
To: Wang Yugui, linux-btrfs
在 2025/12/23 01:37, Wang Yugui 写道:
> Hi,
>
>> 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 (wangyugui@e16-tech.com)
>> 2025/12/21
>
> The following dirty patch seems work here.
>
> Best Regards
> Wang Yugui (wangyugui@e16-tech.com)
> 2025/12/22
>
>
> diff --git a/fs/btrfs/direct-io.c b/fs/btrfs/direct-io.c
> index 802d4dbe5b38..2642dceb6911 100644
> --- a/fs/btrfs/direct-io.c
> +++ b/fs/btrfs/direct-io.c
> @@ -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.
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index fa82def46e39..64eae7417242 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -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)
>
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-22 19:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-21 13:59 FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO Wang Yugui
2025-12-22 15:07 ` Wang Yugui
2025-12-22 19:49 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox