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

From: Jingbo Xu

Date: Sun Jan 11 2026 - 02:29:22 EST




On 1/9/26 10:05 PM, Bernd Schubert wrote:
>
>
> On 1/9/26 08:01, Jingbo Xu wrote:
>> - return err ?: ia->write.out.size;
>> + /*
>> + * As in generic_file_direct_write(), invalidate after the write, to
>> + * invalidate read-ahead cache that may have competed with the write.
>> + * Without FOPEN_DIRECT_IO, generic_file_direct_write() does the
>> + * invalidation for synchronous write.
>> + */
>> + if (!err && written && mapping->nrpages &&
>> + ((ff->open_flags & FOPEN_DIRECT_IO) || !ia->io->blocking)) {
>> + invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT,
>> + (pos + written - 1) >> PAGE_SHIFT);
>> + }
>> +
>> + return err ?: written;
>> }
>
> Sorry, but I'm confused about "|| !ia->io->blocking". When we go into this
> code path it either via generic_file_direct_write(), which then
> already invalidates or directly and then
> (ff->open_flags & FOPEN_DIRECT_IO) is set?
>

Alright. I mistakenly thought that generic_file_direct_write() will skip
the invalidation for async write (without FOPEN_DIRECT_IO) when
fc->async_dio is false, as the ->direct_IO() will return -EIOCBQUEUED
for async write.

But in fact when fc->async_dio is false, fuse_direct_IO() will wait for
the IO completion and return the number of bytes written on success.
Thus generic_file_direct_write() will do the invalidation in this case.

I will drop "|| !ia->io->blocking" in v3 and add your "Reviewed-by" tag
then.

Thank you for the reviewing!

--
Thanks,
Jingbo