Commit c453d8c7 authored by Yang Shi's avatar Yang Shi Committed by akpm

mm/page_vma_mapped.c: check possible huge PMD map with transhuge_vma_suitable()

IIUC page_vma_mapped_walk() checks if the vma is possibly huge PMD mapped
with transparent_hugepage_active() and "pvmw->nr_pages >= HPAGE_PMD_NR".

Actually pvmw->nr_pages is returned by compound_nr() or folio_nr_pages(),
so the page should be THP as long as "pvmw->nr_pages >= HPAGE_PMD_NR". 
And it is guaranteed THP is allocated for valid VMA in the first place. 
But it may be not PMD mapped if the VMA is file VMA and it is not properly
aligned.  The transhuge_vma_suitable() is used to do such check, so
replace transparent_hugepage_active() to it, which is too heavy and
overkilling.

Link: https://lkml.kernel.org/r/20220513191705.457775-1-shy828301@gmail.comSigned-off-by: default avatarYang Shi <shy828301@gmail.com>
Reviewed-by: default avatarMuchun Song <songmuchun@bytedance.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 507db792
...@@ -117,8 +117,10 @@ extern struct kobj_attribute shmem_enabled_attr; ...@@ -117,8 +117,10 @@ extern struct kobj_attribute shmem_enabled_attr;
extern unsigned long transparent_hugepage_flags; extern unsigned long transparent_hugepage_flags;
static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
unsigned long haddr) unsigned long addr)
{ {
unsigned long haddr;
/* Don't have to check pgoff for anonymous vma */ /* Don't have to check pgoff for anonymous vma */
if (!vma_is_anonymous(vma)) { if (!vma_is_anonymous(vma)) {
if (!IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, if (!IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff,
...@@ -126,6 +128,8 @@ static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, ...@@ -126,6 +128,8 @@ static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
return false; return false;
} }
haddr = addr & HPAGE_PMD_MASK;
if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end)
return false; return false;
return true; return true;
...@@ -342,7 +346,7 @@ static inline bool transparent_hugepage_active(struct vm_area_struct *vma) ...@@ -342,7 +346,7 @@ static inline bool transparent_hugepage_active(struct vm_area_struct *vma)
} }
static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
unsigned long haddr) unsigned long addr)
{ {
return false; return false;
} }
......
...@@ -243,7 +243,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) ...@@ -243,7 +243,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
* cleared *pmd but not decremented compound_mapcount(). * cleared *pmd but not decremented compound_mapcount().
*/ */
if ((pvmw->flags & PVMW_SYNC) && if ((pvmw->flags & PVMW_SYNC) &&
transparent_hugepage_active(vma) && transhuge_vma_suitable(vma, pvmw->address) &&
(pvmw->nr_pages >= HPAGE_PMD_NR)) { (pvmw->nr_pages >= HPAGE_PMD_NR)) {
spinlock_t *ptl = pmd_lock(mm, pvmw->pmd); spinlock_t *ptl = pmd_lock(mm, pvmw->pmd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment