* [LTP] [PATCH 1/7] ksm06: Move option parsing into the setup()
2022-03-03 14:50 [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Cyril Hrubis
@ 2022-03-03 14:50 ` 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
` (6 subsequent siblings)
7 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-03 14:50 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/mem/ksm/ksm06.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index c5f219c37..379236f1f 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -42,17 +42,12 @@
static int run = -1;
static int sleep_millisecs = -1;
static int merge_across_nodes = -1;
-static unsigned long nr_pages;
+static unsigned long nr_pages = 100;
static char *n_opt;
static void test_ksm(void)
{
- if (n_opt)
- nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
- else
- nr_pages = 100;
-
test_ksm_merge_across_nodes(nr_pages);
}
@@ -64,6 +59,9 @@ static void setup(void)
if (!is_numa(NULL, NH_MEMS, 2))
tst_brk(TCONF, "The case needs a NUMA system.");
+ if (n_opt)
+ nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
+
/* save the current value */
SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 1/7] ksm06: Move option parsing into the setup()
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
0 siblings, 0 replies; 21+ messages in thread
From: Richard Palethorpe @ 2022-03-07 13:02 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi,
Cyril Hrubis <chrubis@suse.cz> writes:
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>
> ---
> testcases/kernel/mem/ksm/ksm06.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
> index c5f219c37..379236f1f 100644
> --- a/testcases/kernel/mem/ksm/ksm06.c
> +++ b/testcases/kernel/mem/ksm/ksm06.c
> @@ -42,17 +42,12 @@
> static int run = -1;
> static int sleep_millisecs = -1;
> static int merge_across_nodes = -1;
> -static unsigned long nr_pages;
> +static unsigned long nr_pages = 100;
>
> static char *n_opt;
>
> static void test_ksm(void)
> {
> - if (n_opt)
> - nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
> - else
> - nr_pages = 100;
> -
> test_ksm_merge_across_nodes(nr_pages);
> }
>
> @@ -64,6 +59,9 @@ static void setup(void)
> if (!is_numa(NULL, NH_MEMS, 2))
> tst_brk(TCONF, "The case needs a NUMA system.");
>
> + if (n_opt)
> + nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
> +
> /* save the current value */
> SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
> SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
> --
> 2.34.1
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* [LTP] [PATCH 2/7] mem/lib: Export group_check() as ksm_group_check()
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-03 14:50 ` 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
` (5 subsequent siblings)
7 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-03 14:50 UTC (permalink / raw)
To: ltp
This is preparing for the move of the code from library to the ksm06.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/mem/include/mem.h | 2 ++
testcases/kernel/mem/lib/mem.c | 22 +++++++++++-----------
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index f1cba5fcb..776809113 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -50,6 +50,8 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
void create_same_memory(int size, int num, int unit);
void test_ksm_merge_across_nodes(unsigned long nr_pages);
+void ksm_group_check(int run, int pg_shared, int pg_sharing, int pg_volatile,
+ int pg_unshared, int sleep_msecs, int pages_to_scan);
/* THP */
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index ee9fc85b6..102fc5665 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -271,9 +271,9 @@ static void final_group_check(int run, int pages_shared, int pages_sharing,
check("pages_to_scan", pages_to_scan);
}
-static void group_check(int run, int pages_shared, int pages_sharing,
- int pages_volatile, int pages_unshared,
- int sleep_millisecs, int pages_to_scan)
+void ksm_group_check(int run, int pages_shared, int pages_sharing,
+ int pages_volatile, int pages_unshared,
+ int sleep_millisecs, int pages_to_scan)
{
if (run != 1) {
tst_res(TFAIL, "group_check run is not 1, %d.", run);
@@ -489,19 +489,19 @@ void create_same_memory(int size, int num, int unit)
resume_ksm_children(child, num);
stop_ksm_children(child, num);
- group_check(1, 2, size * num * pages - 2, 0, 0, 0, size * pages * num);
+ ksm_group_check(1, 2, size * num * pages - 2, 0, 0, 0, size * pages * num);
resume_ksm_children(child, num);
stop_ksm_children(child, num);
- group_check(1, 3, size * num * pages - 3, 0, 0, 0, size * pages * num);
+ ksm_group_check(1, 3, size * num * pages - 3, 0, 0, 0, size * pages * num);
resume_ksm_children(child, num);
stop_ksm_children(child, num);
- group_check(1, 1, size * num * pages - 1, 0, 0, 0, size * pages * num);
+ ksm_group_check(1, 1, size * num * pages - 1, 0, 0, 0, size * pages * num);
resume_ksm_children(child, num);
stop_ksm_children(child, num);
- group_check(1, 1, size * num * pages - 2, 0, 1, 0, size * pages * num);
+ ksm_group_check(1, 1, size * num * pages - 2, 0, 1, 0, size * pages * num);
tst_res(TINFO, "KSM unmerging...");
SAFE_FILE_PRINTF(PATH_KSM "run", "2");
@@ -586,15 +586,15 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages)
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");
- group_check(1, 1, nr_pages * num_nodes - 1, 0, 0, 0,
- nr_pages * num_nodes);
+ 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");
- group_check(1, num_nodes, nr_pages * num_nodes - num_nodes,
- 0, 0, 0, nr_pages * num_nodes);
+ 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");
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 2/7] mem/lib: Export group_check() as ksm_group_check()
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
0 siblings, 0 replies; 21+ messages in thread
From: Richard Palethorpe @ 2022-03-07 13:03 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi,
Cyril Hrubis <chrubis@suse.cz> writes:
> This is preparing for the move of the code from library to the ksm06.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>
> ---
> testcases/kernel/mem/include/mem.h | 2 ++
> testcases/kernel/mem/lib/mem.c | 22 +++++++++++-----------
> 2 files changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
> index f1cba5fcb..776809113 100644
> --- a/testcases/kernel/mem/include/mem.h
> +++ b/testcases/kernel/mem/include/mem.h
> @@ -50,6 +50,8 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
>
> void create_same_memory(int size, int num, int unit);
> void test_ksm_merge_across_nodes(unsigned long nr_pages);
> +void ksm_group_check(int run, int pg_shared, int pg_sharing, int pg_volatile,
> + int pg_unshared, int sleep_msecs, int pages_to_scan);
>
> /* THP */
>
> diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
> index ee9fc85b6..102fc5665 100644
> --- a/testcases/kernel/mem/lib/mem.c
> +++ b/testcases/kernel/mem/lib/mem.c
> @@ -271,9 +271,9 @@ static void final_group_check(int run, int pages_shared, int pages_sharing,
> check("pages_to_scan", pages_to_scan);
> }
>
> -static void group_check(int run, int pages_shared, int pages_sharing,
> - int pages_volatile, int pages_unshared,
> - int sleep_millisecs, int pages_to_scan)
> +void ksm_group_check(int run, int pages_shared, int pages_sharing,
> + int pages_volatile, int pages_unshared,
> + int sleep_millisecs, int pages_to_scan)
> {
> if (run != 1) {
> tst_res(TFAIL, "group_check run is not 1, %d.", run);
> @@ -489,19 +489,19 @@ void create_same_memory(int size, int num, int unit)
>
> resume_ksm_children(child, num);
> stop_ksm_children(child, num);
> - group_check(1, 2, size * num * pages - 2, 0, 0, 0, size * pages * num);
> + ksm_group_check(1, 2, size * num * pages - 2, 0, 0, 0, size * pages * num);
>
> resume_ksm_children(child, num);
> stop_ksm_children(child, num);
> - group_check(1, 3, size * num * pages - 3, 0, 0, 0, size * pages * num);
> + ksm_group_check(1, 3, size * num * pages - 3, 0, 0, 0, size * pages * num);
>
> resume_ksm_children(child, num);
> stop_ksm_children(child, num);
> - group_check(1, 1, size * num * pages - 1, 0, 0, 0, size * pages * num);
> + ksm_group_check(1, 1, size * num * pages - 1, 0, 0, 0, size * pages * num);
>
> resume_ksm_children(child, num);
> stop_ksm_children(child, num);
> - group_check(1, 1, size * num * pages - 2, 0, 1, 0, size * pages * num);
> + ksm_group_check(1, 1, size * num * pages - 2, 0, 1, 0, size * pages * num);
>
> tst_res(TINFO, "KSM unmerging...");
> SAFE_FILE_PRINTF(PATH_KSM "run", "2");
> @@ -586,15 +586,15 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages)
> 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");
> - group_check(1, 1, nr_pages * num_nodes - 1, 0, 0, 0,
> - nr_pages * num_nodes);
> + 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");
> - group_check(1, num_nodes, nr_pages * num_nodes - num_nodes,
> - 0, 0, 0, nr_pages * num_nodes);
> + 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");
>
> --
> 2.34.1
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* [LTP] [PATCH 3/7] mem/ksm06: Move test code from library to the test
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-03 14:50 ` [LTP] [PATCH 2/7] mem/lib: Export group_check() as ksm_group_check() Cyril Hrubis
@ 2022-03-03 14:50 ` Cyril Hrubis
2022-03-07 13:03 ` Richard Palethorpe
2022-03-03 14:50 ` [LTP] [PATCH 4/7] mem/ksm06: SPDX + docparse comment Cyril Hrubis
` (4 subsequent siblings)
7 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-03 14:50 UTC (permalink / raw)
To: ltp
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>
---
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 3/7] mem/ksm06: Move test code from library to the test
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
0 siblings, 0 replies; 21+ messages in thread
From: Richard Palethorpe @ 2022-03-07 13:03 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
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
^ permalink raw reply [flat|nested] 21+ messages in thread
* [LTP] [PATCH 4/7] mem/ksm06: SPDX + docparse comment
2022-03-03 14:50 [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Cyril Hrubis
` (2 preceding siblings ...)
2022-03-03 14:50 ` [LTP] [PATCH 3/7] mem/ksm06: Move test code from library to the test Cyril Hrubis
@ 2022-03-03 14:50 ` 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
` (3 subsequent siblings)
7 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-03 14:50 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/mem/ksm/ksm06.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index 0f5e4b05d..61507b2aa 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -1,24 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2013-2017 Red Hat, Inc.
+ */
+/*\
+ * [Description]
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * The case is designed to test sysfs boolean knob
+ * /sys/kernel/mm/ksm/merge_across_nodes.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- */
-
-/*
- * The case is designed to test new sysfs boolean knob
- * /sys/kernel/mm/ksm/merge_across_nodes, which was introduced by
- * commit 90bd6fd31c8097ee (ksm: allow trees per NUMA node).
- * when merge_across_nodes is set to zero only pages from the same
+ * When merge_across_nodes is set to zero only pages from the same
* node are merged, otherwise pages from all nodes can be merged
* together.
+ *
+ * Introduced in commit:
+ *
+ * commit 90bd6fd31c8097ee4ddcb74b7e08363134863de5
+ * Author: Petr Holasek <pholasek@redhat.com>
+ * Date: Fri Feb 22 16:35:00 2013 -0800
+ *
+ * ksm: allow trees per NUMA node
*/
#include "config.h"
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 4/7] mem/ksm06: SPDX + docparse comment
2022-03-03 14:50 ` [LTP] [PATCH 4/7] mem/ksm06: SPDX + docparse comment Cyril Hrubis
@ 2022-03-07 13:04 ` Richard Palethorpe
0 siblings, 0 replies; 21+ messages in thread
From: Richard Palethorpe @ 2022-03-07 13:04 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi,
Cyril Hrubis <chrubis@suse.cz> writes:
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>
> ---
> testcases/kernel/mem/ksm/ksm06.c | 30 +++++++++++++++---------------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
> index 0f5e4b05d..61507b2aa 100644
> --- a/testcases/kernel/mem/ksm/ksm06.c
> +++ b/testcases/kernel/mem/ksm/ksm06.c
> @@ -1,24 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> /*
> * Copyright (C) 2013-2017 Red Hat, Inc.
> + */
> +/*\
> + * [Description]
> *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation; either version 2 of the License, or
> - * (at your option) any later version.
> + * The case is designed to test sysfs boolean knob
> + * /sys/kernel/mm/ksm/merge_across_nodes.
> *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
> - * the GNU General Public License for more details.
> - */
> -
> -/*
> - * The case is designed to test new sysfs boolean knob
> - * /sys/kernel/mm/ksm/merge_across_nodes, which was introduced by
> - * commit 90bd6fd31c8097ee (ksm: allow trees per NUMA node).
> - * when merge_across_nodes is set to zero only pages from the same
> + * When merge_across_nodes is set to zero only pages from the same
> * node are merged, otherwise pages from all nodes can be merged
> * together.
> + *
> + * Introduced in commit:
> + *
> + * commit 90bd6fd31c8097ee4ddcb74b7e08363134863de5
> + * Author: Petr Holasek <pholasek@redhat.com>
> + * Date: Fri Feb 22 16:35:00 2013 -0800
> + *
> + * ksm: allow trees per NUMA node
> */
>
> #include "config.h"
> --
> 2.34.1
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct
2022-03-03 14:50 [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Cyril Hrubis
` (3 preceding siblings ...)
2022-03-03 14:50 ` [LTP] [PATCH 4/7] mem/ksm06: SPDX + docparse comment Cyril Hrubis
@ 2022-03-03 14:50 ` Cyril Hrubis
2022-03-04 2:27 ` Li Wang
2022-03-03 14:50 ` [LTP] [PATCH 6/7] libs: libltpnuma: Fix free memory estimate Cyril Hrubis
` (2 subsequent siblings)
7 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-03 14:50 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/mem/ksm/ksm06.c | 28 +++-------------------------
1 file changed, 3 insertions(+), 25 deletions(-)
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index 61507b2aa..f5f7319d7 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -39,9 +39,6 @@
#ifdef HAVE_NUMA_V2
#include <numaif.h>
-static int run = -1;
-static int sleep_millisecs = -1;
-static int merge_across_nodes = -1;
static unsigned long nr_pages = 100;
static char *n_opt;
@@ -141,27 +138,6 @@ static void setup(void)
if (n_opt)
nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
-
- /* save the current value */
- SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
- SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
- "%d", &merge_across_nodes);
- SAFE_FILE_SCANF(PATH_KSM "sleep_millisecs",
- "%d", &sleep_millisecs);
-}
-
-static void cleanup(void)
-{
- if (merge_across_nodes != -1) {
- FILE_PRINTF(PATH_KSM "merge_across_nodes",
- "%d", merge_across_nodes);
- }
-
- if (sleep_millisecs != -1)
- FILE_PRINTF(PATH_KSM "sleep_millisecs", "%d", sleep_millisecs);
-
- if (run != -1)
- FILE_PRINTF(PATH_KSM "run", "%d", run);
}
static struct tst_test test = {
@@ -171,9 +147,11 @@ static struct tst_test test = {
{}
},
.setup = setup,
- .cleanup = cleanup,
.save_restore = (const char * const[]) {
"?/sys/kernel/mm/ksm/max_page_sharing",
+ "?/sys/kernel/mm/ksm/run",
+ "?/sys/kernel/mm/ksm/merge_across_nodes",
+ "?/sys/kernel/mm/ksm/sleep_millisecs",
NULL,
},
.test_all = test_ksm,
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct
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
0 siblings, 1 reply; 21+ messages in thread
From: Li Wang @ 2022-03-04 2:27 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 2683 bytes --]
On Thu, Mar 3, 2022 at 10:49 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
> testcases/kernel/mem/ksm/ksm06.c | 28 +++-------------------------
> 1 file changed, 3 insertions(+), 25 deletions(-)
>
> diff --git a/testcases/kernel/mem/ksm/ksm06.c
> b/testcases/kernel/mem/ksm/ksm06.c
> index 61507b2aa..f5f7319d7 100644
> --- a/testcases/kernel/mem/ksm/ksm06.c
> +++ b/testcases/kernel/mem/ksm/ksm06.c
> @@ -39,9 +39,6 @@
> #ifdef HAVE_NUMA_V2
> #include <numaif.h>
>
> -static int run = -1;
> -static int sleep_millisecs = -1;
> -static int merge_across_nodes = -1;
> static unsigned long nr_pages = 100;
>
> static char *n_opt;
> @@ -141,27 +138,6 @@ static void setup(void)
>
> if (n_opt)
> nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
> -
> - /* save the current value */
> - SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
> - SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
> - "%d", &merge_across_nodes);
> - SAFE_FILE_SCANF(PATH_KSM "sleep_millisecs",
> - "%d", &sleep_millisecs);
> -}
> -
> -static void cleanup(void)
> -{
> - if (merge_across_nodes != -1) {
> - FILE_PRINTF(PATH_KSM "merge_across_nodes",
> - "%d", merge_across_nodes);
> - }
> -
> - if (sleep_millisecs != -1)
> - FILE_PRINTF(PATH_KSM "sleep_millisecs", "%d",
> sleep_millisecs);
> -
> - if (run != -1)
> - FILE_PRINTF(PATH_KSM "run", "%d", run);
> }
>
> static struct tst_test test = {
> @@ -171,9 +147,11 @@ static struct tst_test test = {
> {}
> },
> .setup = setup,
> - .cleanup = cleanup,
> .save_restore = (const char * const[]) {
> "?/sys/kernel/mm/ksm/max_page_sharing",
>
The mem library verifies the max_page_sharing validity before
setting because some old kernels do not have it. Thus it is fine
to use the prefix '?'.
+ "?/sys/kernel/mm/ksm/run",
> + "?/sys/kernel/mm/ksm/merge_across_nodes",
> + "?/sys/kernel/mm/ksm/sleep_millisecs",
>
But for the two knobs(run, sleep_millisecs) that should exist unless
the kernel disables KSM. So here we'd better start with prefix '!' and
add .needs_kconfg for ‘CONFIG_KSM=y' check.
(This also fit for other ksm tests)
For 'merge_across_nodes', we don't need any prefix because
ksm06 is actually relying on it, otherwise TCONF is expected.
Thus it's fine to remove the file check from setup() as well.
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 4710 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct
2022-03-04 2:27 ` Li Wang
@ 2022-03-04 12:02 ` Cyril Hrubis
2022-03-07 1:44 ` Li Wang
0 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-04 12:02 UTC (permalink / raw)
To: Li Wang; +Cc: LTP List
Hi!
> The mem library verifies the max_page_sharing validity before
> setting because some old kernels do not have it. Thus it is fine
> to use the prefix '?'.
>
> + "?/sys/kernel/mm/ksm/run",
> > + "?/sys/kernel/mm/ksm/merge_across_nodes",
> > + "?/sys/kernel/mm/ksm/sleep_millisecs",
> >
>
>
> But for the two knobs(run, sleep_millisecs) that should exist unless
> the kernel disables KSM. So here we'd better start with prefix '!' and
> add .needs_kconfg for ???CONFIG_KSM=y' check.
> (This also fit for other ksm tests)
I guess that if we put ! before the merge_across_nodes that would cause
TBROK on systems without CONFIG_NUMA or kernels without that feature.
So what about just removing the question marks there and adding
.need_kconfigs for KSM and NUMA?
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct
2022-03-04 12:02 ` Cyril Hrubis
@ 2022-03-07 1:44 ` Li Wang
2022-03-07 8:58 ` Cyril Hrubis
0 siblings, 1 reply; 21+ messages in thread
From: Li Wang @ 2022-03-07 1:44 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 1159 bytes --]
On Fri, Mar 4, 2022 at 8:00 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> > The mem library verifies the max_page_sharing validity before
> > setting because some old kernels do not have it. Thus it is fine
> > to use the prefix '?'.
> >
> > + "?/sys/kernel/mm/ksm/run",
> > > + "?/sys/kernel/mm/ksm/merge_across_nodes",
> > > + "?/sys/kernel/mm/ksm/sleep_millisecs",
> > >
> >
> >
> > But for the two knobs(run, sleep_millisecs) that should exist unless
> > the kernel disables KSM. So here we'd better start with prefix '!' and
> > add .needs_kconfg for ???CONFIG_KSM=y' check.
> > (This also fit for other ksm tests)
>
> I guess that if we put ! before the merge_across_nodes that would cause
> TBROK on systems without CONFIG_NUMA or kernels without that feature.
>
> So what about just removing the question marks there and adding
> .need_kconfigs for KSM and NUMA?
>
Er, that's exactly what I meant in the last email, maybe you overlooked
the last sentence:).
i.e.
"
prefix ! for 'run' and 'sleep_milisecs'
no prefix for 'merge_across_nodes'
.need_kconfigs for KSM and NUMA
"
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 2471 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct
2022-03-07 1:44 ` Li Wang
@ 2022-03-07 8:58 ` Cyril Hrubis
2022-03-07 9:06 ` Li Wang
0 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-07 8:58 UTC (permalink / raw)
To: Li Wang; +Cc: LTP List
Hi!
> > > But for the two knobs(run, sleep_millisecs) that should exist unless
> > > the kernel disables KSM. So here we'd better start with prefix '!' and
> > > add .needs_kconfg for ???CONFIG_KSM=y' check.
> > > (This also fit for other ksm tests)
> >
> > I guess that if we put ! before the merge_across_nodes that would cause
> > TBROK on systems without CONFIG_NUMA or kernels without that feature.
> >
> > So what about just removing the question marks there and adding
> > .need_kconfigs for KSM and NUMA?
> >
>
> Er, that's exactly what I meant in the last email, maybe you overlooked
> the last sentence:).
>
> i.e.
>
> "
> prefix ! for 'run' and 'sleep_milisecs'
> no prefix for 'merge_across_nodes'
> .need_kconfigs for KSM and NUMA
> "
Ah, right, sorry. What about this:
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index 61507b2aa..e734786c1 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -39,9 +39,6 @@
#ifdef HAVE_NUMA_V2
#include <numaif.h>
-static int run = -1;
-static int sleep_millisecs = -1;
-static int merge_across_nodes = -1;
static unsigned long nr_pages = 100;
static char *n_opt;
@@ -133,35 +130,11 @@ static void test_ksm(void)
static void setup(void)
{
- if (access(PATH_KSM "merge_across_nodes", F_OK) == -1)
- tst_brk(TCONF, "no merge_across_nodes sysfs knob");
-
if (!is_numa(NULL, NH_MEMS, 2))
tst_brk(TCONF, "The case needs a NUMA system.");
if (n_opt)
nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
-
- /* save the current value */
- SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
- SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
- "%d", &merge_across_nodes);
- SAFE_FILE_SCANF(PATH_KSM "sleep_millisecs",
- "%d", &sleep_millisecs);
-}
-
-static void cleanup(void)
-{
- if (merge_across_nodes != -1) {
- FILE_PRINTF(PATH_KSM "merge_across_nodes",
- "%d", merge_across_nodes);
- }
-
- if (sleep_millisecs != -1)
- FILE_PRINTF(PATH_KSM "sleep_millisecs", "%d", sleep_millisecs);
-
- if (run != -1)
- FILE_PRINTF(PATH_KSM "run", "%d", run);
}
static struct tst_test test = {
@@ -171,11 +144,18 @@ static struct tst_test test = {
{}
},
.setup = setup,
- .cleanup = cleanup,
.save_restore = (const char * const[]) {
"?/sys/kernel/mm/ksm/max_page_sharing",
+ "!/sys/kernel/mm/ksm/run",
+ "!/sys/kernel/mm/ksm/sleep_millisecs",
+ "/sys/kernel/mm/ksm/merge_across_nodes",
NULL,
},
+ .needs_kconfigs = (const char *const[]){
+ "CONFIG_KSM=y",
+ "CONFIG_NUMA=y",
+ NULL
+ },
.test_all = test_ksm,
};
If we add merge_across_nodes without any prefix we can as well remove
the check for the file existence in the test setup.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct
2022-03-07 8:58 ` Cyril Hrubis
@ 2022-03-07 9:06 ` Li Wang
2022-03-07 9:13 ` Cyril Hrubis
0 siblings, 1 reply; 21+ messages in thread
From: Li Wang @ 2022-03-07 9:06 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 3358 bytes --]
On Mon, Mar 7, 2022 at 4:56 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> > > > But for the two knobs(run, sleep_millisecs) that should exist unless
> > > > the kernel disables KSM. So here we'd better start with prefix '!'
> and
> > > > add .needs_kconfg for ???CONFIG_KSM=y' check.
> > > > (This also fit for other ksm tests)
> > >
> > > I guess that if we put ! before the merge_across_nodes that would cause
> > > TBROK on systems without CONFIG_NUMA or kernels without that feature.
> > >
> > > So what about just removing the question marks there and adding
> > > .need_kconfigs for KSM and NUMA?
> > >
> >
> > Er, that's exactly what I meant in the last email, maybe you overlooked
> > the last sentence:).
> >
> > i.e.
> >
> > "
> > prefix ! for 'run' and 'sleep_milisecs'
> > no prefix for 'merge_across_nodes'
> > .need_kconfigs for KSM and NUMA
> > "
>
> Ah, right, sorry. What about this:
>
> diff --git a/testcases/kernel/mem/ksm/ksm06.c
> b/testcases/kernel/mem/ksm/ksm06.c
> index 61507b2aa..e734786c1 100644
> --- a/testcases/kernel/mem/ksm/ksm06.c
> +++ b/testcases/kernel/mem/ksm/ksm06.c
> @@ -39,9 +39,6 @@
> #ifdef HAVE_NUMA_V2
> #include <numaif.h>
>
> -static int run = -1;
> -static int sleep_millisecs = -1;
> -static int merge_across_nodes = -1;
> static unsigned long nr_pages = 100;
>
> static char *n_opt;
> @@ -133,35 +130,11 @@ static void test_ksm(void)
>
> static void setup(void)
> {
> - if (access(PATH_KSM "merge_across_nodes", F_OK) == -1)
> - tst_brk(TCONF, "no merge_across_nodes sysfs knob");
> -
> if (!is_numa(NULL, NH_MEMS, 2))
> tst_brk(TCONF, "The case needs a NUMA system.");
>
> if (n_opt)
> nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
> -
> - /* save the current value */
> - SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
> - SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
> - "%d", &merge_across_nodes);
> - SAFE_FILE_SCANF(PATH_KSM "sleep_millisecs",
> - "%d", &sleep_millisecs);
> -}
> -
> -static void cleanup(void)
> -{
> - if (merge_across_nodes != -1) {
> - FILE_PRINTF(PATH_KSM "merge_across_nodes",
> - "%d", merge_across_nodes);
> - }
> -
> - if (sleep_millisecs != -1)
> - FILE_PRINTF(PATH_KSM "sleep_millisecs", "%d",
> sleep_millisecs);
> -
> - if (run != -1)
> - FILE_PRINTF(PATH_KSM "run", "%d", run);
> }
>
> static struct tst_test test = {
> @@ -171,11 +144,18 @@ static struct tst_test test = {
> {}
> },
> .setup = setup,
> - .cleanup = cleanup,
> .save_restore = (const char * const[]) {
> "?/sys/kernel/mm/ksm/max_page_sharing",
> + "!/sys/kernel/mm/ksm/run",
> + "!/sys/kernel/mm/ksm/sleep_millisecs",
> + "/sys/kernel/mm/ksm/merge_across_nodes",
> NULL,
> },
> + .needs_kconfigs = (const char *const[]){
> + "CONFIG_KSM=y",
> + "CONFIG_NUMA=y",
> + NULL
> + },
> .test_all = test_ksm,
> };
>
>
> If we add merge_across_nodes without any prefix we can as well remove
> the check for the file existence in the test setup.
>
ACK.
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 4839 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* [LTP] [PATCH 6/7] libs: libltpnuma: Fix free memory estimate
2022-03-03 14:50 [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Cyril Hrubis
` (4 preceding siblings ...)
2022-03-03 14:50 ` [LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct Cyril Hrubis
@ 2022-03-03 14:50 ` 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-03 15:06 ` [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Petr Vorel
7 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-03 14:50 UTC (permalink / raw)
To: ltp
On long running systems most of the memory would be consumed by a
file page cache which is reclaimable. Because of that the numa test will
be skipped even if the system has plenty of memory. To fix this this
patch adds 90% of the memory used by the page cache to the free memory
estimate.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
libs/libltpnuma/tst_numa.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libs/libltpnuma/tst_numa.c b/libs/libltpnuma/tst_numa.c
index 417d98ced..7b8c4bc79 100644
--- a/libs/libltpnuma/tst_numa.c
+++ b/libs/libltpnuma/tst_numa.c
@@ -129,6 +129,7 @@ static int node_has_enough_memory(int node, size_t min_kb)
char buf[1024];
long mem_total = 0;
long mem_used = 0;
+ long file_pages = 0;
/* Make sure there is some space for kernel upkeeping as well */
min_kb += 4096;
@@ -152,6 +153,9 @@ static int node_has_enough_memory(int node, size_t min_kb)
if (sscanf(buf, "%*s %*i MemUsed: %li", &val) == 1)
mem_used = val;
+
+ if (sscanf(buf, "%*s %*i FilePages: %li", &val) == 1)
+ file_pages = val;
}
fclose(fp);
@@ -161,7 +165,7 @@ static int node_has_enough_memory(int node, size_t min_kb)
return 0;
}
- if (mem_total - mem_used < (long)min_kb) {
+ if (mem_total - mem_used + (9 * file_pages)/10 < (long)min_kb) {
tst_res(TINFO,
"Not enough free RAM on node %i, have %likB needs %zukB",
node, mem_total - mem_used, min_kb);
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 6/7] libs: libltpnuma: Fix free memory estimate
2022-03-03 14:50 ` [LTP] [PATCH 6/7] libs: libltpnuma: Fix free memory estimate Cyril Hrubis
@ 2022-03-04 2:56 ` Li Wang
0 siblings, 0 replies; 21+ messages in thread
From: Li Wang @ 2022-03-04 2:56 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 437 bytes --]
> - if (mem_total - mem_used < (long)min_kb) {
> + if (mem_total - mem_used + (9 * file_pages)/10 < (long)min_kb) {
> tst_res(TINFO,
> "Not enough free RAM on node %i, have %likB needs
> %zukB",
> node, mem_total - mem_used, min_kb);
>
We'd better count that part in the output message as well.
Reviewed-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 1022 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* [LTP] [PATCH 7/7] mem/ksm06: Make use of the new libltpnuma
2022-03-03 14:50 [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Cyril Hrubis
` (5 preceding siblings ...)
2022-03-03 14:50 ` [LTP] [PATCH 6/7] libs: libltpnuma: Fix free memory estimate Cyril Hrubis
@ 2022-03-03 14:50 ` 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
7 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2022-03-03 14:50 UTC (permalink / raw)
To: ltp
THe main benefit is that the new library also makes sure that memory
nodes have enough memory for the test.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/mem/ksm/Makefile | 3 ++
testcases/kernel/mem/ksm/ksm06.c | 72 ++++++++++++++-----------------
2 files changed, 35 insertions(+), 40 deletions(-)
diff --git a/testcases/kernel/mem/ksm/Makefile b/testcases/kernel/mem/ksm/Makefile
index e8ea801bc..236625690 100644
--- a/testcases/kernel/mem/ksm/Makefile
+++ b/testcases/kernel/mem/ksm/Makefile
@@ -3,6 +3,9 @@
top_srcdir ?= ../../../..
+LTPLIBS = ltpnuma
+ksm06: LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index f5f7319d7..80426bbb0 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -34,41 +34,30 @@
#include <limits.h>
#include "mem.h"
-#include "numa_helper.h"
+#include "tst_numa.h"
#ifdef HAVE_NUMA_V2
-#include <numaif.h>
+# include <numa.h>
+# include <numaif.h>
static unsigned long nr_pages = 100;
-
static char *n_opt;
+static size_t page_size;
+static struct tst_nodemap *nodes;
+
static void test_ksm(void)
{
char **memory;
- int i, ret;
- int num_nodes, *nodes;
+ unsigned int i;
+ int ret;
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;
- }
+ struct bitmask *bm = numa_allocate_nodemask();
- pagesize = sysconf(_SC_PAGE_SIZE);
- length = nr_pages * pagesize;
+ length = nr_pages * page_size;
- memory = SAFE_MALLOC(num_nodes * sizeof(char *));
- for (i = 0; i < num_nodes; i++) {
+ memory = SAFE_MALLOC(nodes->cnt * sizeof(char *));
+ for (i = 0; i < nodes->cnt; i++) {
memory[i] = SAFE_MMAP(NULL, length, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
#ifdef HAVE_DECL_MADV_MERGEABLE
@@ -77,15 +66,13 @@ static void test_ksm(void)
#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);
+ numa_bitmask_setbit(bm, nodes->map[i]);
+
+ ret = mbind(memory[i], length, MPOL_BIND, bm->maskp, bm->size+1, 0);
if (ret == -1)
tst_brk(TBROK|TERRNO, "mbind");
+
+ numa_bitmask_clearbit(bm, nodes->map[i]);
#endif
memset(memory[i], 10, length);
@@ -94,9 +81,11 @@ static void test_ksm(void)
tst_res(TWARN | TERRNO, "mlock() failed");
}
+ numa_free_nodemask(bm);
+
SAFE_FILE_PRINTF(PATH_KSM "sleep_millisecs", "0");
SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld",
- nr_pages * num_nodes);
+ nr_pages * nodes->cnt);
/*
* 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
@@ -106,23 +95,23 @@ static void test_ksm(void)
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);
+ "%ld", nr_pages * nodes->cnt);
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);
+ ksm_group_check(1, 1, nr_pages * nodes->cnt - 1, 0, 0, 0,
+ nr_pages * nodes->cnt);
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);
+ ksm_group_check(1, nodes->cnt, nr_pages * nodes->cnt - nodes->cnt,
+ 0, 0, 0, nr_pages * nodes->cnt);
SAFE_FILE_PRINTF(PATH_KSM "run", "2");
- for (i = 0; i < num_nodes; i++)
+ for (i = 0; i < nodes->cnt; i++)
SAFE_MUNMAP(memory[i], length);
free(memory);
@@ -133,11 +122,14 @@ static void setup(void)
if (access(PATH_KSM "merge_across_nodes", F_OK) == -1)
tst_brk(TCONF, "no merge_across_nodes sysfs knob");
- if (!is_numa(NULL, NH_MEMS, 2))
- tst_brk(TCONF, "The case needs a NUMA system.");
-
if (n_opt)
nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
+
+ page_size = getpagesize();
+
+ nodes = tst_get_nodemap(TST_NUMA_MEM, nr_pages * page_size / 1024);
+ if (nodes->cnt <= 1)
+ tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
}
static struct tst_test test = {
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 7/7] mem/ksm06: Make use of the new libltpnuma
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
0 siblings, 0 replies; 21+ messages in thread
From: Li Wang @ 2022-03-04 3:17 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 401 bytes --]
Hi Cyril,
Beside the tiny issues pointed out in [5|6]/7. The remaining
part looks good to me.
That would be awesome if you could help cleanup other ksm
tests at the same time. Or, I help do that separately later on.
(e.g. knob validation, add KSM kconfig, and remove 'merge_across_nodes'
from ksm_common.h)
Anyway, nice cleanup work!
Reviewed-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 1297 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes
2022-03-03 14:50 [LTP] [PATCH 0/7] ksm06 and libnuma cleanups and fixes Cyril Hrubis
` (6 preceding siblings ...)
2022-03-03 14:50 ` [LTP] [PATCH 7/7] mem/ksm06: Make use of the new libltpnuma Cyril Hrubis
@ 2022-03-03 15:06 ` Petr Vorel
7 siblings, 0 replies; 21+ messages in thread
From: Petr Vorel @ 2022-03-03 15:06 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
very nice cleanup. LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread