From: xu xin Date: Thu, 12 Feb 2026 11:29:32 +0000 (+0800) Subject: ksm: initialize the addr only once in rmap_walk_ksm X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=318d87b8fa733bebdc9c803657671df0b7b8b006;p=thirdparty%2Fkernel%2Fstable.git ksm: initialize the addr only once in rmap_walk_ksm This is a minor performance optimization, especially when there are many for-loop iterations, because the addr variable doesn't change across iterations. Therefore, it only needs to be initialized once before the loop. Link: https://lkml.kernel.org/r/20260212192820223O_r2NQzSEPG_C56cs-z4l@zte.com.cn Link: https://lkml.kernel.org/r/20260212192932941MSsJEAyoRW4YdLBN7_myn@zte.com.cn Signed-off-by: xu xin Acked-by: David Hildenbrand (Arm) Cc: Chengming Zhou Cc: Hugh Dickins Cc: Wang Yaxin Cc: Yang Yang Signed-off-by: Andrew Morton --- diff --git a/mm/ksm.c b/mm/ksm.c index bda71ae609ff..2a2f2f005fc3 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3168,6 +3168,8 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc) return; again: hlist_for_each_entry(rmap_item, &stable_node->hlist, hlist) { + /* Ignore the stable/unstable/sqnr flags */ + const unsigned long addr = rmap_item->address & PAGE_MASK; struct anon_vma *anon_vma = rmap_item->anon_vma; struct anon_vma_chain *vmac; struct vm_area_struct *vma; @@ -3180,16 +3182,13 @@ again: } anon_vma_lock_read(anon_vma); } + anon_vma_interval_tree_foreach(vmac, &anon_vma->rb_root, 0, ULONG_MAX) { - unsigned long addr; cond_resched(); vma = vmac->vma; - /* Ignore the stable/unstable/sqnr flags */ - addr = rmap_item->address & PAGE_MASK; - if (addr < vma->vm_start || addr >= vma->vm_end) continue; /*