<div dir="ltr"><div><div>Hi,<br><br></div>After thinking over this change, I feel that do `echo 100000 >'/sys/kernel/mm/ksm/max_page_sharing` as hard-code is a bad idea. Since the case ksm0[1-6].c could also accept different "num" via parameter, it will be failed if we do `./ksm01 -n num` (eg. num >= 6, the pages >= 196608).  <br><br>-------------------<br># ./ksm02 -n 6<br>ksm02       0  TINFO  :  get node0.<br>ksm02       0  TINFO  :  child 0 stops.<br>ksm02       0  TINFO  :  child 1 stops.<br>ksm02       0  TINFO  :  wait for all children to stop.<br>ksm02       0  TINFO  :  child 3 stops.<br>ksm02       0  TINFO  :  child 2 stops.<br>ksm02       0  TINFO  :  child 4 stops.<br>....<br>ksm02       0  TINFO  :  check!<br>ksm02       0  TINFO  :  run is 1.<br>ksm02       0  TINFO  :  pages_shared is 3.<br>ksm02       1  TFAIL  :  mem.c:238: pages_shared is not 2.<br>ksm02       0  TINFO  :  pages_sharing is 196605.<br>ksm02       2  TFAIL  :  mem.c:238: pages_sharing is not 196606.<br>ksm02       0  TINFO  :  pages_volatile is 0.<br>ksm02       0  TINFO  :  pages_unshared is 0.<br>ksm02       0  TINFO  :  sleep_millisecs is 0.<br>ksm02       0  TINFO  :  pages_to_scan is 196608.<br>...<br><br><br>Sorry for my careless, I just use the default value 'num=3' to test my patchV1 and get pass before. A better way to solve the problem is setting the 'max_page_sharing' dynamically in test program.<br><br><br>Patch V2:<br>---------------<br>diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h<br>index 43988fe..019eb46 100644<br>--- a/testcases/kernel/mem/include/mem.h<br>+++ b/testcases/kernel/mem/include/mem.h<br>@@ -43,7 +43,7 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);<br> /* KSM */<br> <br> #define PATH_KSM               "/sys/kernel/mm/ksm/"<br>-<br>+int max_page_sharing;<br> void test_ksm_merge_across_nodes(unsigned long nr_pages);<br> <br> /* THP */<br>diff --git a/testcases/kernel/mem/ksm/ksm01.c b/testcases/kernel/mem/ksm/ksm01.c<br>index b62df06..a352abd 100644<br>--- a/testcases/kernel/mem/ksm/ksm01.c<br>+++ b/testcases/kernel/mem/ksm/ksm01.c<br>@@ -105,6 +105,9 @@ void setup(void)<br>                tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");<br>        if (access(PATH_KSM, F_OK) == -1)<br>                tst_brkm(TCONF, NULL, "KSM configuration is not enabled");<br>+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>+               SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",<br>+                               "%d", &max_page_sharing);<br> <br>        /*<br>         * kernel commit 90bd6fd introduced a new KSM sysfs knob<br>@@ -128,4 +131,8 @@ void cleanup(void)<br>        if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)<br>                FILE_PRINTF(PATH_KSM "merge_across_nodes",<br>                                 "%d", merge_across_nodes);<br>+<br>+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>+               FILE_PRINTF(PATH_KSM "max_page_sharing",<br>+                                "%d", max_page_sharing);<br> }<br><br>...<br><br>diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c<br>index 7b5bb35..ec25ce3 100644<br>--- a/testcases/kernel/mem/lib/mem.c<br>+++ b/testcases/kernel/mem/lib/mem.c<br>@@ -502,6 +502,9 @@ void create_same_memory(int size, int num, int unit)<br>        stop_ksm_children(child, num);<br> <br>        tst_resm(TINFO, "KSM merging...");<br>+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>+               SAFE_FILE_PRINTF(NULL, PATH_KSM "max_page_sharing",<br>+                               "%ld", size * pages * num);<br>        SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");<br>        SAFE_FILE_PRINTF(cleanup, PATH_KSM "pages_to_scan", "%ld",<br>                         size * pages *num);<br><br><br></div><div>Patch V2 result PASS:<br></div><div>------------------------------<br># ./ksm01 -n 30<br>ksm01       0  TINFO  :  child 0 stops.<br>ksm01       0  TINFO  :  child 1 stops.<br>ksm01       0  TINFO  :  child 2 stops.<br>ksm01       0  TINFO  :  child 3 stops.<br>ksm01       0  TINFO  :  child 4 stops.<br>ksm01       0  TINFO  :  child 5 stops.<br>ksm01       0  TINFO  :  child 6 stops.<br>...<br>ksm01       0  TINFO  :  check!<br>ksm01       0  TINFO  :  run is 1.<br>ksm01       0  TINFO  :  pages_shared is 2.<br>ksm01       0  TINFO  :  pages_sharing is 983038.<br>ksm01       0  TINFO  :  pages_volatile is 0.<br>ksm01       0  TINFO  :  pages_unshared is 0.<br>ksm01       0  TINFO  :  sleep_millisecs is 0.<br>ksm01       0  TINFO  :  pages_to_scan is 983040.<br>....<br><br></div><div>Comments welcome, if no objection, I will send PATCH V2 tomorrow.<br></div><div><br></div><div>Regards,<br></div><div>Li Wang<br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 25, 2016 at 4:48 PM, Li Wang <span dir="ltr"><<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This kernel commit (de39e60a6, ksm: introduce ksm_max_page_sharing per page...)<br>
introduced a new KSM sysfs knob '/sys/kernel/mm/ksm/max_page_sharing' in linux-next.<br>
<br>
The runtime value of 'max_page_sharing' will affect pages_shared/pages_sharing,<br>
because this enforces a deduplication limit to avoid the virtual memory rmap lists<br>
to grow too large.<br>
<br>
ltp/ksm0* tests can easily get failures on that kernel like:<br>
-----<br>
ksm01       0  TINFO  :  wait for all children to stop.<br>
ksm01       0  TINFO  :  KSM merging...<br>
ksm01       0  TINFO  :  resume all children.<br>
ksm01       0  TINFO  :  child 2 stops.<br>
...<br>
ksm01       0  TINFO  :  run is 1.<br>
ksm01       0  TINFO  :  pages_shared is 384.<br>
ksm01       1  TFAIL  :  mem.c:238: pages_shared is not 2.<br>
ksm01       0  TINFO  :  pages_sharing is 97920.<br>
ksm01       2  TFAIL  :  mem.c:238: pages_sharing is not 98302.<br>
ksm01       0  TINFO  :  pages_volatile is 0.<br>
ksm01       0  TINFO  :  pages_unshared is 0.<br>
ksm01       0  TINFO  :  sleep_millisecs is 0.<br>
ksm01       0  TINFO  :  pages_to_scan is 98304.<br>
<br>
So, I composed this patch to extend the 'max_page_sharing' value to make tests pass.<br>
<br>
Signed-off-by: Li Wang <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>><br>
---<br>
 testcases/kernel/mem/ksm/ksm01.c | 10 ++++++++++<br>
 testcases/kernel/mem/ksm/ksm02.c | 10 ++++++++++<br>
 testcases/kernel/mem/ksm/ksm03.c | 11 +++++++++++<br>
 testcases/kernel/mem/ksm/ksm04.c | 11 +++++++++++<br>
 testcases/kernel/mem/ksm/ksm06.c | 10 ++++++++++<br>
 5 files changed, 52 insertions(+)<br>
