* [PATCH RESEND 0/2] KSM: use linear_page_index in collect_procs_ksm()
@ 2026-07-08 3:38 xu.xin16
2026-07-08 4:19 ` [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16
2026-07-08 4:22 ` [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space xu.xin16
0 siblings, 2 replies; 8+ messages in thread
From: xu.xin16 @ 2026-07-08 3:38 UTC (permalink / raw)
To: akpm, david; +Cc: chengming.zhou, linux-mm, linux-kernel
From 65241f800da589be1981181d1bc3efd69a7d0385 Mon Sep 17 00:00:00 2001
From: xu xin <xu.xin16@zte.com.cn>
Date: Wed, 8 Jul 2026 11:13:47 +0800
Subject: [PATCH 0/2] KSM: use linear_page_index in collect_procs_ksm()
In collect_procs_ksm() which is used to collect processes when the error
hit an ksm page, there is the same issue with rmap_walk_ksm (see the
previous discussion at [1]). So we apply the similar logic changes to
the collect_procs_ksm().
The patch [1/2] move the initializaion of addr from the position inside
loop to the position before the loop, since the variable will not change
in the loop.
The patch [2/2] optimize collect_procs_ksm by passing a suitable page offset
range to the anon_vma_interval_tree_foreach loop to reduce ineffective
checks.
[1] https://lore.kernel.org/all/20260703162253688u8Str9eFLR8TGCmo7nIOF@zte.com.cn/
xu xin (2):
mm/ksm: Initialize the addr only once in collect_procs_ksm
mm/ksm: Use precise linear_page_index instead of the whole address
space
mm/ksm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm 2026-07-08 3:38 [PATCH RESEND 0/2] KSM: use linear_page_index in collect_procs_ksm() xu.xin16 @ 2026-07-08 4:19 ` xu.xin16 2026-07-08 7:50 ` David Hildenbrand (Arm) 2026-07-08 7:53 ` David Hildenbrand (Arm) 2026-07-08 4:22 ` [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space xu.xin16 1 sibling, 2 replies; 8+ messages in thread From: xu.xin16 @ 2026-07-08 4:19 UTC (permalink / raw) To: akpm, david, chengming.zhou Cc: akpm, david, chengming.zhou, linux-mm, linux-kernel From: xu xin <xu.xin16@zte.com.cn> Similar with 318d87b8fa7 ("ksm: initialize the addr only once in rmap_walk_ksm"), Only initialize the addr only once in rmap_walk_ksm because the addr variable doesn't change across iterations. Signed-off-by: Xu Xin <xu.xin16@zte.com> --- mm/ksm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index c1dcc3cb4831..337eb04a9340 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3289,7 +3289,7 @@ void collect_procs_ksm(const struct folio *folio, const struct page *page, rcu_read_lock(); for_each_process(tsk) { struct anon_vma_chain *vmac; - unsigned long addr; + const unsigned long addr = rmap_item->address & PAGE_MASK; struct task_struct *t = task_early_kill(tsk, force_early); if (!t) @@ -3299,7 +3299,6 @@ void collect_procs_ksm(const struct folio *folio, const struct page *page, { vma = vmac->vma; if (vma->vm_mm == t->mm) { - addr = rmap_item->address & PAGE_MASK; add_to_kill_ksm(t, page, vma, to_kill, addr); } -- 2.25.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm 2026-07-08 4:19 ` [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16 @ 2026-07-08 7:50 ` David Hildenbrand (Arm) 2026-07-08 7:53 ` David Hildenbrand (Arm) 1 sibling, 0 replies; 8+ messages in thread From: David Hildenbrand (Arm) @ 2026-07-08 7:50 UTC (permalink / raw) To: xu.xin16, akpm, chengming.zhou; +Cc: linux-mm, linux-kernel On 7/8/26 06:19, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > Similar with 318d87b8fa7 ("ksm: initialize the addr only once in rmap_walk_ksm"), > Only initialize the addr only once in rmap_walk_ksm because the addr variable > doesn't change across iterations. > > Signed-off-by: Xu Xin <xu.xin16@zte.com> > --- Acked-by: David Hildenbrand (Arm) <david@kernel.org> -- Cheers, David ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm 2026-07-08 4:19 ` [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16 2026-07-08 7:50 ` David Hildenbrand (Arm) @ 2026-07-08 7:53 ` David Hildenbrand (Arm) 1 sibling, 0 replies; 8+ messages in thread From: David Hildenbrand (Arm) @ 2026-07-08 7:53 UTC (permalink / raw) To: xu.xin16, akpm, chengming.zhou; +Cc: linux-mm, linux-kernel On 7/8/26 06:19, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > Similar with 318d87b8fa7 ("ksm: initialize the addr only once in rmap_walk_ksm"), checkpatch.pl should complain here "Similar as commit 318d87b8fa7 ("ksm: initialize the addr only once in rmap_walk_ksm")," ... > Only initialize the addr only once in rmap_walk_ksm because the addr variable s/Only/only/, but you une one "only" too much here. > doesn't change across iterations. > > Signed-off-by: Xu Xin <xu.xin16@zte.com> > --- > mm/ksm.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index c1dcc3cb4831..337eb04a9340 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -3289,7 +3289,7 @@ void collect_procs_ksm(const struct folio *folio, const struct page *page, > rcu_read_lock(); > for_each_process(tsk) { > struct anon_vma_chain *vmac; > - unsigned long addr; > + const unsigned long addr = rmap_item->address & PAGE_MASK; > struct task_struct *t = > task_early_kill(tsk, force_early); > if (!t) > @@ -3299,7 +3299,6 @@ void collect_procs_ksm(const struct folio *folio, const struct page *page, > { > vma = vmac->vma; > if (vma->vm_mm == t->mm) { > - addr = rmap_item->address & PAGE_MASK; > add_to_kill_ksm(t, page, vma, to_kill, > addr); > } -- Cheers, David ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space 2026-07-08 3:38 [PATCH RESEND 0/2] KSM: use linear_page_index in collect_procs_ksm() xu.xin16 2026-07-08 4:19 ` [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16 @ 2026-07-08 4:22 ` xu.xin16 2026-07-08 7:52 ` David Hildenbrand (Arm) 1 sibling, 1 reply; 8+ messages in thread From: xu.xin16 @ 2026-07-08 4:22 UTC (permalink / raw) To: akpm, david, chengming.zhou Cc: akpm, david, chengming.zhou, linux-mm, linux-kernel, xu.xin16 From: xu xin <xu.xin16@zte.com.cn> 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@zte.com.cn/ [1] Signed-off-by: Xu Xin <xu.xin16@zte.com.cn> --- 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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space 2026-07-08 4:22 ` [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space xu.xin16 @ 2026-07-08 7:52 ` David Hildenbrand (Arm) 2026-07-09 3:10 ` xu.xin16 0 siblings, 1 reply; 8+ messages in thread From: David Hildenbrand (Arm) @ 2026-07-08 7:52 UTC (permalink / raw) To: xu.xin16, akpm, chengming.zhou; +Cc: linux-mm, linux-kernel On 7/8/26 06:22, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > 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. It's awkward to reference a commit by a mailing list link. The other patch is not upstream yet. Best to wait for that to go in first, so you can properly reference the commit. -- Cheers, David ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space 2026-07-08 7:52 ` David Hildenbrand (Arm) @ 2026-07-09 3:10 ` xu.xin16 2026-07-09 8:53 ` David Hildenbrand (Arm) 0 siblings, 1 reply; 8+ messages in thread From: xu.xin16 @ 2026-07-09 3:10 UTC (permalink / raw) To: david, akpm; +Cc: akpm, chengming.zhou, linux-mm, linux-kernel > > From: xu xin <xu.xin16@zte.com.cn> > > > > 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. > > It's awkward to reference a commit by a mailing list link. The other patch is > not upstream yet. Best to wait for that to go in first, so you can properly > reference the commit. Ok, I'm going to resend this after that referenced patch is upstream. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space 2026-07-09 3:10 ` xu.xin16 @ 2026-07-09 8:53 ` David Hildenbrand (Arm) 0 siblings, 0 replies; 8+ messages in thread From: David Hildenbrand (Arm) @ 2026-07-09 8:53 UTC (permalink / raw) To: xu.xin16, akpm; +Cc: chengming.zhou, linux-mm, linux-kernel On 7/9/26 05:10, xu.xin16@zte.com.cn wrote: >>> From: xu xin <xu.xin16@zte.com.cn> >>> >>> 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. >> >> It's awkward to reference a commit by a mailing list link. The other patch is >> not upstream yet. Best to wait for that to go in first, so you can properly >> reference the commit. > > Ok, I'm going to resend this after that referenced patch is upstream. Alternatively, just mention that we now have linear_page_index available that we can use here, without referring to the other patch/commit. That would probably be cleanest. -- Cheers, David ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-09 8:53 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-08 3:38 [PATCH RESEND 0/2] KSM: use linear_page_index in collect_procs_ksm() xu.xin16 2026-07-08 4:19 ` [PATCH 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16 2026-07-08 7:50 ` David Hildenbrand (Arm) 2026-07-08 7:53 ` David Hildenbrand (Arm) 2026-07-08 4:22 ` [PATCH RESEND 2/2] mm/ksm: Use precise linear_page_index instead of the whole address space xu.xin16 2026-07-08 7:52 ` David Hildenbrand (Arm) 2026-07-09 3:10 ` xu.xin16 2026-07-09 8:53 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox