]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: thp: only regular file could be THP eligible
authorYang Shi <shy828301@gmail.com>
Thu, 14 Apr 2022 19:16:45 +0000 (12:16 -0700)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 14 Apr 2022 21:49:50 +0000 (17:49 -0400)
Since commit a4aeaa06d45e ("mm: khugepaged: skip huge page collapse for
special files"), khugepaged just collapses THP for regular file which is
the intended usecase for readonly fs THP.  Only show regular file as THP
eligible accordingly.

And make file_thp_enabled() available for khugepaged too in order to
remove duplicate code.

Link: https://lkml.kernel.org/r/20220404200250.321455-5-shy828301@gmail.com
Signed-off-by: Yang Shi <shy828301@gmail.com>
Acked-by: Song Liu <song@kernel.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/huge_mm.h
mm/huge_memory.c
mm/khugepaged.c

index 9a26bd10e083bc38c500567f853d7dac578840a4..816a9937f30e294131ed17792bb39d6ff25f1b29 100644 (file)
@@ -173,6 +173,20 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
        return false;
 }
 
+static inline bool file_thp_enabled(struct vm_area_struct *vma)
+{
+       struct inode *inode;
+
+       if (!vma->vm_file)
+               return false;
+
+       inode = vma->vm_file->f_inode;
+
+       return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) &&
+              (vma->vm_flags & VM_EXEC) &&
+              !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
+}
+
 bool transparent_hugepage_active(struct vm_area_struct *vma);
 
 #define transparent_hugepage_use_zero_page()                           \
index 6ca56eb756810686e728d8983f6deae5d293c513..8103b518b46e5a3987b7b5e5c914c138bacdf4c6 100644 (file)
@@ -69,13 +69,6 @@ static atomic_t huge_zero_refcount;
 struct page *huge_zero_page __read_mostly;
 unsigned long huge_zero_pfn __read_mostly = ~0UL;
 
-static inline bool file_thp_enabled(struct vm_area_struct *vma)
-{
-       return transhuge_vma_enabled(vma, vma->vm_flags) && vma->vm_file &&
-              !inode_is_open_for_write(vma->vm_file->f_inode) &&
-              (vma->vm_flags & VM_EXEC);
-}
-
 bool transparent_hugepage_active(struct vm_area_struct *vma)
 {
        /* The addr is used to check if the vma size fits */
@@ -87,8 +80,8 @@ bool transparent_hugepage_active(struct vm_area_struct *vma)
                return __transparent_hugepage_enabled(vma);
        if (vma_is_shmem(vma))
                return shmem_huge_enabled(vma);
-       if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS))
-               return file_thp_enabled(vma);
+       if (transhuge_vma_enabled(vma, vma->vm_flags) && file_thp_enabled(vma))
+               return true;
 
        return false;
 }
index 5693489cbfb10e2028079cfbaf48361f49c09c31..c41587d5b9121470c0229cb68fd12157d786b472 100644 (file)
@@ -464,13 +464,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma,
                return false;
 
        /* Only regular file is valid */
-       if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file &&
-           (vm_flags & VM_EXEC)) {
-               struct inode *inode = vma->vm_file->f_inode;
-
-               return !inode_is_open_for_write(inode) &&
-                       S_ISREG(inode->i_mode);
-       }
+       if (file_thp_enabled(vma))
+               return true;
 
        if (!vma->anon_vma || vma->vm_ops)
                return false;