Re: [PATCH v3 3/3] selftests/mm: verify ksm_zero_pages is not inherited on fork

From: Xu Xin (vivo)

Date: Mon Nov 23 2026 - 21:46:09 EST


On Mon, Nov 23, 2026 at 05:49:30PM +0100, David Hildenbrand (Arm) wrote:
> On 11/23/26 04:45, Xu Xin (vivo) wrote:
> > Extend test_fork_ksm_merging_page_count() to enable use_zero_pages and
> > merge zero pages alongside non-zero pages before fork(), verifying that>
> neither ksm_merging_pages nor ksm_zero_pages is inherited by the child.
> >
> > Signed-off-by: Xu Xin (vivo) <xu.xin@xxxxxxxxx>
> > ---
> > .../selftests/mm/ksm_functional_tests.c | 44 +++++++++++++++----
> > 1 file changed, 35 insertions(+), 9 deletions(-)
> >
> > diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> > index b871d5656688..0e128c579d5c 100644
> > --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> > +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> > @@ -655,45 +655,71 @@ static void test_prot_none(void)
> > munmap(map, size);
> > }
> >
> > -static void test_fork_ksm_merging_page_count(void)
> > +static void test_fork_ksm_statistic_count(void)
>
> "statistic_count" sounds odd. did you mean "statistics" or "counters". Below you
> use "stats".

Yes, I meant "counters" (my phrasing was inaccurate). I will rename it to
test_fork_ksm_counters() in v4.

> > }
> >
> > - ksft_test_result_pass("ksm_merging_pages is not inherited after fork\n");
> > -
> > + ksft_test_result_pass("ksm_merging_pages and ksm_zero_pages are reset after fork\n");
> > +unmap_zero:
> > + munmap(zero_map, size);
> > unmap:
> > ksm_stop();
> > munmap(map, size);
>
> This ordering is odd.
>
> Why stop in between?
>
> Also, I suggest using a single label, like:
>
> char *zero_map = MAP_FAILED, *map = MAP_FAILED;
>

Agreed, the ordering was just kept from the original code and looks odd.
I will unify this into a single cleanup label in v4, unmapping both
regions cleanly before calling ksm_stop().

> ...
>
> if (zero_map != MAP_FAILED)
> munmap(zero_map, size);
> if (map != MAP_FAILED)
> munmap(map, size);
>
> --
> Cheers,
>
> David