Skip to content

Commit c94b692

Browse files
yhuang-inteltorvalds
authored andcommitted
/proc/PID/smaps: Add PMD migration entry parsing
Now, when reading /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. To test the patch, we run pmbench to eat 400 MB memory in background, then run /usr/bin/migratepages and `cat /proc/PID/smaps` every second. The issue as follows can be reproduced within 60 seconds. Before the patch, for the fully populated 400 MB anonymous VMA, some THP pages under migration may be lost as below. 7f3f6a7e5000-7f3f837e5000 rw-p 00000000 00:00 0 Size: 409600 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Rss: 407552 kB Pss: 407552 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 0 kB Private_Dirty: 407552 kB Referenced: 301056 kB Anonymous: 407552 kB LazyFree: 0 kB AnonHugePages: 405504 kB ShmemPmdMapped: 0 kB FilePmdMapped: 0 kB Shared_Hugetlb: 0 kB Private_Hugetlb: 0 kB Swap: 0 kB SwapPss: 0 kB Locked: 0 kB THPeligible: 1 VmFlags: rd wr mr mw me ac After the patch, it will be always, 7f3f6a7e5000-7f3f837e5000 rw-p 00000000 00:00 0 Size: 409600 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Rss: 409600 kB Pss: 409600 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 0 kB Private_Dirty: 409600 kB Referenced: 294912 kB Anonymous: 409600 kB LazyFree: 0 kB AnonHugePages: 407552 kB ShmemPmdMapped: 0 kB FilePmdMapped: 0 kB Shared_Hugetlb: 0 kB Private_Hugetlb: 0 kB Swap: 0 kB SwapPss: 0 kB Locked: 0 kB THPeligible: 1 VmFlags: rd wr mr mw me ac Signed-off-by: "Huang, Ying" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Zi Yan <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: "Jérôme Glisse" <[email protected]> Cc: Yang Shi <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 99395ee commit c94b692

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

fs/proc/task_mmu.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,17 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
546546
struct mem_size_stats *mss = walk->private;
547547
struct vm_area_struct *vma = walk->vma;
548548
bool locked = !!(vma->vm_flags & VM_LOCKED);
549-
struct page *page;
549+
struct page *page = NULL;
550+
551+
if (pmd_present(*pmd)) {
552+
/* FOLL_DUMP will return -EFAULT on huge zero page */
553+
page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP);
554+
} else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) {
555+
swp_entry_t entry = pmd_to_swp_entry(*pmd);
550556

551-
/* FOLL_DUMP will return -EFAULT on huge zero page */
552-
page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP);
557+
if (is_migration_entry(entry))
558+
page = migration_entry_to_page(entry);
559+
}
553560
if (IS_ERR_OR_NULL(page))
554561
return;
555562
if (PageAnon(page))
@@ -578,8 +585,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
578585

579586
ptl = pmd_trans_huge_lock(pmd, vma);
580587
if (ptl) {
581-
if (pmd_present(*pmd))
582-
smaps_pmd_entry(pmd, addr, walk);
588+
smaps_pmd_entry(pmd, addr, walk);
583589
spin_unlock(ptl);
584590
goto out;
585591
}

0 commit comments

Comments
 (0)