Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Wang Yugui <wangyugui@e16-tech.com>
To: linux-btrfs@vger.kernel.org
Subject: Re: FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO
Date: Mon, 22 Dec 2025 23:07:49 +0800	[thread overview]
Message-ID: <20251222230749.FFE2.409509F4@e16-tech.com> (raw)
In-Reply-To: <20251221215913.E7B2.409509F4@e16-tech.com>

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)




  reply	other threads:[~2025-12-22 15:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-21 13:59 FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO Wang Yugui
2025-12-22 15:07 ` Wang Yugui [this message]
2025-12-22 19:49   ` Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251222230749.FFE2.409509F4@e16-tech.com \
    --to=wangyugui@e16-tech.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox