Re: Subject: [BUG/RFC] write-open file THP cache purge can discard dirty page cache
From: Pedro Falcato
Date: Wed Jul 01 2026 - 10:33:12 EST
On Wed, Jul 01, 2026 at 09:07:44AM -0400, Gregg Leventhal wrote:
> Thanks all, it sounds like there is nothing for me to do quite yet, correct?
Correct.
> Also Zi Yan is correct, I meant order-0 folios.
>
> Please let me know if there is anything I can do.
> FWIW: The patch I suggested did seem to resolve the issue (based on my
> testing) and did prevent my reproducer from reproducing (whereas it
> repros ~instantly for me on a not patched kernel), but I (obviously)
> defer to you all here.
FWIW, yes, I think your patch approaches correctness, but there are subtle issues, like:
Thread 0 | Thread 1
do_dentry_open() | do_dentry_open()
FMODE_WRITE | FMODE_WRITE
nr_thps > 0 | /* the rest of the THP truncate logic */
write_and_wait |
| write(opened_file)
| /* we now have dirtied folios */
truncate() |
where the effective result depends on whether the invalidate lock
is held across filemap_write_and_wait() as well. But it will always,
as far as I can see, result in weird cases where writes can simply go
missing (truncate isn't really supposed to be called without the inode
lock, I think).
Matthew raised that, fundamentally, large-folio unaware filesystems should
not see these file THPs mixed in with dirty folios. Which is sensible and
seems to result in a simpler and easier to reason about fix overall.
--
Pedro