Subject: linux-next: manual merge of the vfs tree with the btrfs tree

From: Stephen Rothwell <[email-masked]>
Date: Mon, 11 Jul 2022 10:34:15 +1000

Hi all,

Today's linux-next merge of the vfs tree got a conflict in:

  fs/btrfs/file.c

between commit:

  c8223467948b ("btrfs: don't fallback to buffered IO for NOWAIT direct IO writes")

from the btrfs tree and commit:

  eacdf4eaca63 ("btrfs: use IOMAP_DIO_NOSYNC")

from the vfs tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc fs/btrfs/file.c
index 1876072dee9d,30e6aef9739f..000000000000
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@@ -1846,36 -1846,8 +1846,35 @@@ static ssize_t check_direct_IO(struct b
  	return 0;
  }
  
 +static size_t dio_fault_in_size(const struct kiocb *iocb,
 +				const struct iov_iter *iov,
 +				size_t prev_left)
 +{
 +	const size_t left = iov_iter_count(iov);
 +	size_t size = PAGE_SIZE;
 +
 +	/*
 +	 * If there's no progress since the last time we had to fault in pages,
 +	 * then we fault in at most 1 page. Faulting in more than that may
 +	 * result in making very slow progress or falling back to buffered IO,
 +	 * because by the time we retry the DIO operation some of the first
 +	 * remaining pages may have been evicted in order to fault in other pages
 +	 * that follow them. That can happen when we are under memory pressure and
 +	 * the iov represents a large buffer.
 +	 */
 +	if (left != prev_left) {
 +		int dirty_tresh = current->nr_dirtied_pause - current->nr_dirtied;
 +
 +		size = max(dirty_tresh, 8) << PAGE_SHIFT;
 +		size = min_t(size_t, SZ_1M, size);
 +	}
 +	size -= offset_in_page(iocb->ki_pos);
 +
 +	return min(left, size);
 +}
 +
  static ssize_t btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)
  {
- 	const bool is_sync_write = (iocb->ki_flags & IOCB_DSYNC);
  	struct file *file = iocb->ki_filp;
  	struct inode *inode = file_inode(file);
  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@@ -1993,17 -1954,7 +1983,10 @@@ again
  
  	btrfs_inode_unlock(inode, ilock_flags);
  
- 	/*
- 	 * Add back IOCB_DSYNC. Our caller, btrfs_file_write_iter(), will do
- 	 * the fsync (call generic_write_sync()).
- 	 */
- 	if (is_sync_write)
- 		iocb->ki_flags |= IOCB_DSYNC;
- 
 -	/* If 'err' is -ENOTBLK then it means we must fallback to buffered IO. */
 +	/*
 +	 * If 'err' is -ENOTBLK or we have not written all data, then it means
 +	 * we must fallback to buffered IO.
 +	 */
  	if ((err < 0 && err != -ENOTBLK) || !iov_iter_count(from))
  		goto out;