Re: [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true
From: xu.xin16
Date: Sun Jul 26 2026 - 11:15:16 EST
> 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@xxxxxxx>
> ---
> 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@xxxxxxxxxx>