Skip to content

Commit

Permalink
mm: thp: only regular file could be THP eligible
Browse files Browse the repository at this point in the history
Since commit a4aeaa0 ("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/[email protected]
Signed-off-by: Yang Shi <[email protected]>
Acked-by: Song Liu <[email protected]>
Acked-by: Vlastmil Babka <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: Miaohe Lin <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Theodore Ts'o <[email protected]>
Cc: Zi Yan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
yang-shi authored and akpm00 committed May 19, 2022
1 parent 52b52bf commit 78d12c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
14 changes: 14 additions & 0 deletions include/linux/huge_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() \
Expand Down
11 changes: 2 additions & 9 deletions mm/huge_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down
9 changes: 2 additions & 7 deletions mm/khugepaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_is_anonymous(vma))
return false;
Expand Down

0 comments on commit 78d12c1

Please sign in to comment.