@@ -115,9 +115,34 @@ extern struct kobj_attribute shmem_enabled_attr;
115115
116116extern unsigned long transparent_hugepage_flags ;
117117
118+ static inline bool transhuge_vma_suitable (struct vm_area_struct * vma ,
119+ unsigned long haddr )
120+ {
121+ /* Don't have to check pgoff for anonymous vma */
122+ if (!vma_is_anonymous (vma )) {
123+ if (!IS_ALIGNED ((vma -> vm_start >> PAGE_SHIFT ) - vma -> vm_pgoff ,
124+ HPAGE_PMD_NR ))
125+ return false;
126+ }
127+
128+ if (haddr < vma -> vm_start || haddr + HPAGE_PMD_SIZE > vma -> vm_end )
129+ return false;
130+ return true;
131+ }
132+
133+ static inline bool transhuge_vma_enabled (struct vm_area_struct * vma ,
134+ unsigned long vm_flags )
135+ {
136+ /* Explicitly disabled through madvise. */
137+ if ((vm_flags & VM_NOHUGEPAGE ) ||
138+ test_bit (MMF_DISABLE_THP , & vma -> vm_mm -> flags ))
139+ return false;
140+ return true;
141+ }
142+
118143/*
119144 * to be used on vmas which are known to support THP.
120- * Use transparent_hugepage_enabled otherwise
145+ * Use transparent_hugepage_active otherwise
121146 */
122147static inline bool __transparent_hugepage_enabled (struct vm_area_struct * vma )
123148{
@@ -128,15 +153,12 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
128153 if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_NEVER_DAX ))
129154 return false;
130155
131- if (vma -> vm_flags & VM_NOHUGEPAGE )
156+ if (! transhuge_vma_enabled ( vma , vma -> vm_flags ) )
132157 return false;
133158
134159 if (vma_is_temporary_stack (vma ))
135160 return false;
136161
137- if (test_bit (MMF_DISABLE_THP , & vma -> vm_mm -> flags ))
138- return false;
139-
140162 if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_FLAG ))
141163 return true;
142164
@@ -150,22 +172,7 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
150172 return false;
151173}
152174
153- bool transparent_hugepage_enabled (struct vm_area_struct * vma );
154-
155- static inline bool transhuge_vma_suitable (struct vm_area_struct * vma ,
156- unsigned long haddr )
157- {
158- /* Don't have to check pgoff for anonymous vma */
159- if (!vma_is_anonymous (vma )) {
160- if (!IS_ALIGNED ((vma -> vm_start >> PAGE_SHIFT ) - vma -> vm_pgoff ,
161- HPAGE_PMD_NR ))
162- return false;
163- }
164-
165- if (haddr < vma -> vm_start || haddr + HPAGE_PMD_SIZE > vma -> vm_end )
166- return false;
167- return true;
168- }
175+ bool transparent_hugepage_active (struct vm_area_struct * vma );
169176
170177#define transparent_hugepage_use_zero_page () \
171178 (transparent_hugepage_flags & \
@@ -352,7 +359,7 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
352359 return false;
353360}
354361
355- static inline bool transparent_hugepage_enabled (struct vm_area_struct * vma )
362+ static inline bool transparent_hugepage_active (struct vm_area_struct * vma )
356363{
357364 return false;
358365}
@@ -363,6 +370,12 @@ static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
363370 return false;
364371}
365372
373+ static inline bool transhuge_vma_enabled (struct vm_area_struct * vma ,
374+ unsigned long vm_flags )
375+ {
376+ return false;
377+ }
378+
366379static inline void prep_transhuge_page (struct page * page ) {}
367380
368381static inline bool is_transparent_hugepage (struct page * page )
0 commit comments