mm: thp: kill __transhuge_page_enabled()

The page fault path checks THP eligibility with __transhuge_page_enabled()
which does the similar thing as hugepage_vma_check(), so use
hugepage_vma_check() instead.

However page fault allows DAX and !anon_vma cases, so added a new flag,
in_pf, to hugepage_vma_check() to make page fault work correctly.

The in_pf flag is also used to skip shmem and file THP for page fault
since shmem handles THP in its own shmem_fault() and file THP allocation
on fault is not supported yet.

Also remove hugepage_vma_enabled() since hugepage_vma_check() is the only
caller now, it is not necessary to have a helper function.

Link: https://lkml.kernel.org/r/20220616174840.1202070-6-shy828301@gmail.com
Signed-off-by: Yang Shi <shy828301@gmail.com>
Reviewed-by: Zach O'Keefe <zokeefe@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Yang Shi 2022-06-16 10:48:38 -07:00 committed by akpm
parent 9fec51689f
commit 7da4e2cb8b
5 changed files with 53 additions and 74 deletions

View file

@ -146,48 +146,6 @@ static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
return true;
}
static inline bool transhuge_vma_enabled(struct vm_area_struct *vma,
unsigned long vm_flags)
{
/* Explicitly disabled through madvise. */
if ((vm_flags & VM_NOHUGEPAGE) ||
test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))
return false;
return true;
}
/*
* to be used on vmas which are known to support THP.
* Use transparent_hugepage_active otherwise
*/
static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
{
/*
* If the hardware/firmware marked hugepage support disabled.
*/
if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_NEVER_DAX))
return false;
if (!transhuge_vma_enabled(vma, vma->vm_flags))
return false;
if (vma_is_temporary_stack(vma))
return false;
if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_FLAG))
return true;
if (vma_is_dax(vma))
return true;
if (transparent_hugepage_flags &
(1 << TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG))
return !!(vma->vm_flags & VM_HUGEPAGE);
return false;
}
static inline bool file_thp_enabled(struct vm_area_struct *vma)
{
struct inode *inode;
@ -204,7 +162,7 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma)
bool hugepage_vma_check(struct vm_area_struct *vma,
unsigned long vm_flags,
bool smaps);
bool smaps, bool in_pf);
#define transparent_hugepage_use_zero_page() \
(transparent_hugepage_flags & \
@ -348,26 +306,15 @@ static inline bool folio_test_pmd_mappable(struct folio *folio)
return false;
}
static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma)
{
return false;
}
static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
unsigned long addr)
{
return false;
}
static inline bool transhuge_vma_enabled(struct vm_area_struct *vma,
unsigned long vm_flags)
{
return false;
}
static inline bool hugepage_vma_check(struct vm_area_struct *vma,
unsigned long vm_flags,
bool smaps)
bool smaps, bool in_pf)
{
return false;
}