All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@lst.de>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH 4/9] iocb: delay evaluation of IS_SYNC(...) until we want to check IOCB_DSYNC
Date: Tue, 7 Jun 2022 12:34:50 +0200	[thread overview]
Message-ID: <20220607103450.qmkgtt2brbzvx4fu@quack3.lan> (raw)
In-Reply-To: <Yp7P2htu+wZsZ7mc@zeniv-ca.linux.org.uk>

On Tue 07-06-22 04:11:06, Al Viro wrote:
> New helper to be used instead of direct checks for IOCB_DSYNC:
> iocb_is_dsync(iocb).  Checks converted, which allows to avoid
> the IS_SYNC(iocb->ki_filp->f_mapping->host) part (4 cache lines)
> from iocb_flags() - it's checked in iocb_is_dsync() instead
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Does it really matter that much when we have io_is_direct() just two lines
above which does: IS_DAX(filp->f_mapping->host)?

Also presumably even if we got rid of the IS_DAX check, we'll need to do
file->f_mapping->host traversal sooner rather than later anyway so it is
not clear to me how much it helps performance to defer this traversal to a
bit later.

Finally it seems a bit error prone to be checking some IOCB_ flags directly
while IOCB_DSYNC needs to be checked with iocb_is_dsync() instead. I think
we'll grow some place mistakenly checking IOCB_DSYNC sooner rather than
later. So maybe at least rename IOCB_DSYNC to __IOCB_DSYNC to make it more
obvious in the name that something unusual is going on?

								Honza

