History

mm: thp: only regular file could be THP eligible

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.

Yang Shi committed 4 years ago

Commit 78d12c11 parent 52b52bf3 files · +18 −16Browse files

Unified · Split

3 files
  1. include/linux/huge_mm.h +14 −0
  2. mm/huge_memory.c +2 −9
  3. mm/khugepaged.c +2 −7
include/linux/huge_mm.h+14−0
@@ -173,6 +173,20 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) · 172 unmodified lines
173173 return false;
174174 }
175175
176+static inline bool file_thp_enabled(struct vm_area_struct *vma)
177+{
178+ struct inode *inode;
179+
180+ if (!vma->vm_file)
181+ return false;
182+
183+ inode = vma->vm_file->f_inode;
184+
185+ return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) &&
186+ (vma->vm_flags & VM_EXEC) &&
187+ !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
188+}
189+
176190 bool transparent_hugepage_active(struct vm_area_struct *vma);
177191
178192 #define transparent_hugepage_use_zero_page() \
mm/huge_memory.c+2−9
@@ -69,13 +69,6 @@ static atomic_t huge_zero_refcount; · 68 unmodified lines
6969 struct page *huge_zero_page __read_mostly;
7070 unsigned long huge_zero_pfn __read_mostly = ~0UL;
7171
72−static inline bool file_thp_enabled(struct vm_area_struct *vma)
73−{
74− return transhuge_vma_enabled(vma, vma->vm_flags) && vma->vm_file &&
75− !inode_is_open_for_write(vma->vm_file->f_inode) &&
76− (vma->vm_flags & VM_EXEC);
77−}
78−
7972 bool transparent_hugepage_active(struct vm_area_struct *vma)
8073 {
8174 /* The addr is used to check if the vma size fits */
@@ -87,8 +80,8 @@ bool transparent_hugepage_active(struct vm_area_struct *vma) · 5 unmodified lines
8780 return __transparent_hugepage_enabled(vma);
8881 if (vma_is_shmem(vma))
8982 return shmem_huge_enabled(vma);
90− if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS))
91− return file_thp_enabled(vma);
83+ if (transhuge_vma_enabled(vma, vma->vm_flags) && file_thp_enabled(vma))
84+ return true;
9285
9386 return false;
9487 }
mm/khugepaged.c+2−7
@@ -464,13 +464,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, · 463 unmodified lines
464464 return false;
465465
466466 /* Only regular file is valid */
467− if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file &&
468− (vm_flags & VM_EXEC)) {
469− struct inode *inode = vma->vm_file->f_inode;
470−
471− return !inode_is_open_for_write(inode) &&
472− S_ISREG(inode->i_mode);
473− }
467+ if (file_thp_enabled(vma))
468+ return true;
474469
475470 if (!vma->anon_vma || !vma_is_anonymous(vma))
476471 return false;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t