Re: [PATCH] ksm: Stop iterating VMAs when ksm_test_exit returns true
From: David Hildenbrand (Arm)
Date: Mon Jul 27 2026 - 08:49:15 EST
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@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;
>
Yeah, just like the ksm_test_exit() check before the loop.
Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Jumping into an if block is absolutely nasty. The no_vmas label should be
refactored.
--
Cheers,
David