From 0471cade0a272803d192cbd8d8523e93e429ff1d Mon Sep 17 00:00:00 2001 From: xu xin Date: Thu, 9 Jul 2026 17:33:12 +0800 Subject: [PATCH] ksm: use precise linear_page_index instead of the whole address space Since we now have linear_page_index available that we can use here, allowing for optimizing the RMAP walk, we can also use it to locate more precisely all related-processes when error hits the KSM page, which will decrease a lot of invalid iterations. Link: https://lore.kernel.org/20260709173312403qgj1Af6pRkFMDSsmc19sM@zte.com.cn Signed-off-by: xu xin Acked-by: David Hildenbrand (Arm) Cc: Chengming Zhou Signed-off-by: Andrew Morton --- mm/ksm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 337eb04a9340..2791ce5bd44b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3290,12 +3290,13 @@ void collect_procs_ksm(const struct folio *folio, const struct page *page, for_each_process(tsk) { struct anon_vma_chain *vmac; const unsigned long addr = rmap_item->address & PAGE_MASK; + const unsigned long index = rmap_item->linear_page_index; struct task_struct *t = task_early_kill(tsk, force_early); if (!t) continue; - anon_vma_interval_tree_foreach(vmac, &av->rb_root, 0, - ULONG_MAX) + anon_vma_interval_tree_foreach(vmac, &av->rb_root, index, + index) { vma = vmac->vma; if (vma->vm_mm == t->mm) {