mm/ksm: Use precise linear_page_index instead of the whole address space
From: xu.xin16
Date: Tue Jul 07 2026 - 23:40:10 EST
From: xu xin <xu.xin16@xxxxxxxxxx>
Since an earlier commit introduced the linear_page_index to struct
ksm_rmap_item[1], allowing for optimizing the RMAP walk, we can use it
to locate more precisely all processes that hit the KSM page, which will
decrease a lot of unvalid iterations.
Link: https://lore.kernel.org/all/20260703162357853iIa-RP7if9hRlAIuTh5La@xxxxxxxxxx/ [1]
Signed-off-by: Xu Xin <xu.xin16@xxxxxxxxxx>
---
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) {
--
2.25.1