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


Groups > linux.kernel > #1525696

Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for use with device memory

From Jerome Glisse <jglisse@redhat.com>
Newsgroups linux.kernel
Subject Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for use with device memory
Date 2016-11-18 21:20 +0100
Message-ID <sEXND-3s3-7@gated-at.bofh.it> (permalink)
References <sEUZr-1B7-3@gated-at.bofh.it> <sEUZs-1B7-23@gated-at.bofh.it> <sEXuh-32H-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat, Nov 19, 2016 at 01:27:28AM +0530, Aneesh Kumar K.V wrote:
> Jérôme Glisse <jglisse@redhat.com> writes:
>  
>
> [...]
>
> >+
> > +static int hmm_collect_walk_pmd(pmd_t *pmdp,
> > +				unsigned long start,
> > +				unsigned long end,
> > +				struct mm_walk *walk)
> > +{
> > +	struct hmm_migrate *migrate = walk->private;
> > +	struct mm_struct *mm = walk->vma->vm_mm;
> > +	unsigned long addr = start;
> > +	spinlock_t *ptl;
> > +	hmm_pfn_t *pfns;
> > +	int pages = 0;
> > +	pte_t *ptep;
> > +
> > +again:
> > +	if (pmd_none(*pmdp))
> > +		return 0;
> > +
> > +	split_huge_pmd(walk->vma, pmdp, addr);
> > +	if (pmd_trans_unstable(pmdp))
> > +		goto again;
> > +
> > +	pfns = &migrate->pfns[(addr - migrate->start) >> PAGE_SHIFT];
> > +	ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl);
> > +	arch_enter_lazy_mmu_mode();
> > +
> > +	for (; addr < end; addr += PAGE_SIZE, pfns++, ptep++) {
> > +		unsigned long pfn;
> > +		swp_entry_t entry;
> > +		struct page *page;
> > +		hmm_pfn_t flags;
> > +		bool write;
> > +		pte_t pte;
> > +
> > +		pte = ptep_get_and_clear(mm, addr, ptep);
> > +		if (!pte_present(pte)) {
> > +			if (pte_none(pte))
> > +				continue;
> > +
> > +			entry = pte_to_swp_entry(pte);
> > +			if (!is_device_entry(entry)) {
> > +				set_pte_at(mm, addr, ptep, pte);
> > +				continue;
> > +			}
> > +
> > +			flags = HMM_PFN_DEVICE | HMM_PFN_UNADDRESSABLE;
> > +			page = device_entry_to_page(entry);
> > +			write = is_write_device_entry(entry);
> > +			pfn = page_to_pfn(page);
> > +
> > +			if (!(page->pgmap->flags & MEMORY_MOVABLE)) {
> > +				set_pte_at(mm, addr, ptep, pte);
> > +				continue;
> > +			}
> > +
> > +		} else {
> > +			pfn = pte_pfn(pte);
> > +			page = pfn_to_page(pfn);
> > +			write = pte_write(pte);
> > +			flags = is_zone_device_page(page) ? HMM_PFN_DEVICE : 0;
> > +		}
> > +
> > +		/* FIXME support THP see hmm_migrate_page_check() */
> > +		if (PageTransCompound(page))
> > +			continue;
> > +
> > +		*pfns = hmm_pfn_from_pfn(pfn) | HMM_PFN_MIGRATE | flags;
> > +		*pfns |= write ? HMM_PFN_WRITE : 0;
> > +		migrate->npages++;
> > +		get_page(page);
> > +
> > +		if (!trylock_page(page)) {
> > +			set_pte_at(mm, addr, ptep, pte);
> > +		} else {
> > +			pte_t swp_pte;
> > +
> > +			*pfns |= HMM_PFN_LOCKED;
> > +
> > +			entry = make_migration_entry(page, write);
> > +			swp_pte = swp_entry_to_pte(entry);
> > +			if (pte_soft_dirty(pte))
> > +				swp_pte = pte_swp_mksoft_dirty(swp_pte);
> > +			set_pte_at(mm, addr, ptep, swp_pte);
> > +
> > +			page_remove_rmap(page, false);
> > +			put_page(page);
> > +			pages++;
> > +		}
> 
> Can you explain this. What does a failure to lock means here. Also why
> convert the pte to migration entries here ? We do that in try_to_unmap right ?

This an optimization for the usual case where the memory is only use in one
process and that no concurrent migration/memory event is happening. Basicly
if we can lock the page without waiting then we unmap it and the later call
to try_to_unmap() is a no op.

This is purely to optimize this common case. In short it is doing try_to_unmap()
work ahead of time.

Cheers,
Jérôme

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


Thread

[HMM v13 16/18] mm/hmm/migrate: new memory migration helper for use with device memory Jérôme Glisse <jglisse@redhat.com> - 2016-11-18 18:20 +0100
  Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for use with device memory "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> - 2016-11-18 21:00 +0100
    Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for  use with device memory Jerome Glisse <jglisse@redhat.com> - 2016-11-18 21:20 +0100
  Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for use with device memory "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> - 2016-11-19 15:40 +0100
    Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for  use with device memory Jerome Glisse <jglisse@redhat.com> - 2016-11-19 18:20 +0100
      Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for use with device memory "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> - 2016-11-20 19:30 +0100
        Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for  use with device memory Jerome Glisse <jglisse@redhat.com> - 2016-11-20 21:10 +0100
  Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for  use with device memory Balbir Singh <bsingharora@gmail.com> - 2016-11-21 04:40 +0100
    Re: [HMM v13 16/18] mm/hmm/migrate: new memory migration helper for  use with device memory Jerome Glisse <jglisse@redhat.com> - 2016-11-21 06:40 +0100

csiph-web