Re: Subject: [BUG/RFC] write-open file THP cache purge can discard dirty page cache
From: Matthew Wilcox
Date: Tue Jun 30 2026 - 15:07:29 EST
On Tue, Jun 30, 2026 at 03:05:16PM -0400, Zi Yan wrote:
> On Tue Jun 30, 2026 at 2:36 PM EDT, Matthew Wilcox wrote:
> > On Tue, Jun 30, 2026 at 01:01:53PM -0400, Gregg Leventhal wrote:
> >> On an affected 6.12 kernel with CONFIG_READ_ONLY_THP_FOR_FS=y, a file can
> >> contain read-only file THPs installed by khugepaged / MADV_COLLAPSE. When that
> >> same file is later opened for write, do_dentry_open() notices
> >> filemap_nr_thps() and drops the page cache:
> > [...]
> >>
> >> This is unsafe if the mapping also contains dirty folios.
> >
> > But there shouldn't be any. It should not be possible to have
> > dirty folios and THPs in the same file unless the filesystem
> > supports large folios natively.
> >
> > If the file is open for writing, the attempt to create THPs should fail.
>
> Maybe he means order-0 dirty folios?
Even then. They're all supposed to be gone. I don't want to guarantee
that the filesystem will properly skip over clean folios during
writeback.