The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 0/2] KSM: use linear_page_index in collect_procs_ksm()
@ 2026-07-09  9:31 xu.xin16
  2026-07-09  9:32 ` [PATCH v2 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16
  2026-07-09  9:33 ` [PATCH v2 2/2] ksm: Use precise linear_page_index instead of the whole address space xu.xin16
  0 siblings, 2 replies; 5+ messages in thread
From: xu.xin16 @ 2026-07-09  9:31 UTC (permalink / raw)
  To: akpm, david; +Cc: xu.xin16, chengming.zhou, linux-mm, linux-kernel

From: xu xin <xu.xin16@zte.com.cn>

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
  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] 5+ messages in thread

* [PATCH v2 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm
  2026-07-09  9:31 [PATCH v2 0/2] KSM: use linear_page_index in collect_procs_ksm() xu.xin16
@ 2026-07-09  9:32 ` xu.xin16
  2026-07-09  9:58   ` David Hildenbrand (Arm)
  2026-07-09  9:33 ` [PATCH v2 2/2] ksm: Use precise linear_page_index instead of the whole address space xu.xin16
  1 sibling, 1 reply; 5+ messages in thread
From: xu.xin16 @ 2026-07-09  9:32 UTC (permalink / raw)
  To: akpm, david; +Cc: chengming.zhou, linux-mm, linux-kernel, xu.xin16

From: xu xin <xu.xin16@zte.com.cn>

Similar as 318d87b8fa7 ("ksm: initialize the addr only once in
rmap_walk_ksm"), only initialize the addr once in rmap_walk_ksm
because the addr variable doesn't change across iterations.

Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
 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] 5+ messages in thread

* [PATCH v2 2/2] ksm: Use precise linear_page_index instead of the whole address space
  2026-07-09  9:31 [PATCH v2 0/2] KSM: use linear_page_index in collect_procs_ksm() xu.xin16
  2026-07-09  9:32 ` [PATCH v2 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16
@ 2026-07-09  9:33 ` xu.xin16
  2026-07-09  9:59   ` David Hildenbrand (Arm)
  1 sibling, 1 reply; 5+ messages in thread
From: xu.xin16 @ 2026-07-09  9:33 UTC (permalink / raw)
  To: akpm, david; +Cc: chengming.zhou, linux-mm, linux-kernel, xu.xin16

From: xu xin <xu.xin16@zte.com.cn>

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.

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] 5+ messages in thread

* Re: [PATCH v2 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm
  2026-07-09  9:32 ` [PATCH v2 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16
@ 2026-07-09  9:58   ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-09  9:58 UTC (permalink / raw)
  To: xu.xin16, akpm; +Cc: chengming.zhou, linux-mm, linux-kernel

On 7/9/26 11:32, xu.xin16@zte.com.cn wrote:
> From: xu xin <xu.xin16@zte.com.cn>
> 
> Similar as 318d87b8fa7 ("ksm: initialize the addr only once in
> rmap_walk_ksm"), only initialize the addr once in rmap_walk_ksm
> because the addr variable doesn't change across iterations.
> 
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> ---

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] ksm: Use precise linear_page_index instead of the whole address space
  2026-07-09  9:33 ` [PATCH v2 2/2] ksm: Use precise linear_page_index instead of the whole address space xu.xin16
@ 2026-07-09  9:59   ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-09  9:59 UTC (permalink / raw)
  To: xu.xin16, akpm; +Cc: chengming.zhou, linux-mm, linux-kernel

On 7/9/26 11:33, xu.xin16@zte.com.cn wrote:
> From: xu xin <xu.xin16@zte.com.cn>
> 
> 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.
> 
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> ---

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-09  9:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-09  9:31 [PATCH v2 0/2] KSM: use linear_page_index in collect_procs_ksm() xu.xin16
2026-07-09  9:32 ` [PATCH v2 1/2] mm/ksm: Initialize the addr only once in collect_procs_ksm xu.xin16
2026-07-09  9:58   ` David Hildenbrand (Arm)
2026-07-09  9:33 ` [PATCH v2 2/2] ksm: Use precise linear_page_index instead of the whole address space xu.xin16
2026-07-09  9:59   ` 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