Linux Test Project
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 3/7] mem/ksm06: Move test code from library to the test
Date: Mon, 07 Mar 2022 13:03:48 +0000	[thread overview]
Message-ID: <875yopnccj.fsf@suse.de> (raw)
In-Reply-To: <20220303145032.21493-4-chrubis@suse.cz>

Hi,

Cyril Hrubis <chrubis@suse.cz> writes:

> There is no point in keeping the test code in the library since ksm06 is
> the only test that actually uses it.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

> ---
>  testcases/kernel/mem/ksm/ksm06.c | 82 +++++++++++++++++++++++++++++-
>  testcases/kernel/mem/lib/mem.c   | 85 --------------------------------
>  2 files changed, 81 insertions(+), 86 deletions(-)
>
> diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
> index 379236f1f..0f5e4b05d 100644
> --- a/testcases/kernel/mem/ksm/ksm06.c
> +++ b/testcases/kernel/mem/ksm/ksm06.c
> @@ -48,7 +48,87 @@ static char *n_opt;
>  
>  static void test_ksm(void)
>  {
> -	test_ksm_merge_across_nodes(nr_pages);
> +	char **memory;
> +	int i, ret;
> +	int num_nodes, *nodes;
> +	unsigned long length;
> +	unsigned long pagesize;
> +
> +#ifdef HAVE_NUMA_V2
> +	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
> +#endif
> +
> +	ret = get_allowed_nodes_arr(NH_MEMS, &num_nodes, &nodes);
> +	if (ret != 0)
> +		tst_brk(TBROK|TERRNO, "get_allowed_nodes_arr");
> +	if (num_nodes < 2) {
> +		tst_res(TINFO, "need NUMA system support");
> +		free(nodes);
> +		return;
> +	}
> +
> +	pagesize = sysconf(_SC_PAGE_SIZE);
> +	length = nr_pages * pagesize;
> +
> +	memory = SAFE_MALLOC(num_nodes * sizeof(char *));
> +	for (i = 0; i < num_nodes; i++) {
> +		memory[i] = SAFE_MMAP(NULL, length, PROT_READ|PROT_WRITE,
> +			    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
> +#ifdef HAVE_DECL_MADV_MERGEABLE
> +		if (madvise(memory[i], length, MADV_MERGEABLE) == -1)
> +			tst_brk(TBROK|TERRNO, "madvise");
> +#endif
> +
> +#ifdef HAVE_NUMA_V2
> +		clean_node(nmask);
> +		set_node(nmask, nodes[i]);
> +		/*
> +		 * Use mbind() to make sure each node contains
> +		 * length size memory.
> +		 */
> +		ret = mbind(memory[i], length, MPOL_BIND, nmask, MAXNODES, 0);
> +		if (ret == -1)
> +			tst_brk(TBROK|TERRNO, "mbind");
> +#endif
> +
> +		memset(memory[i], 10, length);
> +
> +		if (mlock(memory[i], length))
> +			tst_res(TWARN | TERRNO, "mlock() failed");
> +	}
> +
> +	SAFE_FILE_PRINTF(PATH_KSM "sleep_millisecs", "0");
> +	SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld",
> +			 nr_pages * num_nodes);
> +	/*
> +	 * merge_across_nodes and max_page_sharing setting can be changed
> +	 * only when there are no ksm shared pages in system, so set run 2
> +	 * to unmerge pages first, then to 1 after changing merge_across_nodes,
> +	 * to remerge according to the new setting.
> +	 */
> +	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
> +	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
> +		SAFE_FILE_PRINTF(PATH_KSM "max_page_sharing",
> +			"%ld", nr_pages * num_nodes);
> +	tst_res(TINFO, "Start to test KSM with merge_across_nodes=1");
> +	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
> +	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
> +	ksm_group_check(1, 1, nr_pages * num_nodes - 1, 0, 0, 0,
> +			nr_pages * num_nodes);
> +
> +	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
> +	tst_res(TINFO, "Start to test KSM with merge_across_nodes=0");
> +	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "0");
> +	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
> +	ksm_group_check(1, num_nodes, nr_pages * num_nodes - num_nodes,
> +			0, 0, 0, nr_pages * num_nodes);
> +
> +	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
> +
> +	for (i = 0; i < num_nodes; i++)
> +		SAFE_MUNMAP(memory[i], length);
> +
> +	free(memory);
>  }
>  
>  static void setup(void)
> diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
> index 102fc5665..090569ebb 100644
> --- a/testcases/kernel/mem/lib/mem.c
> +++ b/testcases/kernel/mem/lib/mem.c
> @@ -519,91 +519,6 @@ void create_same_memory(int size, int num, int unit)
>  				 WEXITSTATUS(status));
>  }
>  
> -void test_ksm_merge_across_nodes(unsigned long nr_pages)
> -{
> -	char **memory;
> -	int i, ret;
> -	int num_nodes, *nodes;
> -	unsigned long length;
> -	unsigned long pagesize;
> -
> -#ifdef HAVE_NUMA_V2
> -	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
> -#endif
> -
> -	ret = get_allowed_nodes_arr(NH_MEMS, &num_nodes, &nodes);
> -	if (ret != 0)
> -		tst_brk(TBROK|TERRNO, "get_allowed_nodes_arr");
> -	if (num_nodes < 2) {
> -		tst_res(TINFO, "need NUMA system support");
> -		free(nodes);
> -		return;
> -	}
> -
> -	pagesize = sysconf(_SC_PAGE_SIZE);
> -	length = nr_pages * pagesize;
> -
> -	memory = SAFE_MALLOC(num_nodes * sizeof(char *));
> -	for (i = 0; i < num_nodes; i++) {
> -		memory[i] = SAFE_MMAP(NULL, length, PROT_READ|PROT_WRITE,
> -			    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
> -#ifdef HAVE_DECL_MADV_MERGEABLE
> -		if (madvise(memory[i], length, MADV_MERGEABLE) == -1)
> -			tst_brk(TBROK|TERRNO, "madvise");
> -#endif
> -
> -#ifdef HAVE_NUMA_V2
> -		clean_node(nmask);
> -		set_node(nmask, nodes[i]);
> -		/*
> -		 * Use mbind() to make sure each node contains
> -		 * length size memory.
> -		 */
> -		ret = mbind(memory[i], length, MPOL_BIND, nmask, MAXNODES, 0);
> -		if (ret == -1)
> -			tst_brk(TBROK|TERRNO, "mbind");
> -#endif
> -
> -		memset(memory[i], 10, length);
> -
> -		if (mlock(memory[i], length))
> -			tst_res(TWARN | TERRNO, "mlock() failed");
> -	}
> -
> -	SAFE_FILE_PRINTF(PATH_KSM "sleep_millisecs", "0");
> -	SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld",
> -			 nr_pages * num_nodes);
> -	/*
> -	 * merge_across_nodes and max_page_sharing setting can be changed
> -	 * only when there are no ksm shared pages in system, so set run 2
> -	 * to unmerge pages first, then to 1 after changing merge_across_nodes,
> -	 * to remerge according to the new setting.
> -	 */
> -	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
> -	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
> -		SAFE_FILE_PRINTF(PATH_KSM "max_page_sharing",
> -			"%ld", nr_pages * num_nodes);
> -	tst_res(TINFO, "Start to test KSM with merge_across_nodes=1");
> -	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
> -	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
> -	ksm_group_check(1, 1, nr_pages * num_nodes - 1, 0, 0, 0,
> -		        nr_pages * num_nodes);
> -
> -	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
> -	tst_res(TINFO, "Start to test KSM with merge_across_nodes=0");
> -	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "0");
> -	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
> -	ksm_group_check(1, num_nodes, nr_pages * num_nodes - num_nodes,
> -		        0, 0, 0, nr_pages * num_nodes);
> -
> -	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
> -
> -	for (i = 0; i < num_nodes; i++)
> -		SAFE_MUNMAP(memory[i], length);
> -
> -	free(memory);
> -}
> -
>  /* THP */
>  
>  /* cpuset/memcg */
> -- 
> 2.34.1


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-03-07 13:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 14:50 [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Cyril Hrubis
2022-03-03 14:50 ` [LTP] [PATCH 1/7] ksm06: Move option parsing into the setup() Cyril Hrubis
2022-03-07 13:02   ` Richard Palethorpe
2022-03-03 14:50 ` [LTP] [PATCH 2/7] mem/lib: Export group_check() as ksm_group_check() Cyril Hrubis
2022-03-07 13:03   ` Richard Palethorpe
2022-03-03 14:50 ` [LTP] [PATCH 3/7] mem/ksm06: Move test code from library to the test Cyril Hrubis
2022-03-07 13:03   ` Richard Palethorpe [this message]
2022-03-03 14:50 ` [LTP] [PATCH 4/7] mem/ksm06: SPDX + docparse comment Cyril Hrubis
2022-03-07 13:04   ` Richard Palethorpe
2022-03-03 14:50 ` [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct Cyril Hrubis
2022-03-04  2:27   ` Li Wang
2022-03-04 12:02     ` Cyril Hrubis
2022-03-07  1:44       ` Li Wang
2022-03-07  8:58         ` Cyril Hrubis
2022-03-07  9:06           ` Li Wang
2022-03-07  9:13             ` Cyril Hrubis
2022-03-03 14:50 ` [LTP] [PATCH 6/7] libs: libltpnuma: Fix free memory estimate Cyril Hrubis
2022-03-04  2:56   ` Li Wang
2022-03-03 14:50 ` [LTP] [PATCH 7/7] mem/ksm06: Make use of the new libltpnuma Cyril Hrubis
2022-03-04  3:17   ` Li Wang
2022-03-03 15:06 ` [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Petr Vorel

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=875yopnccj.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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