Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Wang Yugui <wangyugui@e16-tech.com>, linux-btrfs@vger.kernel.org
Subject: Re: FOP_DONTCACHE when btrfs Direct IO fallback to buffered IO
Date: Tue, 23 Dec 2025 06:19:51 +1030	[thread overview]
Message-ID: <a85e28ee-6a66-461f-97d1-a65de6e4b800@gmx.com> (raw)
In-Reply-To: <20251222230749.FFE2.409509F4@e16-tech.com>



在 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)
> 
> 
> 
> 


      reply	other threads:[~2025-12-22 19:49 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
2025-12-22 19:49   ` Qu Wenruo [this message]

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=a85e28ee-6a66-461f-97d1-a65de6e4b800@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wangyugui@e16-tech.com \
    /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