From: Zi Yan Date: Sun, 17 May 2026 13:54:05 +0000 (-0400) Subject: mm/huge_memory: remove READ_ONLY_THP_FOR_FS from file_thp_enabled() X-Git-Tag: v7.2-rc1~59^2~95 X-Git-Url: http://git.ipfire.org/index.cgi?a=commitdiff_plain;h=8a088263a097d567c212159d3a7bc747348e31fd;p=thirdparty%2Flinux.git mm/huge_memory: remove READ_ONLY_THP_FOR_FS from file_thp_enabled() Replace it with a check on the max folio order of the file's address space mapping, making sure PMD folio is supported. Keep the inode open-for-write check, since even if collapse_file() now makes sure all to-be-collapsed folios are clean and the created PMD file THP can be handled by FSes properly, the filemap_flush() could perform undesirable write back. Link: https://lore.kernel.org/20260517135416.1434539-4-ziy@nvidia.com Signed-off-by: Zi Yan Acked-by: David Hildenbrand (Arm) Reviewed-by: Lance Yang Reviewed-by: Nico Pache Cc: Al Viro Cc: Baolin Wang Cc: Barry Song Cc: Chris Mason Cc: Christian Brauner Cc: David Sterba Cc: Dev Jain Cc: Jan Kara Cc: Liam Howlett Cc: Lorenzo Stoakes Cc: Matthew Wilcox (Oracle) Cc: Michal Hocko Cc: Mike Rapoport Cc: Ryan Roberts Cc: Shuah Khan Cc: Song Liu Cc: Suren Baghdasaryan Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- diff --git a/mm/huge_memory.c b/mm/huge_memory.c index b4062396ce877..8808eb56ef0e3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -89,9 +89,6 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma) { struct inode *inode; - if (!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) - return false; - if (!vma->vm_file) return false; @@ -100,6 +97,9 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma) if (IS_ANON_FILE(inode)) return false; + if (!mapping_pmd_folio_support(vma->vm_file->f_mapping)) + return false; + return !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode); }