Re: [PATCH 2/6] thp: optimize away unnecessary page table locking

From: Hillf Danton
Date: Fri Jan 13 2012 - 07:04:55 EST


On Fri, Jan 13, 2012 at 3:34 AM, Naoya Horiguchi
<n-horiguchi@xxxxxxxxxxxxx> wrote:
> Currently when we check if we can handle thp as it is or we need to
> split it into regular sized pages, we hold page table lock prior to
> check whether a given pmd is mapping thp or not. Because of this,
> when it's not "huge pmd" we suffer from unnecessary lock/unlock overhead.
> To remove it, this patch introduces a optimized check function and
> replace several similar logics with it.
>
> Signed-off-by: Naoya Horiguchi <n-horiguchi@xxxxxxxxxxxxx>
> Cc: David Rientjes <rientjes@xxxxxxxxxx>
>
> Changes since v2:
> Â- Fix missing "return 0" in "thp under splitting" path
> Â- Remove unneeded comment
> Â- Change the name of check function to describe what it does
> Â- Add VM_BUG_ON(mmap_sem)
> ---
> Âfs/proc/task_mmu.c   Â|  73 +++++++++------------------
> Âinclude/linux/huge_mm.h | Â Â7 +++
> Âmm/huge_memory.c    Â| Â127 +++++++++++++++++++++++------------------------
> Âmm/mremap.c       |  Â3 +-
> Â4 files changed, 95 insertions(+), 115 deletions(-)
>
[...]
> +/*
> + * Returns 1 if a given pmd is mapping a thp and stable (not under splitting.)
> + * Returns 0 otherwise. Note that if it returns 1, this routine returns without
> + * unlocking page table locks. So callers must unlock them.
> + */
> +int pmd_trans_huge_stable(pmd_t *pmd, struct vm_area_struct *vma)
> +{
> + Â Â Â VM_BUG_ON(!rwsem_is_locked(&vma->vm_mm->mmap_sem));
> +
> + Â Â Â if (!pmd_trans_huge(*pmd))
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â spin_lock(&vma->vm_mm->page_table_lock);
> + Â Â Â if (likely(pmd_trans_huge(*pmd))) {
> + Â Â Â Â Â Â Â if (pmd_trans_splitting(*pmd)) {
> + Â Â Â Â Â Â Â Â Â Â Â spin_unlock(&vma->vm_mm->page_table_lock);
> + Â Â Â Â Â Â Â Â Â Â Â wait_split_huge_page(vma->anon_vma, pmd);
> + Â Â Â Â Â Â Â Â Â Â Â return 0;
> + Â Â Â Â Â Â Â } else {

           spin_unlock(&vma->vm_mm->page_table_lock); yes?

> + Â Â Â Â Â Â Â Â Â Â Â /* Thp mapped by 'pmd' is stable, so we can
> + Â Â Â Â Â Â Â Â Â Â Â Â* handle it as it is. */
> + Â Â Â Â Â Â Â Â Â Â Â return 1;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> + Â Â Â spin_unlock(&vma->vm_mm->page_table_lock);
> + Â Â Â return 0;
> +}
> +
--
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/