Skip to content

Commit f0849ac

Browse files
Yang Shitorvalds
authored andcommitted
mm: thp: fix potential clearing to referenced flag in page_idle_clear_pte_refs_one()
For PTE-mapped THP, the compound THP has not been split to normal 4K pages yet, the whole THP is considered referenced if any one of sub page is referenced. When walking PTE-mapped THP by pvmw, all relevant PTEs will be checked to retrieve referenced bit. But, the current code just returns the result of the last PTE. If the last PTE has not referenced, the referenced flag will be cleared. Just set referenced when ptep{pmdp}_clear_young_notify() returns true. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Yang Shi <[email protected]> Reported-by: Gang Deng <[email protected]> Suggested-by: Kirill A. Shutemov <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c9e97a1 commit f0849ac

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mm/page_idle.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ static bool page_idle_clear_pte_refs_one(struct page *page,
6565
while (page_vma_mapped_walk(&pvmw)) {
6666
addr = pvmw.address;
6767
if (pvmw.pte) {
68-
referenced = ptep_clear_young_notify(vma, addr,
69-
pvmw.pte);
68+
/*
69+
* For PTE-mapped THP, one sub page is referenced,
70+
* the whole THP is referenced.
71+
*/
72+
if (ptep_clear_young_notify(vma, addr, pvmw.pte))
73+
referenced = true;
7074
} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
71-
referenced = pmdp_clear_young_notify(vma, addr,
72-
pvmw.pmd);
75+
if (pmdp_clear_young_notify(vma, addr, pvmw.pmd))
76+
referenced = true;
7377
} else {
7478
/* unexpected pmd-mapped page? */
7579
WARN_ON_ONCE(1);

0 commit comments

Comments
 (0)