Skip to contentSkip to conversation

/proc/PID/smaps: Add PMD migration entry parsing

PATCH In review Huang, Ying 5 participants 12 messages Mar 31, 2020 – Apr 2, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 /proc/PID/smaps: Add PMD migration entry parsing

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
 fs/proc/task_mmu.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
fs/proc/task_mmu.c +12 -4
index 8d382d4ec067..b5b3aef8cb3b 100644
@@ -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;
 
-	/* 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))) {
+		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;
 	}
Signature · 1 line
2.25.0
#1 lore raw
Quoted 25 lines · Ying

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
  fs/proc/task_mmu.c | 16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
fs/proc/task_mmu.c +0 -0
index 8d382d4ec067..b5b3aef8cb3b 100644

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 549

Quoted 2 lines
fs/proc/task_mmu.c +0 -0
@@ -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;
        struct page *page = NULL;

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 558

Quoted 11 lines
fs/proc/task_mmu.c +8 -2
-	/* 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))) {
+		swp_entry_t entry = pmd_to_swp_entry(*pmd);
+
+		VM_BUG_ON(!is_migration_entry(entry));
+		page = migration_entry_to_page(entry);
                if (is_migration_entry(entry))
                        page = migration_entry_to_page(entry);

Seems safer and doesn't add much code.

Quoted 17 lines
fs/proc/task_mmu.c +4 -2
+	} 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 lore raw
Quoted 21 lines · Konstantin Khlebnikov
Quoted 20 lines · Ying

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
  fs/proc/task_mmu.c | 16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 9 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 549

Quoted 7 lines
fs/proc/task_mmu.c +0 -0
index 8d382d4ec067..b5b3aef8cb3b 100644
@@ -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;
        struct page *page = NULL;

Looks good. Will do this in the next version.

Quoted 14 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 558

Quoted 10 lines
fs/proc/task_mmu.c +8 -1
  -	/* 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))) {
+		swp_entry_t entry = pmd_to_swp_entry(*pmd);
+
+		VM_BUG_ON(!is_migration_entry(entry));
+		page = migration_entry_to_page(entry);
                if (is_migration_entry(entry))
                        page = migration_entry_to_page(entry);
Quoted 1 line

Seems safer and doesn't add much code.

With this, we lose an opportunity to capture some bugs during debugging. Right?

Best Regards,
Huang, Ying

Quoted 16 lines
Quoted 16 lines
fs/proc/task_mmu.c +4 -2
+	} 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;
  	}
 
#3 lore raw
Quoted 49 lines · Ying
Quoted 21 lines · Konstantin Khlebnikov
Quoted 20 lines · Ying

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
   fs/proc/task_mmu.c | 16 ++++++++++++----
   1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 9 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 549

Quoted 7 lines
fs/proc/task_mmu.c +0 -0
index 8d382d4ec067..b5b3aef8cb3b 100644
@@ -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;
         struct page *page = NULL;

Looks good. Will do this in the next version.

Quoted 14 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 558

Quoted 10 lines
fs/proc/task_mmu.c +8 -1
   -	/* 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))) {
+		swp_entry_t entry = pmd_to_swp_entry(*pmd);
+
+		VM_BUG_ON(!is_migration_entry(entry));
+		page = migration_entry_to_page(entry);
                 if (is_migration_entry(entry))
                         page = migration_entry_to_page(entry);
Quoted 4 lines
Quoted 1 line

Seems safer and doesn't add much code.

With this, we lose an opportunity to capture some bugs during debugging. Right?

You can keep VM_BUG_ON or VM_WARN_ON_ONCE

Off-by-page in statistics isn't a big deal and not a good reason to crash (even debug) kernel. But for normal build should use safe behaviour if this isn't hard.

Quoted 20 lines

Best Regards,
Huang, Ying

Quoted 16 lines
Quoted 16 lines
fs/proc/task_mmu.c +4 -2
+	} 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;
   	}
 
#4 lore raw
Quoted 52 lines · Konstantin Khlebnikov
Quoted 51 lines · Ying
Quoted 21 lines · Konstantin Khlebnikov
Quoted 20 lines · Ying

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
   fs/proc/task_mmu.c | 16 ++++++++++++----
   1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 9 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 549

Quoted 7 lines
fs/proc/task_mmu.c +0 -0
index 8d382d4ec067..b5b3aef8cb3b 100644
@@ -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;
         struct page *page = NULL;

Looks good. Will do this in the next version.

Quoted 15 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 558

Quoted 10 lines
fs/proc/task_mmu.c +8 -1
   -	/* 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))) {
+		swp_entry_t entry = pmd_to_swp_entry(*pmd);
+
+		VM_BUG_ON(!is_migration_entry(entry));
+		page = migration_entry_to_page(entry);
                 if (is_migration_entry(entry))
                         page = migration_entry_to_page(entry);

Seems safer and doesn't add much code.

Quoted 7 lines
Quoted 2 lines

With this, we lose an opportunity to capture some bugs during debugging. Right?

You can keep VM_BUG_ON or VM_WARN_ON_ONCE

Off-by-page in statistics isn't a big deal and not a good reason to crash (even debug) kernel. But for normal build should use safe behaviour if this isn't hard.

Sounds reasonable! Will revise the code. Thanks!

Best Regards,
Huang, Ying

Quoted 20 lines
Quoted 20 lines

Best Regards,
Huang, Ying

Quoted 16 lines
Quoted 16 lines
fs/proc/task_mmu.c +4 -2
+	} 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;
   	}
 
Reviewed-by on v1 1/1
#5 lore raw
In reply to Huang, Ying
Quoted 26 lines · Ying

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
 fs/proc/task_mmu.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
fs/proc/task_mmu.c +0 -0
index 8d382d4ec067..b5b3aef8cb3b 100644

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 549

Quoted 2 lines
fs/proc/task_mmu.c +0 -0
@@ -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.

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 554

Quoted 7 lines
fs/proc/task_mmu.c +4 -2
-       /* 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.

Quoted 21 lines
fs/proc/task_mmu.c +8 -3
+               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;
        }
--
Quoted 1 line

2.25.0

Everything else looks good to me. Thanks.

With the fixes mentioned above, you can add

—
Best Regards,
Yan Zi

#6 lore raw
Quoted 22 lines · Zi Yan
Quoted 21 lines · Ying

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
 fs/proc/task_mmu.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 10 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 549

Quoted 7 lines
fs/proc/task_mmu.c +0 -0
index 8d382d4ec067..b5b3aef8cb3b 100644
@@ -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.

Quoted 8 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 554

Quoted 7 lines
fs/proc/task_mmu.c +4 -2
-       /* 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))) {
Quoted 5 lines

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()?

Quoted 25 lines
Quoted 21 lines
fs/proc/task_mmu.c +8 -3
+               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;
        }
--
Quoted 1 line

2.25.0

Everything else looks good to me. Thanks.

Quoted 2 lines

With the fixes mentioned above, you can add

Thanks!

Best Regards,
Huang, Ying

#7 lore raw
Quoted 38 lines · Ying

External email: Use caution opening links or attachments

Quoted 22 lines · Zi Yan
Quoted 21 lines · Ying

From: Huang Ying <[email protected]>

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.

Cc Andrea Arcangeli <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Zi Yan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Konstantin Khlebnikov <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
Cc Yang Shi <[email protected]>
---
 fs/proc/task_mmu.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 10 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 549

Quoted 7 lines
fs/proc/task_mmu.c +0 -0
index 8d382d4ec067..b5b3aef8cb3b 100644
@@ -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.

Quoted 1 line

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

Thanks.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
fs/proc/task_mmu.c +4 -2
-       /* 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))) {
Quoted 8 lines
Quoted 5 lines

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()?

Oh, I missed that. Your original code is right. Thank you for the explanation.

—
Best Regards,
Yan Zi

#8 lore raw
In reply to Zi Yan
Quoted 10 lines · Zi Yan

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 554

Quoted 8 lines · Ying

From: Huang Ying <[email protected]>

fs/proc/task_mmu.c +4 -2
-       /* 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))) {
Quoted 2 lines

Should be:

          } else if (unlikely(thp_migration_support() && is_swap_pmd(*pmd))) {

Thought this again. This can reduce the code size if thp_migration_support() isn't enabled. I will do this in the next version.

Best Regards,
Huang, Ying

maintainer
#9 lore raw
In reply to Huang, Ying
Quoted 5 lines · Ying

From: Huang Ying <[email protected]>

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.

It would be helpful to show the before-and-after output in the changelog.

Quoted 5 lines
fs/proc/task_mmu.c +0 -0
@@ -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;

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 557

Quoted 10 lines
fs/proc/task_mmu.c +7 -2
 
-	/* 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))) {
+		swp_entry_t entry = pmd_to_swp_entry(*pmd);
+
+		VM_BUG_ON(!is_migration_entry(entry));

I don't think this justifies nuking the kernel. A WARN()-and-recover would be better.

Quoted 17 lines
fs/proc/task_mmu.c +5 -2
+		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;
 	}
#10 lore raw
Quoted 9 lines · Andrew Morton
Quoted 5 lines · Ying

From: Huang Ying <[email protected]>

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.

It would be helpful to show the before-and-after output in the changelog.

OK.

Quoted 6 lines
Quoted 6 lines
fs/proc/task_mmu.c +0 -0
@@ -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;
 
Quoted 12 lines

fs/proc/task_mmu.c static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, · line 557

Quoted 9 lines
fs/proc/task_mmu.c +7 -2
-	/* 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))) {
+		swp_entry_t entry = pmd_to_swp_entry(*pmd);
+
+		VM_BUG_ON(!is_migration_entry(entry));

I don't think this justifies nuking the kernel. A WARN()-and-recover would be better.

Yes. Will change this in the next version.

Best Regards,
Huang, Ying

Quoted 17 lines
Quoted 17 lines
fs/proc/task_mmu.c +5 -2
+		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;
 	}
#11 lore raw
In reply to Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 5 lines · Ying

From: Huang Ying <[email protected]>

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.

It would be helpful to show the before-and-after output in the changelog.

Migration entries are ephemeral. Is this observable in practice? I suspect this is just primarily motivated by reading the code more than hitting the actual problem.

Signature · 2 lines
Michal Hocko
SUSE Labs