Re: [PATCH v3] fuse: invalidate the page cache after direct write

From: Markus Elfring

Date: Sun Jan 11 2026 - 03:19:07 EST



> +++ 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);

> @@ -1160,10 +1174,26 @@ static ssize_t fuse_send_write(struct fuse_io_args *ia, loff_t pos,

- 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;


You may omit curly brackets at selected source code places.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.19-rc4#n197

Regards,
Markus