Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1423987

Re: [PATCHv9-rebased2 05/37] khugepaged: recheck pmd after mmap_sem re-acquired

From "Kirill A. Shutemov" <kirill@shutemov.name>
Newsgroups linux.kernel
Subject Re: [PATCHv9-rebased2 05/37] khugepaged: recheck pmd after mmap_sem re-acquired
Date 2016-06-16 14:00 +0200
Message-ID <rKE7M-7Uc-17@gated-at.bofh.it> (permalink)
References <rH3o5-5Yv-3@gated-at.bofh.it> <rKpip-74l-3@gated-at.bofh.it> <rKps5-77R-7@gated-at.bofh.it> <rKDY5-7QS-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Jun 16, 2016 at 02:47:14PM +0300, Ebru Akagunduz wrote:
> On Wed, Jun 15, 2016 at 11:06:10PM +0300, Kirill A. Shutemov wrote:
> > Vlastimil noted[1] that pmd can be no longer valid after we drop
> > mmap_sem. We need recheck it once mmap_sem taken again.
> > 
> > [1] http://lkml.kernel.org/r/12918dcd-a695-c6f4-e06f-69141c5f357f@suse.cz
> > 
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > ---
> >  mm/huge_memory.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index d7ccc8558187..0efdad975659 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -2437,6 +2437,9 @@ static bool __collapse_huge_page_swapin(struct mm_struct *mm,
> >  			/* vma is no longer available, don't continue to swapin */
> >  			if (hugepage_vma_revalidate(mm, address))
> >  				return false;
> > +			/* check if the pmd is still valid */
> > +			if (mm_find_pmd(mm, address) != pmd)
> > +				return false;
> >  		}
> Thanks for fixing this.
> 
> >  		if (ret & VM_FAULT_ERROR) {
> >  			trace_mm_collapse_huge_page_swapin(mm, swapped_in, 0);
> > @@ -2522,6 +2525,9 @@ static void collapse_huge_page(struct mm_struct *mm,
> >  	result = hugepage_vma_revalidate(mm, address);
> >  	if (result)
> >  		goto out;
> > +	/* check if the pmd is still valid */
> > +	if (mm_find_pmd(mm, address) != pmd)
> > +		goto out;
> >  
> However here, I don't know do we need to check pmd.
> Because in collapse_huge_page; pmd is newly created,
> after taking mmap_sem read:
> {
> 
> 	pmd_t *pmd, _pmd;
>         pte_t *pte;
>         ...
>         down_read(&mm->mmap_sem);
>         result = hugepage_vma_revalidate(mm, address);
>         ...
>         pmd = mm_find_pmd(mm, address);
>         ...
> 
> Therefore it did not seem like a problem for me.

I guess you're looking on the first hugepage_vma_revalidate() in
collapse_huge_page(). The patch fixes issue after the second one:

	pmd_t *pmd, _pmd;
        pte_t *pte;
        ...
        down_read(&mm->mmap_sem);
        result = hugepage_vma_revalidate(mm, address);
        ...
        pmd = mm_find_pmd(mm, address);
        ...
	up_read(&mm->mmap_sem);
	...
	down_write(&mm->mmap_sem);
	result = hugepage_vma_revalidate(mm, address);
	if (mm_find_pmd(mm, address) != pmd)
		 goto out;


-- 
 Kirill A. Shutemov

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHv9-rebased2 00/37] THP-enabled tmpfs/shmem using compound pages "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 05/37] khugepaged: recheck pmd after mmap_sem re-acquired "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
    Re: [PATCHv9-rebased2 05/37] khugepaged: recheck pmd after mmap_sem  re-acquired Ebru Akagunduz <ebru.akagunduz@gmail.com> - 2016-06-16 13:50 +0200
      Re: [PATCHv9-rebased2 05/37] khugepaged: recheck pmd after mmap_sem  re-acquired "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-06-16 14:00 +0200
  [PATCHv9-rebased2 12/37] thp, vmstats: add counters for huge file pages "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 17/37] thp: prepare change_huge_pmd() for file thp "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 09/37] mm: postpone page table allocation until we have page to map "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 18/37] thp: run vma_adjust_trans_huge() outside i_mmap_rwsem "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 21/37] vmscan: split file huge pages before paging them out "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 13/37] thp: support file pages in zap_huge_pmd() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 29/37] shmem: add huge pages support "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 06/37] thp, mlock: update unevictable-lru.txt "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 19/37] thp: file pages support for split_huge_page() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 28/37] shmem: get_unmapped_area align huge page "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 07/37] mm: do not pass mm_struct into handle_mm_fault "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 34/37] khugepaged: add support of collapse for tmpfs/shmem pages "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 14/37] thp: handle file pages in split_huge_pmd() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 11/37] mm: introduce do_set_pmd() "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 26/37] mm, rmap: account shmem thp pages "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 25/37] truncate: handle file thp "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 24/37] filemap: prepare find and delete operations for huge pages "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 22/37] page-flags: relax policy for PG_mappedtodisk and PG_reclaim "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 27/37] shmem: prepare huge= mount option and sysfs knob "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 10/37] rmap: support file thp "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:20 +0200
  [PATCHv9-rebased2 04/37]  mm-thp-make-swapin-readahead-under-down_read-of-mmap_sem-fix-2-fix "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> - 2016-06-15 22:30 +0200

csiph-web