linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Stefan Roesch <shr@devkernel.io>, kernel-team@fb.com
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, riel@surriel.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v2 2/2] mm/ksm: Test case for prctl fork/exec workflow
Date: Thu, 21 Sep 2023 13:44:08 +0200	[thread overview]
Message-ID: <a5e5b08f-851b-3dd1-889b-5b09eff5b7be@redhat.com> (raw)
In-Reply-To: <20230920190117.784151-3-shr@devkernel.io>

On 20.09.23 21:01, Stefan Roesch wrote:
> This adds a new test case to the ksm functional tests to make sure that
> the KSM setting is inherited by the child process when doing a
> fork/exec.
> 
> Signed-off-by: Stefan Roesch <shr@devkernel.io>
> ---
>   .../selftests/mm/ksm_functional_tests.c       | 67 ++++++++++++++++++-
>   1 file changed, 66 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index 901e950f9138..40b86c9caf3a 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -26,6 +26,7 @@
>   
>   #define KiB 1024u
>   #define MiB (1024 * KiB)
> +#define FORK_EXEC_CHILD_PRG_NAME "ksm_fork_exec_child"
>   
>   static int mem_fd;
>   static int ksm_fd;
> @@ -479,6 +480,65 @@ static void test_prctl_fork(void)
>   	ksft_test_result_pass("PR_SET_MEMORY_MERGE value is inherited\n");
>   }
>   
> +static int ksm_fork_exec_child(void)
> +{
> +	/* Test if KSM is enabled for the process. */
> +	int ksm = prctl(PR_GET_MEMORY_MERGE, 0, 0, 0, 0);
> +	return ksm == 1;

You can simply do "return prctl(PR_GET_MEMORY_MERGE, 0, 0, 0, 0) == 1;"

Or maybe even "return prctl(PR_GET_MEMORY_MERGE, 0, 0, 0, 0);" and 
adjust the comparison below in the caller.

> +}
> +
> +static void test_prctl_fork_exec(void)
> +{
> +	int ret, status;
> +	pid_t child_pid;
> +
> +	ksft_print_msg("[RUN] %s\n", __func__);
> +
> +	ret = prctl(PR_SET_MEMORY_MERGE, 1, 0, 0, 0);
> +	if (ret < 0 && errno == EINVAL) {
> +		ksft_test_result_skip("PR_SET_MEMORY_MERGE not supported\n");
> +		return;
> +	} else if (ret) {
> +		ksft_test_result_fail("PR_SET_MEMORY_MERGE=1 failed\n");
> +		return;
> +	}
> +
> +	child_pid = fork();
> +	if (child_pid == -1) {
> +		ksft_test_result_skip("fork() failed\n");
> +		return;
> +	} else if (child_pid == 0) {
> +		char *prg_name = "./ksm_functional_tests";
> +		char *argv_for_program[] = { prg_name, FORK_EXEC_CHILD_PRG_NAME };
> +

I'd simply have used the magic number "1" or so. But this works as well.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2023-09-21 11:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 19:01 [PATCH v2 0/2] mm/ksm: add fork-exec support for prctl Stefan Roesch
2023-09-20 19:01 ` [PATCH v2 1/2] mm/ksm: support fork/exec " Stefan Roesch
2023-09-20 19:01 ` [PATCH v2 2/2] mm/ksm: Test case for prctl fork/exec workflow Stefan Roesch
2023-09-21 11:44   ` David Hildenbrand [this message]
2023-09-21 16:25     ` Stefan Roesch

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=a5e5b08f-851b-3dd1-889b-5b09eff5b7be@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.com \
    --cc=shr@devkernel.io \
    /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