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
173 return false;173 return false;
174}174}
175 175
176static 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
176bool transparent_hugepage_active(struct vm_area_struct *vma);190bool transparent_hugepage_active(struct vm_area_struct *vma);
177 191
178#define transparent_hugepage_use_zero_page() \192#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
69struct page *huge_zero_page __read_mostly;69struct page *huge_zero_page __read_mostly;
70unsigned long huge_zero_pfn __read_mostly = ~0UL;70unsigned long huge_zero_pfn __read_mostly = ~0UL;
71 71
72static 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
79bool transparent_hugepage_active(struct vm_area_struct *vma)72bool transparent_hugepage_active(struct vm_area_struct *vma)
80{73{
81 /* The addr is used to check if the vma size fits */74 /* 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
87 return __transparent_hugepage_enabled(vma);80 return __transparent_hugepage_enabled(vma);
88 if (vma_is_shmem(vma))81 if (vma_is_shmem(vma))
89 return shmem_huge_enabled(vma);82 return shmem_huge_enabled(vma);
90 if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS))83 if (transhuge_vma_enabled(vma, vma->vm_flags) && file_thp_enabled(vma))
91 return file_thp_enabled(vma);84 return true;
92 85
93 return false;86 return false;
94}87}
mm/khugepaged.c+2−7
@@ -464,13 +464,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, · 463 unmodified lines
464 return false;464 return false;
465 465
466 /* Only regular file is valid */466 /* Only regular file is valid */
467 if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file &&467 if (file_thp_enabled(vma))
468 (vm_flags & VM_EXEC)) {468 return true;
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 }
474 469
475 if (!vma->anon_vma || !vma_is_anonymous(vma))470 if (!vma->anon_vma || !vma_is_anonymous(vma))
476 return false;471 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