Re: [PATCH v2 1/2] khugepaged: enable collapse pmd for pte-mapped THP

From: Oleg Nesterov
Date: Thu Aug 01 2019 - 10:50:36 EST


On 07/31, Song Liu wrote:
>
> +static int khugepaged_add_pte_mapped_thp(struct mm_struct *mm,
> + unsigned long addr)
> +{
> + struct mm_slot *mm_slot;
> + int ret = 0;
> +
> + /* hold mmap_sem for khugepaged_test_exit() */
> + VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
> + VM_BUG_ON(addr & ~HPAGE_PMD_MASK);
> +
> + if (unlikely(khugepaged_test_exit(mm)))
> + return 0;
> +
> + if (!test_bit(MMF_VM_HUGEPAGE, &mm->flags) &&
> + !test_bit(MMF_DISABLE_THP, &mm->flags)) {
> + ret = __khugepaged_enter(mm);
> + if (ret)
> + return ret;
> + }

could you explain why do we need mm->mmap_sem, khugepaged_test_exit() check
and __khugepaged_enter() ?


> + spin_lock(&khugepaged_mm_lock);
> + mm_slot = get_mm_slot(mm);
> + if (likely(mm_slot && mm_slot->nr_pte_mapped_thp < MAX_PTE_MAPPED_THP))
> + mm_slot->pte_mapped_thp[mm_slot->nr_pte_mapped_thp++] = addr;

if get_mm_slot() returns mm_slot != NULL we can safely modify ->pte_mapped_thp.
We do not care even if this task has already passed __mmput/__khugepaged_exit,
this slot can't go away.

No?

Oleg.