mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Bernd Schubert <bschubert@ddn.com>
Subject: Re: [PATCH v3] fuse: invalidate the page cache after direct write
Date: Tue, 24 Feb 2026 16:30:12 +0800	[thread overview]
Message-ID: <5a612ef9-0de6-43a2-a84c-eb8776235eef@linux.alibaba.com> (raw)
In-Reply-To: <20260111073701.6071-1-jefflexu@linux.alibaba.com>

gentle ping

On 1/11/26 3:37 PM, Jingbo Xu wrote:
> This fixes xfstests generic/451 (for both O_DIRECT and FOPEN_DIRECT_IO
> direct write).
> 
> Commit b359af8275a9 ("fuse: Invalidate the page cache after
> FOPEN_DIRECT_IO write") tries to fix the similar issue for
> FOPEN_DIRECT_IO write, which can be reproduced by xfstests generic/209.
> It only fixes the issue for synchronous direct write, while omitting
> the case for asynchronous direct write (exactly targeted by
> generic/451).
> 
> While for O_DIRECT direct write, it's somewhat more complicated.  For
> synchronous direct write, generic_file_direct_write() will invalidate
> the page cache after the write, and thus it can pass generic/209.  While
> for asynchronous direct write, the invalidation in
> generic_file_direct_write() is bypassed since the invalidation shall be
> done when the asynchronous IO completes.  This is omitted in FUSE and
> generic/451 fails whereby.
> 
> Fix this by conveying the invalidation for both synchronous and
> asynchronous write.
> 
> - with FOPEN_DIRECT_IO
>   - sync write,  invalidate in fuse_send_write()
>   - async write, invalidate in fuse_aio_complete() with FUSE_ASYNC_DIO,
> 		 fuse_send_write() otherwise
> - without FOPEN_DIRECT_IO
>   - sync write,  invalidate in generic_file_direct_write()
>   - async write, invalidate in fuse_aio_complete() with FUSE_ASYNC_DIO,
> 		 generic_file_direct_write() otherwise
> 
> Reviewed-by: Bernd Schubert <bschubert@ddn.com>
> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
> ---
> changes:
> - drop "|| !ia->io->blocking" in fuse_send_write() (Bernd)
> ---
>  fs/fuse/file.c | 43 ++++++++++++++++++++++++++++++++-----------
>  1 file changed, 32 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index 01bc894e9c2b..625d236b881b 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -667,6 +667,18 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos)
>  			struct inode *inode = file_inode(io->iocb->ki_filp);
>  			struct fuse_conn *fc = get_fuse_conn(inode);
>  			struct fuse_inode *fi = get_fuse_inode(inode);
> +			struct address_space *mapping = io->iocb->ki_filp->f_mapping;
> +
> +			/*
> +			 * As in generic_file_direct_write(), invalidate after the
> +			 * write, to invalidate read-ahead cache that may have competed
> +			 * with the write.
> +			 */
> +			if (io->write && res && mapping->nrpages) {
> +				invalidate_inode_pages2_range(mapping,
> +						io->offset >> PAGE_SHIFT,
> +						(io->offset + res - 1) >> PAGE_SHIFT);
> +			}
>  
>  			spin_lock(&fi->lock);
>  			fi->attr_version = atomic64_inc_return(&fc->attr_version);
> @@ -1144,9 +1156,11 @@ static ssize_t fuse_send_write(struct fuse_io_args *ia, loff_t pos,
>  {
>  	struct kiocb *iocb = ia->io->iocb;
>  	struct file *file = iocb->ki_filp;
> +	struct address_space *mapping = file->f_mapping;
>  	struct fuse_file *ff = file->private_data;
>  	struct fuse_mount *fm = ff->fm;
>  	struct fuse_write_in *inarg = &ia->write.in;
> +	ssize_t written;
>  	ssize_t err;
>  
>  	fuse_write_args_fill(ia, ff, pos, count);
> @@ -1160,10 +1174,26 @@ static ssize_t fuse_send_write(struct fuse_io_args *ia, loff_t pos,
>  		return fuse_async_req_send(fm, ia, count);
>  
>  	err = fuse_simple_request(fm, &ia->ap.args);
> -	if (!err && ia->write.out.size > count)
> +	written = ia->write.out.size;
> +	if (!err && written > count)
>  		err = -EIO;
>  
> -	return err ?: ia->write.out.size;
> +	/*
> +	 * Without FOPEN_DIRECT_IO, generic_file_direct_write() does the
> +	 * invalidation for us.
> +	 */
> +	if (!err && written && mapping->nrpages &&
> +	    (ff->open_flags & FOPEN_DIRECT_IO)) {
> +		/*
> +		 * As in generic_file_direct_write(), invalidate after the
> +		 * write, to invalidate read-ahead cache that may have competed
> +		 * with the write.
> +		 */
> +		invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT,
> +					(pos + written - 1) >> PAGE_SHIFT);
> +	}
> +
> +	return err ?: written;
>  }
>  
>  bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written)
> @@ -1738,15 +1768,6 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
>  	if (res > 0)
>  		*ppos = pos;
>  
> -	if (res > 0 && write && fopen_direct_io) {
> -		/*
> -		 * As in generic_file_direct_write(), invalidate after the
> -		 * write, to invalidate read-ahead cache that may have competed
> -		 * with the write.
> -		 */
> -		invalidate_inode_pages2_range(mapping, idx_from, idx_to);
> -	}
> -
>  	return res > 0 ? res : err;
>  }
>  EXPORT_SYMBOL_GPL(fuse_direct_io);

-- 
Thanks,
Jingbo


  parent reply	other threads:[~2026-02-24  8:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11  7:37 Jingbo Xu
2026-01-11  8:18 ` Markus Elfring
2026-01-11  9:43   ` Bernd Schubert
2026-01-12  5:37   ` Jingbo Xu
2026-02-24  8:30 ` Jingbo Xu [this message]
2026-02-27 15:09 ` Miklos Szeredi
2026-03-02 19:29   ` Bernd Schubert
2026-03-02 21:19     ` Bernd Schubert
2026-03-02 21:28       ` Miklos Szeredi
2026-03-03  2:56       ` Jingbo Xu
2026-03-03  6:47       ` Jingbo Xu

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=5a612ef9-0de6-43a2-a84c-eb8776235eef@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=bschubert@ddn.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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

all inboxes | Powered by JetHome®