<br>
diff --git a/testcases/kernel/mem/ksm/ksm01.c b/testcases/kernel/mem/ksm/ksm01.c<br>
index b62df06..fccae1c 100644<br>
--- a/testcases/kernel/mem/ksm/ksm01.c<br>
+++ b/testcases/kernel/mem/ksm/ksm01.c<br>
@@ -73,6 +73,7 @@ char *TCID = "ksm01";<br>
 int TST_TOTAL = 1;<br>
<br>
 static int merge_across_nodes;<br>
+static int max_page_sharing;<br>
<br>
 option_t ksm_options[] = {<br>
        {"n:", &opt_num, &opt_numstr},<br>
@@ -105,6 +106,11 @@ void setup(void)<br>
                tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");<br>
        if (access(PATH_KSM, F_OK) == -1)<br>
                tst_brkm(TCONF, NULL, "KSM configuration is not enabled");<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0) {<br>
+               SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",<br>
+                               "%d", &max_page_sharing);<br>
+               SAFE_FILE_PRINTF(NULL, PATH_KSM "max_page_sharing", "100000");<br>
+       }<br>
<br>
        /*<br>
         * kernel commit 90bd6fd introduced a new KSM sysfs knob<br>
@@ -128,4 +134,8 @@ void cleanup(void)<br>
        if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)<br>
                FILE_PRINTF(PATH_KSM "merge_across_nodes",<br>
                                 "%d", merge_across_nodes);<br>
+<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>
+               FILE_PRINTF(PATH_KSM "max_page_sharing",<br>
+                                "%d", max_page_sharing);<br>
 }<br>
diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c<br>
index 537ec01..8ca397a 100644<br>
--- a/testcases/kernel/mem/ksm/ksm02.c<br>
+++ b/testcases/kernel/mem/ksm/ksm02.c<br>
@@ -73,6 +73,7 @@ char *TCID = "ksm02";<br>
 int TST_TOTAL = 1;<br>
<br>
 static int merge_across_nodes;<br>
+static int max_page_sharing;<br>
<br>
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \<br>
        && HAVE_MPOL_CONSTANTS<br>
@@ -125,6 +126,10 @@ void cleanup(void)<br>
                FILE_PRINTF(PATH_KSM "merge_across_nodes",<br>
                                 "%d", merge_across_nodes);<br>
<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>
+               FILE_PRINTF(PATH_KSM "max_page_sharing",<br>
+                               "%d", max_page_sharing);<br>
+<br>
        umount_mem(CPATH, CPATH_NEW);<br>
 }<br>
<br>
@@ -136,6 +141,11 @@ void setup(void)<br>
                tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");<br>
        if (access(PATH_KSM, F_OK) == -1)<br>
                tst_brkm(TCONF, NULL, "KSM configuration is not enabled");<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0) {<br>
+               SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",<br>
+                               "%d", &max_page_sharing);<br>
+               SAFE_FILE_PRINTF(NULL, PATH_KSM "max_page_sharing", "100000");<br>
+       }<br>
<br>
        if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {<br>
                SAFE_FILE_SCANF(NULL, PATH_KSM "merge_across_nodes",<br>
diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c<br>
index b73e023..8670ed8 100644<br>
--- a/testcases/kernel/mem/ksm/ksm03.c<br>
+++ b/testcases/kernel/mem/ksm/ksm03.c<br>
@@ -73,6 +73,7 @@ char *TCID = "ksm03";<br>
 int TST_TOTAL = 1;<br>
<br>
 static int merge_across_nodes;<br>
+static int max_page_sharing;<br>
<br>
 option_t ksm_options[] = {<br>
        {"n:", &opt_num, &opt_numstr},<br>
@@ -113,6 +114,12 @@ void setup(void)<br>
                SAFE_FILE_PRINTF(NULL, PATH_KSM "merge_across_nodes", "1");<br>
        }<br>
<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0) {<br>
+               SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",<br>
+                               "%d", &max_page_sharing);<br>
+               SAFE_FILE_PRINTF(NULL, PATH_KSM "max_page_sharing", "100000");<br>
+       }<br>
+<br>
        mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);<br>
        tst_sig(FORK, DEF_HANDLER, NULL);<br>
        TEST_PAUSE;<br>
@@ -124,5 +131,9 @@ void cleanup(void)<br>
                FILE_PRINTF(PATH_KSM "merge_across_nodes",<br>
                                 "%d", merge_across_nodes);<br>
<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>
+               FILE_PRINTF(PATH_KSM "max_page_sharing",<br>
+                               "%d", max_page_sharing);<br>
+<br>
        umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);<br>
 }<br>
diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c<br>
index 0c1d4e0..15988f7 100644<br>
--- a/testcases/kernel/mem/ksm/ksm04.c<br>
+++ b/testcases/kernel/mem/ksm/ksm04.c<br>
@@ -73,6 +73,7 @@ char *TCID = "ksm04";<br>
 int TST_TOTAL = 1;<br>
<br>
 static int merge_across_nodes;<br>
+static int max_page_sharing;<br>
<br>
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \<br>
        && HAVE_MPOL_CONSTANTS<br>
@@ -127,6 +128,10 @@ void cleanup(void)<br>
                FILE_PRINTF(PATH_KSM "merge_across_nodes",<br>
                                 "%d", merge_across_nodes);<br>
<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>
+               FILE_PRINTF(PATH_KSM "max_page_sharing",<br>
+                               "%d", max_page_sharing);<br>
+<br>
        umount_mem(CPATH, CPATH_NEW);<br>
        umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);<br>
 }<br>
@@ -146,6 +151,12 @@ void setup(void)<br>
                SAFE_FILE_PRINTF(NULL, PATH_KSM "merge_across_nodes", "1");<br>
        }<br>
<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0) {<br>
+               SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",<br>
+                               "%d", &max_page_sharing);<br>
+               SAFE_FILE_PRINTF(NULL, PATH_KSM "max_page_sharing", "100000");<br>
+       }<br>
+<br>
        tst_sig(FORK, DEF_HANDLER, cleanup);<br>
        TEST_PAUSE;<br>
        mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);<br>
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c<br>
index 1cda01f..3d12419 100644<br>
--- a/testcases/kernel/mem/ksm/ksm06.c<br>
+++ b/testcases/kernel/mem/ksm/ksm06.c<br>
@@ -57,6 +57,7 @@ int TST_TOTAL = 1;<br>
 static int run;<br>
 static int sleep_millisecs;<br>
 static int merge_across_nodes;<br>
+static int max_page_sharing;<br>
 static int n_flag;<br>
 static unsigned long nr_pages;<br>
<br>
@@ -104,6 +105,11 @@ void setup(void)<br>
                        "%d", &merge_across_nodes);<br>
        SAFE_FILE_SCANF(NULL, PATH_KSM "sleep_millisecs",<br>
                        "%d", &sleep_millisecs);<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0) {<br>
+               SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",<br>
+                               "%d", &max_page_sharing);<br>
+               SAFE_FILE_PRINTF(NULL, PATH_KSM "max_page_sharing", "100000");<br>
+       }<br>
<br>
        tst_sig(FORK, DEF_HANDLER, cleanup);<br>
        TEST_PAUSE;<br>
@@ -116,6 +122,10 @@ void cleanup(void)<br>
        FILE_PRINTF(PATH_KSM "sleep_millisecs",<br>
                         "%d", sleep_millisecs);<br>
        FILE_PRINTF(PATH_KSM "run", "%d", run);<br>
+<br>
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)<br>
+               FILE_PRINTF(PATH_KSM "max_page_sharing",<br>
+                               "%d", max_page_sharing);<br>
 }<br>
<br>
 static void usage(void)<br>
<span class=""><font color="#888888">--<br>
1.8.3.1<br>
<br>
<br>
--<br>
Mailing list info: <a href="http://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">http://lists.linux.it/listinfo/ltp</a><br>
</font></span></blockquote></div><br></div></div>