v2
2026-07-15
khugepaged 清理与辅助函数 · v2
提交 khugepaged 清理系列,引入辅助函数、更新注释并提取 PTE 状态检查为帮助函数。
原始补丁链接
子 Patch(7)
1/7
mm/khugepaged: refactor per-scan state clearing into collapse_control_init_scan()
Extract the repeated clearing of node_load, alloc_nmask, and mthp_present_ptes into a helper to reduce duplication in collapse_scan_pmd() and collapse_scan_file(). Althought file scans do not current
2/7
mm/khugepaged: extract young page check into collapse_is_referenced() helper
This change deduplicates the “is this PTE/folio referenced enough to be considered for a collapse” condition that was repeated in both __collapse_huge_page_isolate() and collapse_scan_pmd(), extractin
3/7
mm/khugepaged: introduce a count_collapse_event() helper
Provide a simple helper function to help reduce a often used, and duplicate pattern across the khugepaged code. When collapsing to a PMD we need to record a vm_event and the mTHP_stat event. When doi
4/7
mm/khugepaged: fix outdated comments
Fix comment in collapse_scan_pmd() that still described the old folio_mapcount() > folio_ref_count() check and a “512” false-positive scenario. The code now uses folio_expected_ref_count() != folio_re
5/7
mm/khugepaged: Refactor the PTE state checks into a helper
For anonymous collapse, the collapse_scan_pmd() and __collapse_huge_page_isolate() functions share a large portion of their logic. These functions both check the state of the PTEs and verify the follo
6/7
mm/khugepaged: unmap pte before releasing vma write lock
We are currently dropping the anon_vma write lock before unmapping the PTE. Although this is safe, due to us still holding the mmap_write_lock, its safer and less confusing to switch the order of thes
7/7
mm: Documentation: clarify where the mTHP stats live
The note about khugepaged counters references /proc/vmstat for the PMD case, but never mentions where the mTHPs stats can be found (i.e.: /sys/kernel/mm/transparent_hugepage/hugepages-kB/stats/)