/* * Idle page tracking only considers user memory pages, for other types of * pages the idle flag is always unset and an attempt to set it is silently * ignored. * * We treat a page as a user memory page if it is on an LRU list, because it is * always safe to pass such a page to rmap_walk(), which is essential for idle * page tracking. With such an indicator of user pages we can skip isolated * pages, but since there are not usually many of them, it will hardly affect * the overall result. * * This function tries to get a user memory page by pfn as described above.
*/ staticstruct folio *page_idle_get_folio(unsignedlong pfn)
{ struct page *page = pfn_to_online_page(pfn); struct folio *folio;
while (page_vma_mapped_walk(&pvmw)) {
addr = pvmw.address; if (pvmw.pte) { /* * For PTE-mapped THP, one sub page is referenced, * the whole THP is referenced. * * PFN swap PTEs, such as device-exclusive ones, that * actually map pages are "old" from a CPU perspective. * The MMU notifier takes care of any device aspects.
*/ if (likely(pte_present(ptep_get(pvmw.pte))))
referenced |= ptep_test_and_clear_young(vma, addr, pvmw.pte);
referenced |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE);
} elseif (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { if (pmdp_clear_young_notify(vma, addr, pvmw.pmd))
referenced = true;
} else { /* unexpected pmd-mapped page? */
WARN_ON_ONCE(1);
}
}
if (referenced) {
folio_clear_idle(folio); /* * We cleared the referenced bit in a mapping to this page. To * avoid interference with page reclaim, mark it young so that * folio_referenced() will return > 0.
*/
folio_set_young(folio);
} returntrue;
}
staticvoid page_idle_clear_pte_refs(struct folio *folio)
{ /* * Since rwc.try_lock is unused, rwc is effectively immutable, so we * can make it static to save some cycles and stack.
*/ staticstruct rmap_walk_control rwc = {
.rmap_one = page_idle_clear_pte_refs_one,
.anon_lock = folio_lock_anon_vma_read,
}; bool need_lock;
if (!folio_mapped(folio) || !folio_raw_mapping(folio)) return;
need_lock = !folio_test_anon(folio) || folio_test_ksm(folio); if (need_lock && !folio_trylock(folio)) return;
for (; pfn < end_pfn; pfn++) {
bit = pfn % BITMAP_CHUNK_BITS; if (!bit)
*out = 0ULL;
folio = page_idle_get_folio(pfn); if (folio) { if (folio_test_idle(folio)) { /* * The page might have been referenced via a * pte, in which case it is not idle. Clear * refs and recheck.
*/
page_idle_clear_pte_refs(folio); if (folio_test_idle(folio))
*out |= 1ULL << bit;
}
folio_put(folio);
} if (bit == BITMAP_CHUNK_BITS - 1)
out++;
cond_resched();
} return (char *)out - buf;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.