mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true
@ 2026-07-26 13:35 Wang Wensheng
  2026-07-26 15:14 ` xu.xin16
  2026-07-27 12:43 ` David Hildenbrand (Arm)
  0 siblings, 2 replies; 3+ messages in thread
From: Wang Wensheng @ 2026-07-26 13:35 UTC (permalink / raw)
  To: akpm, david, xu.xin16, chengming.zhou, linux-mm, linux-kernel; +Cc: wsw9603

In scan_get_next_rmap_item() the break statement only exits the inner
while loop, leaving remaining VMAs to be iterated even if ksm_test_exit()
returns true. Replace it with a goto statement to avoid the unnecessary
work.

Signed-off-by: Wang Wensheng <wsw9603@163.com>
---
 mm/ksm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index 7d5b76478f0b..5ed9db676b9f 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2666,7 +2666,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
 			struct folio *folio;
 
 			if (ksm_test_exit(mm))
-				break;
+				goto no_vmas;
 
 			int found;
 
-- 
2.43.0


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

* Re: [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true
  2026-07-26 13:35 [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true Wang Wensheng
@ 2026-07-26 15:14 ` xu.xin16
  2026-07-27 12:43 ` David Hildenbrand (Arm)
  1 sibling, 0 replies; 3+ messages in thread
From: xu.xin16 @ 2026-07-26 15:14 UTC (permalink / raw)
  To: wsw9603, akpm, david; +Cc: chengming.zhou, linux-mm, linux-kernel, wsw9603

> In scan_get_next_rmap_item() the break statement only exits the inner
> while loop, leaving remaining VMAs to be iterated even if ksm_test_exit()
> returns true. Replace it with a goto statement to avoid the unnecessary
> work.
> 
> Signed-off-by: Wang Wensheng <wsw9603@163.com>
> ---
>  mm/ksm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 7d5b76478f0b..5ed9db676b9f 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -2666,7 +2666,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
>              struct folio *folio;
>  
>              if (ksm_test_exit(mm))
> -                break;
> +                goto no_vmas;
>  
>              int found;
>  
> -- 
> 2.43.0

Thanks, I noticed it too recently.

Looks good to me.

Reviewed-by: Xu Xin <xu.xin16@zte.com.cn>

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

* Re: [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true
  2026-07-26 13:35 [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true Wang Wensheng
  2026-07-26 15:14 ` xu.xin16
@ 2026-07-27 12:43 ` David Hildenbrand (Arm)
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-27 12:43 UTC (permalink / raw)
  To: Wang Wensheng, akpm, xu.xin16, chengming.zhou, linux-mm, linux-kernel

On 7/26/26 15:35, Wang Wensheng wrote:
> In scan_get_next_rmap_item() the break statement only exits the inner
> while loop, leaving remaining VMAs to be iterated even if ksm_test_exit()
> returns true. Replace it with a goto statement to avoid the unnecessary
> work.
> 
> Signed-off-by: Wang Wensheng <wsw9603@163.com>
> ---
>  mm/ksm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 7d5b76478f0b..5ed9db676b9f 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -2666,7 +2666,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
>  			struct folio *folio;
>  
>  			if (ksm_test_exit(mm))
> -				break;
> +				goto no_vmas;
>  
>  			int found;
>  

Yeah, just like the ksm_test_exit() check before the loop.

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


Jumping into an if block is absolutely nasty. The no_vmas label should be
refactored.

-- 
Cheers,

David

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

end of thread, other threads:[~2026-07-27 12:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-26 13:35 [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true Wang Wensheng
2026-07-26 15:14 ` xu.xin16
2026-07-27 12:43 ` 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

all inboxes | Powered by JetHome®