From: David Hildenbrand <david@redhat.com>
To: Donet Tom <donettom@linux.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Ritesh Harjani <ritesh.list@gmail.com>,
Xu Xin <xu.xin16@zte.com.cn>,
Chengming Zhou <chengming.zhou@linux.dev>,
Wei Yang <richard.weiyang@gmail.com>,
Aboorva Devarajan <aboorvad@linux.ibm.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Subject: Re: [PATCH v2 2/3] selftests/mm: Added fork inheritance test for ksm_merging_pages counter
Date: Wed, 17 Sep 2025 15:15:39 +0200 [thread overview]
Message-ID: <26e38fe5-e6c4-4678-8056-95c0ff4350e6@redhat.com> (raw)
In-Reply-To: <f07c901d4b6b1d1c15a8c1bbd324367d6135d0a3.1757946863.git.donettom@linux.ibm.com>
On 15.09.25 17:03, Donet Tom wrote:
> Added a new selftest to verify whether the `ksm_merging_pages` counter
> in `mm_struct` is not inherited by a child process after fork. This helps
> ensure correctness of KSM accounting across process creation.
>
> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
> ---
> .../selftests/mm/ksm_functional_tests.c | 42 ++++++++++++++++++-
> 1 file changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index 712f43c87736..645cefba2126 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -602,6 +602,45 @@ static void test_prot_none(void)
> munmap(map, size);
> }
>
> +static void test_fork_ksm_merging_page_count(void)
> +{
> + const unsigned int size = 2 * MiB;
> + char *map;
> + pid_t child_pid;
> + int status;
> +
> + ksft_print_msg("[RUN] %s\n", __func__);
> +
> + map = mmap_and_merge_range(0xcf, size, PROT_READ | PROT_WRITE, KSM_MERGE_MADVISE);
> + if (map == MAP_FAILED)
> + return;
> +
> + child_pid = fork();
> + if (!child_pid) {
> + init_global_file_handles();
> + exit(ksm_get_self_merging_pages());
> + } else if (child_pid < 0) {
> + ksft_test_result_fail("fork() failed\n");
> + return;
Probably
goto out;
in all these fail cases
> + }
> +
> + if (waitpid(child_pid, &status, 0) < 0) {
> + ksft_test_result_fail("waitpid() failed\n");
> + return;
> + }
> +
> + status = WEXITSTATUS(status);
> + if (status) {
> + ksft_test_result_fail("ksm_merging_page in child: %d\n", status);
> + return;
> + }
> +
> + ksft_test_result_pass("ksm_merging_pages is not inherited after fork\n");
> +
And have
out:
here
With that:
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers
David / dhildenb
next prev parent reply other threads:[~2025-09-17 13:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 15:03 [PATCH v2 0/3] mm/ksm: Fix incorrect accounting of KSM counters during fork Donet Tom
2025-09-15 15:03 ` [PATCH v2 1/3] mm/ksm: Fix incorrect KSM counter handling in mm_struct " Donet Tom
2025-09-15 23:42 ` Andrew Morton
2025-09-16 2:14 ` Joe Perches
2025-09-16 2:54 ` Andrew Morton
2025-09-16 4:33 ` Sasha Levin
2025-09-16 4:41 ` Andrew Morton
2025-09-16 12:45 ` Sasha Levin
2025-09-16 5:50 ` Donet Tom
2025-09-17 10:38 ` David Hildenbrand
2025-09-17 12:27 ` Chengming Zhou
2025-09-15 15:03 ` [PATCH v2 2/3] selftests/mm: Added fork inheritance test for ksm_merging_pages counter Donet Tom
2025-09-17 13:15 ` David Hildenbrand [this message]
2025-09-17 14:45 ` Donet Tom
2025-09-15 15:03 ` [PATCH v2 3/3] selftests/mm: Added fork test to verify global ksm_zero_pages counter behavior Donet Tom
2025-09-17 13:19 ` David Hildenbrand
2025-09-17 14:47 ` Donet Tom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=26e38fe5-e6c4-4678-8056-95c0ff4350e6@redhat.com \
--to=david@redhat.com \
--cc=aboorvad@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=donettom@linux.ibm.com \
--cc=giorgitchankvetadze1997@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=richard.weiyang@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=xu.xin16@zte.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox