linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Goldwyn Rodrigues <rgoldwyn@suse.de>, linux-btrfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, hch@infradead.org,
	darrick.wong@oracle.com, fdmanana@kernel.org,
	Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: Re: [PATCH 3/5] btrfs: Switch to iomap_dio_rw() for dio
Date: Tue, 26 Nov 2019 13:54:14 +0200	[thread overview]
Message-ID: <c5b05ecd-b25c-5b5e-8b50-1c39871ea620@suse.com> (raw)
In-Reply-To: <20191126031456.12150-4-rgoldwyn@suse.de>



On 26.11.19 г. 5:14 ч., Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> Switch from __blockdev_direct_IO() to iomap_dio_rw().
> Rename btrfs_get_blocks_direct() to btrfs_dio_iomap_begin() and use it
> as iomap_begin() for iomap direct I/O functions. This function
> allocates and locks all the blocks required for the I/O.
> btrfs_submit_direct() is used as the submit_io() hook for direct I/O
> ops.
> 
> Since we need direct I/O reads to go through iomap_dio_rw(), we change
> file_operations.read_iter() to a btrfs_file_read_iter() which calls
> btrfs_direct_IO() for direct reads and falls back to
> generic_file_buffered_read() for incomplete reads and buffered reads.
> 
> We don't need address_space.direct_IO() anymore so set it to noop.
> Similarly, we don't need flags used in __blockdev_direct_IO(). iomap is
> capable of direct I/O reads from a hole, so we don't need to return
> -ENOENT.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> ---
>  fs/btrfs/ctree.h |   2 +
>  fs/btrfs/file.c  |  15 ++++-
>  fs/btrfs/inode.c | 171 ++++++++++++++++++++++++++-----------------------------
>  3 files changed, 97 insertions(+), 91 deletions(-)
> 

<snip>

> -static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
> -				   struct buffer_head *bh_result, int create)
> +static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
> +		loff_t length, unsigned flags, struct iomap *iomap,
> +		struct iomap *srcmap)
>  {
>  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>  	struct extent_map *em;
>  	struct extent_state *cached_state = NULL;
>  	struct btrfs_dio_data *dio_data = NULL;
> -	u64 start = iblock << inode->i_blkbits;
>  	u64 lockstart, lockend;
> -	u64 len = bh_result->b_size;
> +	int create = flags & IOMAP_WRITE;

nit: Imo this should be turned into a bool and renamed to write or
is_write. Create implies we are always creating blocks which is not true
if we are doing overwrite. This has been a misnomer ever since it was
introduced. We really care to distinguish read vs write.

<snip>

> @@ -8636,28 +8637,13 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
>  	struct extent_changeset *data_reserved = NULL;
>  	loff_t offset = iocb->ki_pos;
>  	size_t count = 0;
> -	int flags = 0;
> -	bool wakeup = true;
>  	bool relock = false;
>  	ssize_t ret;
>  
>  	if (check_direct_IO(fs_info, iter, offset))
>  		return 0;
>  
> -	inode_dio_begin(inode);
> -
> -	/*
> -	 * The generic stuff only does filemap_write_and_wait_range, which
> -	 * isn't enough if we've written compressed pages to this area, so
> -	 * we need to flush the dirty pages again to make absolutely sure
> -	 * that any outstanding dirty pages are on disk.
> -	 */
>  	count = iov_iter_count(iter);
> -	if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
> -		     &BTRFS_I(inode)->runtime_flags))
> -		filemap_fdatawrite_range(inode->i_mapping, offset,
> -					 offset + count - 1);
> -
>  	if (iov_iter_rw(iter) == WRITE) {
>  		/*
>  		 * If the write DIO is beyond the EOF, we need update
> @@ -8688,17 +8674,11 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
>  		dio_data.unsubmitted_oe_range_end = (u64)offset;
>  		current->journal_info = &dio_data;
>  		down_read(&BTRFS_I(inode)->dio_sem);
> -	} else if (test_bit(BTRFS_INODE_READDIO_NEED_LOCK,
> -				     &BTRFS_I(inode)->runtime_flags)) {

This is the sole reader of BTRFS_INODE_READDIO_NEED_LOCK flag. Have you
verified this is correct w.r.t btrfs_setsize. I'm very much in favor or
removing the subtle behavior this flag introduced.

On the other hand, with iomap we no longer have control over when
inode_dio_end is called e.g. inode_dio_begin is called before calling
iomap_apply and then it's finished in iomap_dio_complete. Also for DIO
reads you now hold the inode lock which is also held during setattr
(notify_change calls ->setattr callback and it has a
WARN_ON_ONCE(!inode_is_locked(inode)); at the beginning) so perhaps you
can simply delete relevant code in btrfs_setattr as well.

> -		inode_dio_end(inode);
> -		flags = DIO_LOCKING | DIO_SKIP_HOLES;
> -		wakeup = false;
>  	}

<snip>

  reply	other threads:[~2019-11-26 11:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26  3:14 [PATCH 0/5 v2] btrfs direct-io using iomap Goldwyn Rodrigues
2019-11-26  3:14 ` [PATCH 1/5] fs: Export generic_file_buffered_read() Goldwyn Rodrigues
2019-11-26  3:43   ` Matthew Wilcox
2019-11-26 10:10   ` Johannes Thumshirn
2019-11-26 10:43     ` Johannes Thumshirn
2019-11-26  3:14 ` [PATCH 2/5] iomap: add a filesystem hook for direct I/O bio submission Goldwyn Rodrigues
2019-11-26 10:53   ` Nikolay Borisov
2019-11-26 11:51   ` Johannes Thumshirn
2019-11-26  3:14 ` [PATCH 3/5] btrfs: Switch to iomap_dio_rw() for dio Goldwyn Rodrigues
2019-11-26 11:54   ` Nikolay Borisov [this message]
2019-11-26 12:13   ` Nikolay Borisov
2019-11-26  3:14 ` [PATCH 4/5] btrfs: Wait for extent bits to release page Goldwyn Rodrigues
2019-11-26 12:38   ` Nikolay Borisov
2019-11-26 12:42   ` Johannes Thumshirn
2019-11-26  3:14 ` [PATCH 5/5] fs: Remove dio_end_io() Goldwyn Rodrigues
2019-11-26 12:39   ` Nikolay Borisov
2019-11-26 12:50   ` Johannes Thumshirn
2019-11-27 15:51 ` [PATCH 0/5 v2] btrfs direct-io using iomap David Sterba

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=c5b05ecd-b25c-5b5e-8b50-1c39871ea620@suse.com \
    --to=nborisov@suse.com \
    --cc=darrick.wong@oracle.com \
    --cc=fdmanana@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=rgoldwyn@suse.com \
    --cc=rgoldwyn@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).