Re: [PATCH v6 13/14] mm/khugepaged: enable clean pagecache folio collapse for writable files

From: David Hildenbrand (Arm)

Date: Tue Jun 16 2026 - 08:49:13 EST


On 5/17/26 15:54, Zi Yan wrote:
> collapse_file() is capable of collapsing pagecache folios from writable
> files to PMD folios. Now enable clean pagecache folio collapse in
> addition to read-only pagecache folio collapse by removing the
> inode_is_open_for_write() from file_thp_enabled() and only performing
> filemap_flush() if the file is read-only.
>
> This means userspace needs to explicitly flush the content of pagecache
> folios before khugepaged can collapse the folios, or use
> madvise(MADV_COLLAPSE), which does the flush in the retry. The reason is
> that blindly enabling dirty pagecache folio from writable files collapse
> makes khugepaged flush these folios all the time. It is undesirable to
> cause system level pagecache flushes.
>
> To properly support dirty pagecache folio collapse, filemap_flush() needs
> to be avoided. Potentially, merging associated buffer instead of dropping
> it with filemap_release_folio() might be needed.
>
> NOTE: this breaks khugepaged selftests for writable file pagecache
> collapse, which is set to fail all the time. The next commit fixes it.
>
> Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
> Reviewed-by: Lance Yang <lance.yang@xxxxxxxxx>
> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
> Cc: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
> Cc: Barry Song <baohua@xxxxxxxxxx>
> Cc: Chris Mason <clm@xxxxxx>
> Cc: Christian Brauner <brauner@xxxxxxxxxx>
> Cc: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Cc: David Sterba <dsterba@xxxxxxxx>
> Cc: Dev Jain <dev.jain@xxxxxxx>
> Cc: Jan Kara <jack@xxxxxxx>
> Cc: Liam Howlett <liam@xxxxxxxxxxxxx>
> Cc: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> Cc: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
> Cc: Michal Hocko <mhocko@xxxxxxxx>
> Cc: Mike Rapoport <rppt@xxxxxxxxxx>
> Cc: Nico Pache <npache@xxxxxxxxxx>
> Cc: Ryan Roberts <ryan.roberts@xxxxxxx>
> Cc: Shuah Khan <shuah@xxxxxxxxxx>
> Cc: Song Liu <songliubraving@xxxxxx>
> Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx>
> Cc: Vlastimil Babka <vbabka@xxxxxxxxxx>

Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

--
Cheers,

David