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


Groups > linux.kernel > #1423832 > unrolled thread

Re: [PATCHv9-rebased2 11/37] mm: introduce do_set_pmd()

Started by"Hillf Danton" <hillf.zj@alibaba-inc.com>
First post2016-06-16 11:20 +0200
Last post2016-06-16 12:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCHv9-rebased2 11/37] mm: introduce do_set_pmd() "Hillf Danton" <hillf.zj@alibaba-inc.com> - 2016-06-16 11:20 +0200
    Re: [PATCHv9-rebased2 11/37] mm: introduce do_set_pmd() "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-06-16 12:20 +0200

#1423832 — Re: [PATCHv9-rebased2 11/37] mm: introduce do_set_pmd()

From"Hillf Danton" <hillf.zj@alibaba-inc.com>
Date2016-06-16 11:20 +0200
SubjectRe: [PATCHv9-rebased2 11/37] mm: introduce do_set_pmd()
Message-ID<rKBCV-6wx-3@gated-at.bofh.it>
> +
> +static int do_set_pmd(struct fault_env *fe, struct page *page)
> +{
> +	struct vm_area_struct *vma = fe->vma;
> +	bool write = fe->flags & FAULT_FLAG_WRITE;
> +	unsigned long haddr = fe->address & HPAGE_PMD_MASK;
> +	pmd_t entry;
> +	int i, ret;
> +
> +	if (!transhuge_vma_suitable(vma, haddr))
> +		return VM_FAULT_FALLBACK;
> +
> +	ret = VM_FAULT_FALLBACK;
> +	page = compound_head(page);
> +
> +	fe->ptl = pmd_lock(vma->vm_mm, fe->pmd);
> +	if (unlikely(!pmd_none(*fe->pmd)))
> +		goto out;

Can we reply to the caller that fault is handled correctly(by
resetting ret to zero before jump)?

> +
> +	for (i = 0; i < HPAGE_PMD_NR; i++)
> +		flush_icache_page(vma, page + i);
> +
> +	entry = mk_huge_pmd(page, vma->vm_page_prot);
> +	if (write)
> +		entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
> +
> +	add_mm_counter(vma->vm_mm, MM_FILEPAGES, HPAGE_PMD_NR);
> +	page_add_file_rmap(page, true);
> +
> +	set_pmd_at(vma->vm_mm, haddr, fe->pmd, entry);
> +
> +	update_mmu_cache_pmd(vma, haddr, fe->pmd);
> +
> +	/* fault is handled */
> +	ret = 0;
> +out:
> +	spin_unlock(fe->ptl);
> +	return ret;
> +}
> +#else
> +static int do_set_pmd(struct fault_env *fe, struct page *page)
> +{
> +	BUILD_BUG();
> +	return 0;
> +}
> +#endif
> +
>  /**
>   * alloc_set_pte - setup new PTE entry for given page and add reverse page
>   * mapping. If needed, the fucntion allocates page table or use pre-allocated.
> @@ -2940,9 +3000,19 @@ int alloc_set_pte(struct fault_env *fe, struct mem_cgroup *memcg,
>  	struct vm_area_struct *vma = fe->vma;
>  	bool write = fe->flags & FAULT_FLAG_WRITE;
>  	pte_t entry;
> +	int ret;
> +
> +	if (pmd_none(*fe->pmd) && PageTransCompound(page)) {
> +		/* THP on COW? */
> +		VM_BUG_ON_PAGE(memcg, page);
> +
> +		ret = do_set_pmd(fe, page);
> +		if (ret != VM_FAULT_FALLBACK)
> +			return ret;
> +	}
> 
>  	if (!fe->pte) {
> -		int ret = pte_alloc_one_map(fe);
> +		ret = pte_alloc_one_map(fe);
>  		if (ret)
>  			return ret;
>  	}
> diff --git a/mm/migrate.c b/mm/migrate.c

[toc] | [next] | [standalone]


#1423905

From"Kirill A. Shutemov" <kirill@shutemov.name>
Date2016-06-16 12:20 +0200
Message-ID<rKCyZ-75H-17@gated-at.bofh.it>
In reply to#1423832
On Thu, Jun 16, 2016 at 05:15:22PM +0800, Hillf Danton wrote:
> > +
> > +static int do_set_pmd(struct fault_env *fe, struct page *page)
> > +{
> > +	struct vm_area_struct *vma = fe->vma;
> > +	bool write = fe->flags & FAULT_FLAG_WRITE;
> > +	unsigned long haddr = fe->address & HPAGE_PMD_MASK;
> > +	pmd_t entry;
> > +	int i, ret;
> > +
> > +	if (!transhuge_vma_suitable(vma, haddr))
> > +		return VM_FAULT_FALLBACK;
> > +
> > +	ret = VM_FAULT_FALLBACK;
> > +	page = compound_head(page);
> > +
> > +	fe->ptl = pmd_lock(vma->vm_mm, fe->pmd);
> > +	if (unlikely(!pmd_none(*fe->pmd)))
> > +		goto out;
> 
> Can we reply to the caller that fault is handled correctly(by
> resetting ret to zero before jump)?

It's non necessary handled. It's handled only if the pmd if huge. If it
points to pte table, we need to check relevant pte entry.

If pmd is huge it will caught by pte_alloc_one_map() later.

-- 
 Kirill A. Shutemov

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web