On Tue 21-08-18 18:10:42, Mike Kravetz wrote: [...] > diff --git a/mm/rmap.c b/mm/rmap.c > index eb477809a5c0..8cf853a4b093 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1362,11 +1362,21 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, > } > > /* > - * We have to assume the worse case ie pmd for invalidation. Note that > - * the page can not be free in this function as call of try_to_unmap() > - * must hold a reference on the page. > + * For THP, we have to assume the worse case ie pmd for invalidation. > + * For hugetlb, it could be much worse if we need to do pud > + * invalidation in the case of pmd sharing. > + * > + * Note that the page can not be free in this function as call of > + * try_to_unmap() must hold a reference on the page. > */ > end = min(vma->vm_end, start + (PAGE_SIZE << compound_order(page))); > + if (PageHuge(page)) { > + /* > + * If sharing is possible, start and end will be adjusted > + * accordingly. > + */ > + (void)huge_pmd_sharing_possible(vma, &start, &end); > + } > mmu_notifier_invalidate_range_start(vma->vm_mm, start, end); I do not get this part. Why don't we simply unconditionally invalidate the whole huge page range? > > while (page_vma_mapped_walk(&pvmw)) { > @@ -1409,6 +1419,32 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, > subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte); > address = pvmw.address; > > + if (PageHuge(page)) { > + if (huge_pmd_unshare(mm, &address, pvmw.pte)) { huge_pmd_unshare is documented to require a pte lock. Where do we take it? -- Michal Hocko SUSE Labs