Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Christoph Hellwig <hch@infradead.org>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2] btrfs: use IOMAP_DIO_BOUNCE flag instead of falling back to buffered IO
Date: Mon, 25 May 2026 16:46:16 +0930	[thread overview]
Message-ID: <6ff25e6e-ee87-4708-8a86-e4d982edc2df@gmx.com> (raw)
In-Reply-To: <ahP0yXND64FAOsCV@infradead.org>



在 2026/5/25 16:35, Christoph Hellwig 写道:
> On Mon, May 25, 2026 at 02:35:33PM +0930, Qu Wenruo wrote:
>> +	struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp));
>>   	struct btrfs_dio_data data = { 0 };
>> +	const u64 data_profile = btrfs_data_alloc_profile(inode->root->fs_info) &
>> +				 BTRFS_BLOCK_GROUP_PROFILE_MASK;
>> +	unsigned int dio_flags = IOMAP_DIO_PARTIAL | IOMAP_DIO_FSBLOCK_ALIGNED;
>> +
>> +	/*
>> +	 * Userspace may modify the buffer while DIO is in flight. With
>> +	 * data checksumming this would produce a checksum that doesn't
>> +	 * match the persisted data; with duplicated profiles the mirrors
>> +	 * would diverge. Bounce in those cases so writeback sees stable
>> +	 * content.
>> +	 */
>> +	if (!(inode->flags & BTRFS_INODE_NODATASUM) ||
>> +	    (data_profile != BTRFS_BLOCK_GROUP_RAID0 && data_profile != 0))
> 
> Should the 0 here be BTRFS_RAID_SINGLE for better documentation?

That BTRFS_RAID_SINGLE is a special enum for iterating btrfs_raid_array[].

Meanwhile for bit flags we do not use that enum index, even if the 
values match.
> 
> Also the old code only did this for !BTRFS_INODE_NODATASUM and not
> raid, right?

The old code also does the fallback to buffered for raid too.

That's done in commit 7c2830f00c3e ("btrfs: fallback to buffered IO if 
the data profile has duplication").

> 
> 
>> +		dio_flags |= IOMAP_DIO_BOUNCE;
> 
> Splitting the data_profile check into a helper would improve readabilty
> here.

Sure, will go a dedicated helper for that.

>  Maybe even as a prep patch before the actual change, then a
> patch to add IOMAP_DIO_BOUNCE, and the extension to raid as another
> stand-alone well documented patch?
> 
> Also while you touch this, you should probably also check the
> bdev_stable_writes similar to XFS (probably yet another patch).

For btrfs stable writes == data csum so far. But we do not have any bdev 
stable writes checks, thus it will be a pretty huge change if we want to 
take per-dev stable writes into consideration.

Thanks,
Qu

  reply	other threads:[~2026-05-25  7:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25  5:05 [PATCH v2] btrfs: use IOMAP_DIO_BOUNCE flag instead of falling back to buffered IO Qu Wenruo
2026-05-25  7:05 ` Christoph Hellwig
2026-05-25  7:16   ` Qu Wenruo [this message]
2026-05-25  7:23     ` Christoph Hellwig
2026-05-25  9:14 ` Qu Wenruo
2026-05-26  0:38   ` Qu Wenruo
2026-05-26  6:38   ` Christoph Hellwig
2026-05-25 23:55 ` Wang Yugui
2026-05-26 17:59 ` Boris Burkov
2026-05-26 21:42   ` 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=6ff25e6e-ee87-4708-8a86-e4d982edc2df@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=hch@infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.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