Re: [PATCH 7.2 v2 06/12] mm: fs: remove filemap_nr_thps*() functions and their users
From: Matthew Wilcox
Date: Mon Apr 13 2026 - 16:40:38 EST
On Mon, Apr 13, 2026 at 03:20:24PM -0400, Zi Yan wrote:
> They are used by READ_ONLY_THP_FOR_FS to handle writes to FSes without
> large folio support, so that read-only THPs created in these FSes are not
> seen by the FSes when the underlying fd becomes writable. Now read-only PMD
> THPs only appear in a FS with large folio support and the supported orders
> include PMD_ORDRE.
>
> READ_ONLY_THP_FOR_FS was using mapping->nr_thps, inode->i_writecount, and
> smp_mb() to prevent writes to a read-only THP and collapsing writable
> folios into a THP. In collapse_file(), mapping->nr_thps is increased, then
> smp_mb(), and if inode->i_writecount > 0, collapse is stopped, while
> do_dentry_open() first increases inode->i_writecount, then a full memory
> fence, and if mapping->nr_thps > 0, all read-only THPs are truncated.
>
> Now this mechanism can be removed along with READ_ONLY_THP_FOR_FS code,
> since a dirty folio check has been added after try_to_unmap() and
> try_to_unmap_flush() in collapse_file() to make sure no writable folio can
> be collapsed.
>
> Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
> ---
> fs/open.c | 27 ---------------------------
> include/linux/pagemap.h | 29 -----------------------------
> mm/filemap.c | 1 -
> mm/huge_memory.c | 1 -
> mm/khugepaged.c | 28 ----------------------------
> 5 files changed, 86 deletions(-)
This is great.
Reviewed-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>