Re: [RFC][PATCH 1/3] pagemap: avoid splitting thp when reading /proc/pid/pagemap

From: Naoya Horiguchi
Date: Mon Dec 19 2011 - 14:17:13 EST


On Mon, Dec 19, 2011 at 10:48:17AM -0800, David Rientjes wrote:
> On Mon, 19 Dec 2011, Naoya Horiguchi wrote:
...
> > @@ -666,10 +685,33 @@ static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
> > pte_t *pte;
> > int err = 0;
> >
> > - split_huge_page_pmd(walk->mm, pmd);
> > -
> > /* find the first VMA at or above 'addr' */
> > vma = find_vma(walk->mm, addr);
> > +
> > + spin_lock(&walk->mm->page_table_lock);
>
> pagemap_pte_range() could potentially be called a _lot_, so I'd recommend
> optimizing this by checking for pmd_trans_huge() prior to taking
> page_table_lock and then rechecking after grabbing it with likely().

OK, I'll try it.
Similar logic is used on smaps_pte_range() and gather_pte_stats(),
so I think it's better to write a separate patch for this optimization.

> > + if (pmd_trans_huge(*pmd)) {
> > + if (pmd_trans_splitting(*pmd)) {
> > + spin_unlock(&walk->mm->page_table_lock);
> > + wait_split_huge_page(vma->anon_vma, pmd);
> > + } else {
> > + u64 pfn = PM_NOT_PRESENT;
>
> This doesn't need to be initialized and it would probably be better to
> declare "pfn" at the top-level of this function since it's later used for
> the non-thp case.

Agreed.
I unify two declarations of "pfn" at the beginning of the function.

Thank you for nice feedback.
Naoya
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/