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.
Unified · Split
| @@ -173,6 +173,20 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) · 172 unmodified lines | ||
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 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 | + | |
| 176 | 190 | bool transparent_hugepage_active(struct vm_area_struct *vma); |
| 177 | 191 | |
| 178 | 192 | #define transparent_hugepage_use_zero_page() \ |
| @@ -69,13 +69,6 @@ static atomic_t huge_zero_refcount; · 68 unmodified lines | ||
| 69 | 69 | struct page *huge_zero_page __read_mostly; |
| 70 | 70 | unsigned long huge_zero_pfn __read_mostly = ~0UL; |
| 71 | 71 | |
| 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 | − | |
| 79 | 72 | bool transparent_hugepage_active(struct vm_area_struct *vma) |
| 80 | 73 | { |
| 81 | 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 | 80 | return __transparent_hugepage_enabled(vma); |
| 88 | 81 | if (vma_is_shmem(vma)) |
| 89 | 82 | 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; | |
| 92 | 85 | |
| 93 | 86 | return false; |
| 94 | 87 | } |
| @@ -464,13 +464,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, · 463 unmodified lines | ||
| 464 | 464 | return false; |
| 465 | 465 | |
| 466 | 466 | /* 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; | |
| 474 | 469 | |
| 475 | 470 | if (!vma->anon_vma || !vma_is_anonymous(vma)) |
| 476 | 471 | return false; |