Re: [PATCH] /proc/PID/smaps: Add PMD migration entry parsing

From: Huang\, Ying
Date: Tue Mar 31 2020 - 22:25:03 EST


Zi Yan <ziy@xxxxxxxxxx> writes:

> On 31 Mar 2020, at 4:56, Huang, Ying wrote:
>>
>> From: Huang Ying <ying.huang@xxxxxxxxx>
>>
>> Now, when read /proc/PID/smaps, the PMD migration entry in page table is simply
>> ignored. To improve the accuracy of /proc/PID/smaps, its parsing and processing
>> is added.
>>
>> Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx>
>> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
>> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
>> Cc: Zi Yan <ziy@xxxxxxxxxx>
>> Cc: Vlastimil Babka <vbabka@xxxxxxx>
>> Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx>
>> Cc: Michal Hocko <mhocko@xxxxxxxx>
>> Cc: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx>
>> Cc: "JÃrÃme Glisse" <jglisse@xxxxxxxxxx>
>> Cc: Yang Shi <yang.shi@xxxxxxxxxxxxxxxxx>
>> ---
>> fs/proc/task_mmu.c | 16 ++++++++++++----
>> 1 file changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
>> index 8d382d4ec067..b5b3aef8cb3b 100644
>> --- a/fs/proc/task_mmu.c
>> +++ b/fs/proc/task_mmu.c
>> @@ -548,8 +548,17 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
>> bool locked = !!(vma->vm_flags & VM_LOCKED);
>> struct page *page;
>
> Like Konstantin pointed out in another email, you could initialize page to NULL here.
> Plus you do not need the âelse-returnâ below, if you do that.

Yes. That looks better. Will change this in the next version.

>>
>> - /* FOLL_DUMP will return -EFAULT on huge zero page */
>> - page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP);
>> + if (pmd_present(*pmd)) {
>> + /* FOLL_DUMP will return -EFAULT on huge zero page */
>> + page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP);
>> + } else if (unlikely(is_swap_pmd(*pmd))) {
>
> Should be:
> } else if (unlikely(thp_migration_support() && is_swap_pmd(*pmd))) {
>
> Otherwise, when THP migration is disabled and the PMD is under splitting, VM_BUG_ON
> will be triggered.

We hold the PMD page table lock when call smaps_pmd_entry(). How does
PMD splitting trigger VM_BUG_ON()?

>> + swp_entry_t entry = pmd_to_swp_entry(*pmd);
>> +
>> + VM_BUG_ON(!is_migration_entry(entry));
>> + page = migration_entry_to_page(entry);
>> + } else {
>> + return;
>> + }
>> if (IS_ERR_OR_NULL(page))
>> return;
>> if (PageAnon(page))
>> @@ -578,8 +587,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
>>
>> ptl = pmd_trans_huge_lock(pmd, vma);
>> if (ptl) {
>> - if (pmd_present(*pmd))
>> - smaps_pmd_entry(pmd, addr, walk);
>> + smaps_pmd_entry(pmd, addr, walk);
>> spin_unlock(ptl);
>> goto out;
>> }
>> --
>> 2.25.0
>
> Everything else looks good to me. Thanks.
>
> With the fixes mentioned above, you can add
> Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>

Thanks!

Best Regards,
Huang, Ying