> ---
>  block/fops.c         |  2 +-
>  fs/btrfs/file.c      |  2 +-
>  fs/direct-io.c       |  2 +-
>  fs/fuse/file.c       |  2 +-
>  fs/iomap/direct-io.c | 22 ++++++++++++----------
>  fs/zonefs/super.c    |  2 +-
>  include/linux/fs.h   | 10 ++++++++--
>  7 files changed, 25 insertions(+), 17 deletions(-)
> 
> diff --git a/block/fops.c b/block/fops.c
> index d6b3276a6c68..6e86931ab847 100644
> --- a/block/fops.c
> +++ b/block/fops.c
> @@ -37,7 +37,7 @@ static unsigned int dio_bio_write_op(struct kiocb *iocb)
>  	unsigned int op = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
>  
>  	/* avoid the need for a I/O completion work item */
> -	if (iocb->ki_flags & IOCB_DSYNC)
> +	if (iocb_is_dsync(iocb))
>  		op |= REQ_FUA;
>  	return op;
>  }
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 98f81e304eb1..54358a5c9d56 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -2021,7 +2021,7 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from,
>  	struct file *file = iocb->ki_filp;
>  	struct btrfs_inode *inode = BTRFS_I(file_inode(file));
>  	ssize_t num_written, num_sync;
> -	const bool sync = iocb->ki_flags & IOCB_DSYNC;
> +	const bool sync = iocb_is_dsync(iocb);
>  
>  	/*
>  	 * If the fs flips readonly due to some impossible error, although we
> diff --git a/fs/direct-io.c b/fs/direct-io.c
> index 840752006f60..39647eb56904 100644
> --- a/fs/direct-io.c
> +++ b/fs/direct-io.c
> @@ -1210,7 +1210,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
>  	 */
>  	if (dio->is_async && iov_iter_rw(iter) == WRITE) {
>  		retval = 0;
> -		if (iocb->ki_flags & IOCB_DSYNC)
> +		if (iocb_is_dsync(iocb))
>  			retval = dio_set_defer_completion(dio);
>  		else if (!dio->inode->i_sb->s_dio_done_wq) {
>  			/*
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index 05caa2b9272e..00fa861aeead 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -1042,7 +1042,7 @@ static unsigned int fuse_write_flags(struct kiocb *iocb)
>  {
>  	unsigned int flags = iocb->ki_filp->f_flags;
>  
> -	if (iocb->ki_flags & IOCB_DSYNC)
> +	if (iocb_is_dsync(iocb))
>  		flags |= O_DSYNC;
>  	if (iocb->ki_flags & IOCB_SYNC)
>  		flags |= O_SYNC;
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 0f16479b13d6..2be8d9e98fbc 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -548,17 +548,19 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		}
>  
>  		/* for data sync or sync, we need sync completion processing */
> -		if (iocb->ki_flags & IOCB_DSYNC && !(dio_flags & IOMAP_DIO_NOSYNC))
> -			dio->flags |= IOMAP_DIO_NEED_SYNC;
> +		if (iocb_is_dsync(iocb)) {
> +			if (!(dio_flags & IOMAP_DIO_NOSYNC))
> +				dio->flags |= IOMAP_DIO_NEED_SYNC;
>  
> -		/*
> -		 * For datasync only writes, we optimistically try using FUA for
> -		 * this IO.  Any non-FUA write that occurs will clear this flag,
> -		 * hence we know before completion whether a cache flush is
> -		 * necessary.
> -		 */
> -		if ((iocb->ki_flags & (IOCB_DSYNC | IOCB_SYNC)) == IOCB_DSYNC)
> -			dio->flags |= IOMAP_DIO_WRITE_FUA;
> +			/*
> +			 * For datasync only writes, we optimistically try
> +			 * using FUA for this IO.  Any non-FUA write that
> +			 * occurs will clear this flag, hence we know before
> +			 * completion whether a cache flush is necessary.
> +			 */
> +			if (!(iocb->ki_flags & IOCB_SYNC))
> +				dio->flags |= IOMAP_DIO_WRITE_FUA;
> +		}
>  	}
>  
>  	if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) {
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index bcb21aea990a..04a98b4cd7ee 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -746,7 +746,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
>  			REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE, GFP_NOFS);
>  	bio->bi_iter.bi_sector = zi->i_zsector;
>  	bio->bi_ioprio = iocb->ki_ioprio;
> -	if (iocb->ki_flags & IOCB_DSYNC)
> +	if (iocb_is_dsync(iocb))
>  		bio->bi_opf |= REQ_FUA;
>  
>  	ret = bio_iov_iter_get_pages(bio, from);
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 6a2a4906041f..380a1292f4f9 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2720,6 +2720,12 @@ extern int vfs_fsync(struct file *file, int datasync);
>  extern int sync_file_range(struct file *file, loff_t offset, loff_t nbytes,
>  				unsigned int flags);
>  
> +static inline bool iocb_is_dsync(const struct kiocb *iocb)
> +{
> +	return (iocb->ki_flags & IOCB_DSYNC) ||
> +		IS_SYNC(iocb->ki_filp->f_mapping->host);
> +}
> +
>  /*
>   * Sync the bytes written if this was a synchronous write.  Expect ki_pos
>   * to already be updated for the write, and will return either the amount
> @@ -2727,7 +2733,7 @@ extern int sync_file_range(struct file *file, loff_t offset, loff_t nbytes,
>   */
>  static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count)
>  {
> -	if (iocb->ki_flags & IOCB_DSYNC) {
> +	if (iocb_is_dsync(iocb)) {
>  		int ret = vfs_fsync_range(iocb->ki_filp,
>  				iocb->ki_pos - count, iocb->ki_pos - 1,
>  				(iocb->ki_flags & IOCB_SYNC) ? 0 : 1);
> @@ -3262,7 +3268,7 @@ static inline int iocb_flags(struct file *file)
>  		res |= IOCB_APPEND;
>  	if (file->f_flags & O_DIRECT)
>  		res |= IOCB_DIRECT;
> -	if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host))
> +	if (file->f_flags & O_DSYNC)
>  		res |= IOCB_DSYNC;
>  	if (file->f_flags & __O_SYNC)
>  		res |= IOCB_SYNC;
> -- 
> 2.30.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2022-06-07 10:35 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07  4:08 [RFC][PATCHES] iov_iter stuff Al Viro
2022-06-07  4:09 ` [PATCH 1/9] No need of likely/unlikely on calls of check_copy_size() Al Viro
2022-06-07  4:41   ` Christoph Hellwig
2022-06-07 11:49   ` Christian Brauner
2022-06-07  4:09 ` [PATCH 2/9] btrfs_direct_write(): cleaner way to handle generic_write_sync() suppression Al Viro
2022-06-07  4:42   ` Christoph Hellwig
2022-06-07 16:06     ` Al Viro
2022-06-07 23:27       ` Al Viro
2022-06-07 23:31         ` [PATCH 01/10] No need of likely/unlikely on calls of check_copy_size() Al Viro
2022-06-07 23:31           ` [PATCH 02/10] teach iomap_dio_rw() to suppress dsync Al Viro
2022-06-08  6:18             ` Christoph Hellwig
2022-06-08 15:17             ` Darrick J. Wong
2022-06-10 11:38             ` Christian Brauner
2022-06-07 23:31           ` [PATCH 03/10] btrfs: use IOMAP_DIO_NOSYNC Al Viro
2022-06-08  6:18             ` Christoph Hellwig
2022-06-10 11:09             ` Christian Brauner
2022-06-07 23:31           ` [PATCH 04/10] struct file: use anonymous union member for rcuhead and llist Al Viro
2022-06-07 23:31           ` [PATCH 05/10] iocb: delay evaluation of IS_SYNC(...) until we want to check IOCB_DSYNC Al Viro
2022-06-10 11:41             ` Christian Brauner
2022-06-07 23:31           ` [PATCH 06/10] keep iocb_flags() result cached in struct file Al Viro
2022-06-09  0:35             ` Dave Chinner
2022-06-10 11:43             ` Christian Brauner
2022-06-07 23:31           ` [PATCH 07/10] copy_page_{to,from}_iter(): switch iovec variants to generic Al Viro
2022-06-07 23:31           ` [PATCH 08/10] new iov_iter flavour - ITER_UBUF Al Viro
2022-06-07 23:31           ` [PATCH 09/10] switch new_sync_{read,write}() to ITER_UBUF Al Viro
2022-06-10 11:11             ` Christian Brauner
2022-06-07 23:31           ` [PATCH 10/10] iov_iter_bvec_advance(): don't bother with bvec_iter Al Viro
2022-06-08  6:16       ` [PATCH 2/9] btrfs_direct_write(): cleaner way to handle generic_write_sync() suppression Christoph Hellwig
2022-06-07 14:49   ` Matthew Wilcox
2022-06-07 20:17     ` Al Viro
2022-06-07  4:10 ` [PATCH 3/9] struct file: use anonymous union member for rcuhead and llist Al Viro
2022-06-07 10:18   ` Jan Kara
2022-06-07 11:46   ` Christian Brauner
2022-06-07  4:11 ` [PATCH 4/9] iocb: delay evaluation of IS_SYNC(...) until we want to check IOCB_DSYNC Al Viro
2022-06-07 10:34   ` Jan Kara [this message]
2022-06-07 15:34     ` Al Viro
2022-06-07  4:11 ` [PATCH 5/9] keep iocb_flags() result cached in struct file Al Viro
2022-06-07  4:12 ` [PATCH 6/9] copy_page_{to,from}_iter(): switch iovec variants to generic Al Viro
2022-06-07  4:12 ` [PATCH 7/9] new iov_iter flavour - ITER_UBUF Al Viro
2022-06-07  4:13 ` [PATCH 8/9] switch new_sync_{read,write}() to ITER_UBUF Al Viro
2022-06-07  4:13 ` [PATCH 9/9] iov_iter_bvec_advance(): don't bother with bvec_iter Al Viro
2022-06-08 19:28 ` [RFC][PATCHES] iov_iter stuff Sedat Dilek
2022-06-08 20:39   ` Al Viro
2022-06-09 19:10     ` Sedat Dilek
2022-06-09 19:22       ` Matthew Wilcox
2022-06-09 19:58         ` Matthew Wilcox
2022-06-09 19:45       ` Al Viro
2022-06-17 22:30 ` Jens Axboe
2022-06-17 22:48   ` Al Viro
2022-06-18  5:27     ` Al Viro
2022-06-18  5:35       ` [PATCH 01/31] splice: stop abusing iov_iter_advance() to flush a pipe Al Viro
2022-06-18  5:35         ` [PATCH 02/31] ITER_PIPE: helper for getting pipe buffer by index Al Viro
2022-06-18  5:35         ` [PATCH 03/31] ITER_PIPE: helpers for adding pipe buffers Al Viro
2022-06-18  5:35         ` [PATCH 04/31] ITER_PIPE: allocate buffers as we go in copy-to-pipe primitives Al Viro
2022-06-19  1:34           ` Al Viro
2022-06-18  5:35         ` [PATCH 05/31] ITER_PIPE: fold push_pipe() into __pipe_get_pages() Al Viro
2022-06-18  5:35         ` [PATCH 06/31] ITER_PIPE: lose iter_head argument of __pipe_get_pages() Al Viro
2022-06-18  5:35         ` [PATCH 07/31] ITER_PIPE: clean pipe_advance() up Al Viro
2022-06-18  5:35         ` [PATCH 08/31] ITER_PIPE: clean iov_iter_revert() Al Viro
2022-06-18  5:35         ` [PATCH 09/31] ITER_PIPE: cache the type of last buffer Al Viro
2022-06-18  5:35         ` [PATCH 10/10] iov_iter_bvec_advance(): don't bother with bvec_iter Al Viro
2022-06-18  5:35         ` [PATCH 10/31] ITER_PIPE: fold data_start() and pipe_space_for_user() together Al Viro
2022-06-19  2:25           ` Al Viro
2022-06-18  5:35         ` [PATCH 11/31] iov_iter_get_pages{,_alloc}(): cap the maxsize with LONG_MAX Al Viro
2022-06-18  5:35         ` [PATCH 12/31] iov_iter_get_pages_alloc(): lift freeing pages array on failure exits into wrapper Al Viro
2022-06-18  5:35         ` [PATCH 13/31] iov_iter_get_pages(): sanity-check arguments Al Viro
2022-06-19  3:07           ` Al Viro
2022-06-18  5:35         ` [PATCH 14/31] unify pipe_get_pages() and pipe_get_pages_alloc() Al Viro
2022-06-18  5:35         ` [PATCH 15/31] unify xarray_get_pages() and xarray_get_pages_alloc() Al Viro
2022-06-18  5:35         ` [PATCH 16/31] unify the rest of iov_iter_get_pages()/iov_iter_get_pages_alloc() guts Al Viro
2022-06-19  3:56           ` Al Viro
2022-06-18  5:35         ` [PATCH 17/31] ITER_XARRAY: don't open-code DIV_ROUND_UP() Al Viro
2022-06-18  5:35         ` [PATCH 18/31] iov_iter: lift dealing with maxpages out of first_{iovec,bvec}_segment() Al Viro
2022-06-18  5:35         ` [PATCH 19/31] iov_iter: massage calling conventions for first_{iovec,bvec}_segment() Al Viro
2022-06-18 11:13           ` Al Viro
2022-06-18 11:18             ` Al Viro
2022-06-18  5:35         ` [PATCH 20/31] found_iovec_segment(): just return address Al Viro
2022-06-18  5:35         ` [PATCH 21/31] fold __pipe_get_pages() into pipe_get_pages() Al Viro
2022-06-18  5:35         ` [PATCH 22/31] iov_iter: saner helper for page array allocation Al Viro
2022-06-18 11:14           ` Al Viro
2022-06-18  5:35         ` [PATCH 23/31] iov_iter: advancing variants of iov_iter_get_pages{,_alloc}() Al Viro
2022-06-18  5:35         ` [PATCH 24/31] block: convert to " Al Viro
2022-06-18  5:35         ` [PATCH 25/31] iter_to_pipe(): switch to advancing variant of iov_iter_get_pages() Al Viro
2022-06-18  5:35         ` [PATCH 26/31] af_alg_make_sg(): " Al Viro
2022-06-18  5:35         ` [PATCH 27/31] 9p: convert to advancing variant of iov_iter_get_pages_alloc() Al Viro
2022-06-18  5:35         ` [PATCH 28/31] ceph: switch the last caller " Al Viro
2022-06-18  5:35         ` [PATCH 29/31] get rid of non-advancing variants Al Viro
2022-06-18 11:14           ` Al Viro
2022-06-18  5:35         ` [PATCH 30/31] pipe_get_pages(): switch to append_pipe() Al Viro
2022-06-19  4:01           ` Al Viro
2022-06-19  4:09             ` Al Viro
2022-06-18  5:35         ` [PATCH 31/31] expand those iov_iter_advance() Al Viro
2022-06-18 11:14           ` Al Viro

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=20220607103450.qmkgtt2brbzvx4fu@quack3.lan \
    --to=jack@suse.cz \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.