Skip to contentSkip to conversation

mm/ksm: taking use of SAFE_FILE_ macro for ksm05.c

PATCH Superseded Li Wang 2 participants 9 messages Mar 10, 2016 – Mar 22, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/4 mm/ksm: taking use of SAFE_FILE_ macro for ksm05.c

---
 testcases/kernel/mem/ksm/ksm05.c | 32 +++-----------------------------
 1 file changed, 3 insertions(+), 29 deletions(-)
testcases/kernel/mem/ksm/ksm05.c +3 -29
index abf888e..2baca3b 100644
@@ -75,7 +75,6 @@ int TST_TOTAL = 1;
 static int ksm_run_orig;
 
 static void sighandler(int sig);
-static void write_ksm_run(int val);
 
 int main(int argc, char *argv[])
 {
@@ -123,25 +122,8 @@ static void sighandler(int sig)
 	_exit((sig == SIGSEGV) ? 0 : sig);
 }
 
-static void write_ksm_run(int val)
-{
-	int fd;
-	char buf[BUFSIZ];
-
-	sprintf(buf, "%d", val);
-	fd = open(PATH_KSM "run", O_WRONLY);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open");
-	if (write(fd, buf, 1) != 1)
-		tst_brkm(TBROK | TERRNO, cleanup, "write");
-	close(fd);
-}
-
 void setup(void)
 {
-	int fd;
-	char buf[BUFSIZ];
-
 	tst_require_root();
 
 	if (tst_kvercmp(2, 6, 32) < 0)
@@ -155,24 +137,16 @@ void setup(void)
 	TEST_PAUSE;
 
 	/* save original /sys/kernel/mm/ksm/run value */
-	fd = open(PATH_KSM "run", O_RDONLY);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open");
-	if (read(fd, buf, 1) != 1)
-		tst_brkm(TBROK | TERRNO, cleanup, "read");
-	close(fd);
-	ksm_run_orig = atoi(buf);
+	SAFE_FILE_SCANF(NULL, PATH_KSM "run", "%d", &ksm_run_orig);
 
 	/* echo 1 > /sys/kernel/mm/ksm/run */
-	if (ksm_run_orig != 1)
-		write_ksm_run(1);
+	SAFE_FILE_PRINTF(NULL, PATH_KSM "run", "1");
 }
 
 void cleanup(void)
 {
 	/* restore /sys/kernel/mm/ksm/run value */
-	if (ksm_run_orig != 1)
-		write_ksm_run(ksm_run_orig);
+	FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
 }
 #else
 int main(void)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/4 mm/ksm: extend 'max_page_sharing' before ksm testing

This kernel commit (de39e60a6, ksm: introduce ksm_max_page_sharing per page...) introduced a new KSM sysfs knob '/sys/kernel/mm/ksm/max_page_sharing' in linux-next.

The runtime value of 'max_page_sharing' will affect pages_shared/pages_sharing, because this enforces a deduplication limit to avoid the virtual memory rmap lists to grow too large.

ltp/ksm0* tests can easily get failures on that kernel like:
-----

ksm01       0  TINFO  :  wait for all children to stop.
ksm01       0  TINFO  :  KSM merging...
ksm01       0  TINFO  :  resume all children.
ksm01       0  TINFO  :  child 2 stops.
...
ksm01       0  TINFO  :  run is 1.
ksm01       0  TINFO  :  pages_shared is 384.
ksm01       1  TFAIL  :  mem.c:238: pages_shared is not 2.
ksm01       0  TINFO  :  pages_sharing is 97920.
ksm01       2  TFAIL  :  mem.c:238: pages_sharing is not 98302.
ksm01       0  TINFO  :  pages_volatile is 0.
ksm01       0  TINFO  :  pages_unshared is 0.
ksm01       0  TINFO  :  sleep_millisecs is 0.
ksm01       0  TINFO  :  pages_to_scan is 98304.

This patch is intened to extend the 'max_page_sharing' value dynamically to make tests pass.

---
 testcases/kernel/mem/include/mem.h | 1 +
 testcases/kernel/mem/ksm/ksm01.c   | 7 +++++++
 testcases/kernel/mem/ksm/ksm02.c   | 7 +++++++
 testcases/kernel/mem/ksm/ksm03.c   | 8 ++++++++
 testcases/kernel/mem/ksm/ksm04.c   | 8 ++++++++
 testcases/kernel/mem/ksm/ksm06.c   | 7 +++++++
 testcases/kernel/mem/lib/mem.c     | 8 +++++++-
 7 files changed, 45 insertions(+), 1 deletion(-)
testcases/kernel/mem/include/mem.h +1 -0
index 43988fe..fbb11b2 100644
@@ -43,6 +43,7 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
 /* KSM */
 
 #define PATH_KSM		"/sys/kernel/mm/ksm/"
+int max_page_sharing;
 
 void test_ksm_merge_across_nodes(unsigned long nr_pages);
 
testcases/kernel/mem/ksm/ksm01.c +7 -0
index b62df06..a352abd 100644
@@ -105,6 +105,9 @@ void setup(void)
 		tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");
 	if (access(PATH_KSM, F_OK) == -1)
 		tst_brkm(TCONF, NULL, "KSM configuration is not enabled");
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+				"%d", &max_page_sharing);
 
 	/*
 	 * kernel commit 90bd6fd introduced a new KSM sysfs knob
@@ -128,4 +131,8 @@ void cleanup(void)
 	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
 		FILE_PRINTF(PATH_KSM "merge_across_nodes",
 				 "%d", merge_across_nodes);
+
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		FILE_PRINTF(PATH_KSM "max_page_sharing",
+				 "%d", max_page_sharing);
 }
testcases/kernel/mem/ksm/ksm02.c +7 -0
index 537ec01..7b004b4 100644
@@ -125,6 +125,10 @@ void cleanup(void)
 		FILE_PRINTF(PATH_KSM "merge_across_nodes",
 				 "%d", merge_across_nodes);
 
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		FILE_PRINTF(PATH_KSM "max_page_sharing",
+				"%d", max_page_sharing);
+
 	umount_mem(CPATH, CPATH_NEW);
 }
 
@@ -136,6 +140,9 @@ void setup(void)
 		tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");
 	if (access(PATH_KSM, F_OK) == -1)
 		tst_brkm(TCONF, NULL, "KSM configuration is not enabled");
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+				"%d", &max_page_sharing);
 
 	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
 		SAFE_FILE_SCANF(NULL, PATH_KSM "merge_across_nodes",
testcases/kernel/mem/ksm/ksm03.c +8 -0
index b73e023..f909294 100644
@@ -113,6 +113,10 @@ void setup(void)
 		SAFE_FILE_PRINTF(NULL, PATH_KSM "merge_across_nodes", "1");
 	}
 
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+				"%d", &max_page_sharing);
+
 	mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
 	tst_sig(FORK, DEF_HANDLER, NULL);
 	TEST_PAUSE;
@@ -124,5 +128,9 @@ void cleanup(void)
 		FILE_PRINTF(PATH_KSM "merge_across_nodes",
 				 "%d", merge_across_nodes);
 
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		FILE_PRINTF(PATH_KSM "max_page_sharing",
+				"%d", max_page_sharing);
+
 	umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
 }
testcases/kernel/mem/ksm/ksm04.c +8 -0
index 0c1d4e0..fe8c640 100644
@@ -127,6 +127,10 @@ void cleanup(void)
 		FILE_PRINTF(PATH_KSM "merge_across_nodes",
 				 "%d", merge_across_nodes);
 
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		FILE_PRINTF(PATH_KSM "max_page_sharing",
+				"%d", max_page_sharing);
+
 	umount_mem(CPATH, CPATH_NEW);
 	umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
 }
@@ -146,6 +150,10 @@ void setup(void)
 		SAFE_FILE_PRINTF(NULL, PATH_KSM "merge_across_nodes", "1");
 	}
 
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+				"%d", &max_page_sharing);
+
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	TEST_PAUSE;
 	mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
testcases/kernel/mem/ksm/ksm06.c +7 -0
index 02d304f..1efb613 100644
@@ -104,6 +104,9 @@ void setup(void)
 			"%d", &merge_across_nodes);
 	SAFE_FILE_SCANF(NULL, PATH_KSM "sleep_millisecs",
 			"%d", &sleep_millisecs);
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+				"%d", &max_page_sharing);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	TEST_PAUSE;
@@ -116,6 +119,10 @@ void cleanup(void)
 	FILE_PRINTF(PATH_KSM "sleep_millisecs",
 			 "%d", sleep_millisecs);
 	FILE_PRINTF(PATH_KSM "run", "%d", run);
+
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		FILE_PRINTF(PATH_KSM "max_page_sharing",
+				"%d", max_page_sharing);
 }
 
 static void usage(void)
testcases/kernel/mem/lib/mem.c +7 -1
index 7b5bb35..d37d6a4 100644
@@ -502,9 +502,12 @@ void create_same_memory(int size, int num, int unit)
 	stop_ksm_children(child, num);
 
 	tst_resm(TINFO, "KSM merging...");
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_PRINTF(cleanup, PATH_KSM "max_page_sharing",
+				"%ld", size * pages * num);
 	SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
 	SAFE_FILE_PRINTF(cleanup, PATH_KSM "pages_to_scan", "%ld",
-			 size * pages *num);
+			 size * pages * num);
 	SAFE_FILE_PRINTF(cleanup, PATH_KSM "sleep_millisecs", "0");
 
 	resume_ksm_children(child, num);
@@ -595,6 +598,9 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages)
 	SAFE_FILE_PRINTF(cleanup, PATH_KSM "sleep_millisecs", "0");
 	SAFE_FILE_PRINTF(cleanup, PATH_KSM "pages_to_scan", "%ld",
 			 nr_pages * num_nodes);
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_PRINTF(cleanup, PATH_KSM "max_page_sharing",
+			"%ld", nr_pages * num_nodes);
 	/*
 	 * merge_across_nodes setting can be changed only when there
 	 * are no ksm shared pages in system, so set run 2 to unmerge
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 3/4 mm/ksm: moving the merge_across_nodes statement in mem.h

The mem.c take use of this value, so that would be better to declear it in mem.h.

---
 testcases/kernel/mem/include/mem.h | 1 +
 testcases/kernel/mem/ksm/ksm01.c   | 2 --
 testcases/kernel/mem/ksm/ksm02.c   | 2 --
 testcases/kernel/mem/ksm/ksm03.c   | 2 --
 testcases/kernel/mem/ksm/ksm04.c   | 2 --
 testcases/kernel/mem/ksm/ksm06.c   | 1 -
 6 files changed, 1 insertion(+), 9 deletions(-)
testcases/kernel/mem/include/mem.h +1 -0
index fbb11b2..18388ee 100644
@@ -44,6 +44,7 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
 
 #define PATH_KSM		"/sys/kernel/mm/ksm/"
 int max_page_sharing;
+int merge_across_nodes;
 
 void test_ksm_merge_across_nodes(unsigned long nr_pages);
 
testcases/kernel/mem/ksm/ksm01.c +0 -2
index a352abd..b37cfbf 100644
@@ -72,8 +72,6 @@
 char *TCID = "ksm01";
 int TST_TOTAL = 1;
 
-static int merge_across_nodes;
-
 option_t ksm_options[] = {
 	{"n:", &opt_num, &opt_numstr},
 	{"s:", &opt_size, &opt_sizestr},
testcases/kernel/mem/ksm/ksm02.c +0 -2
index 7b004b4..5429b3c 100644
@@ -72,8 +72,6 @@
 char *TCID = "ksm02";
 int TST_TOTAL = 1;
 
-static int merge_across_nodes;
-
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
 option_t ksm_options[] = {
testcases/kernel/mem/ksm/ksm03.c +0 -2
index f909294..ab03f47 100644
@@ -72,8 +72,6 @@
 char *TCID = "ksm03";
 int TST_TOTAL = 1;
 
-static int merge_across_nodes;
-
 option_t ksm_options[] = {
 	{"n:", &opt_num, &opt_numstr},
 	{"s:", &opt_size, &opt_sizestr},
testcases/kernel/mem/ksm/ksm04.c +0 -2
index fe8c640..4272207 100644
@@ -72,8 +72,6 @@
 char *TCID = "ksm04";
 int TST_TOTAL = 1;
 
-static int merge_across_nodes;
-
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
 option_t ksm_options[] = {
testcases/kernel/mem/ksm/ksm06.c +0 -1
index 1efb613..3adcb81 100644
@@ -56,7 +56,6 @@ int TST_TOTAL = 1;
 
 static int run;
 static int sleep_millisecs;
-static int merge_across_nodes;
 static int n_flag;
 static unsigned long nr_pages;
 
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH 4/4 mm/oom: enable ksm before OOM-KSM testing

In the alloc_mem() function, the memory flag is set to 'MADV_MERGEABLE',

	if (testcase == KSM && madvise(s, length, MADV_MERGEABLE) == -1)
			return errno;

But it still doesn't send the whole item for test, unless the ksm is enabled.

Generally, the '../ksm/run' default is 0, it should be changed to 1 to activate ksm.

---
 testcases/kernel/mem/include/mem.h | 1 +
 testcases/kernel/mem/ksm/ksm05.c   | 2 --
 testcases/kernel/mem/lib/mem.c     | 3 +++
 3 files changed, 4 insertions(+), 2 deletions(-)
testcases/kernel/mem/include/mem.h +1 -0
index 18388ee..9dea888 100644
@@ -43,6 +43,7 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
 /* KSM */
 
 #define PATH_KSM		"/sys/kernel/mm/ksm/"
+int ksm_run_orig;
 int max_page_sharing;
 int merge_across_nodes;
 
testcases/kernel/mem/ksm/ksm05.c +0 -2
index 2baca3b..4037ff3 100644
@@ -72,8 +72,6 @@ int TST_TOTAL = 1;
 
 #ifdef HAVE_MADV_MERGEABLE
 
-static int ksm_run_orig;
-
 static void sighandler(int sig);
 
 int main(int argc, char *argv[])
testcases/kernel/mem/lib/mem.c +3 -0
index d37d6a4..0ecde55 100644
@@ -224,7 +224,10 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)
 			 "skip OOM test for KSM pags");
 	} else {
 		tst_resm(TINFO, "start OOM testing for KSM pages.");
+		SAFE_FILE_SCANF(NULL, PATH_KSM "run", "%d", &ksm_run_orig);
+		SAFE_FILE_PRINTF(NULL, PATH_KSM "run", "1");
 		oom(KSM, lite, retcode, allow_sigkill);
+		FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
 	}
 }
 
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 2/4 mm/ksm: extend 'max_page_sharing' before ksm testing

In reply to Li Wang

testcases/kernel/mem/include/mem.h void testoom(int mempolicy, int lite, int retcode, int allow_sigkill); · line 46

Quoted 9 lines
testcases/kernel/mem/include/mem.h +1 -0
index 43988fe..fbb11b2 100644
@@ -43,6 +43,7 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
 /* KSM */
 
 #define PATH_KSM		"/sys/kernel/mm/ksm/"
+int max_page_sharing;

This variable is not used in the library. It does not make sense to declare it in the header file.

Quoted 17 lines
testcases/kernel/mem/include/mem.h +0 -0
 void test_ksm_merge_across_nodes(unsigned long nr_pages);
 
testcases/kernel/mem/ksm/ksm01.c +3 -0
index b62df06..a352abd 100644
@@ -105,6 +105,9 @@ void setup(void)
 		tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");
 	if (access(PATH_KSM, F_OK) == -1)
 		tst_brkm(TCONF, NULL, "KSM configuration is not enabled");
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+				"%d", &max_page_sharing);
 
 	/*
 	 * kernel commit 90bd6fd introduced a new KSM sysfs knob

testcases/kernel/mem/ksm/ksm01.c void cleanup(void) · line 138

Quoted 8 lines
testcases/kernel/mem/ksm/ksm01.c +4 -0
@@ -128,4 +131,8 @@ void cleanup(void)
 	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
 		FILE_PRINTF(PATH_KSM "merge_across_nodes",
 				 "%d", merge_across_nodes);
+
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		FILE_PRINTF(PATH_KSM "max_page_sharing",
+				 "%d", max_page_sharing);
 }

You are saving and restoring the file in each test. Why can't you just add two functions to save and restore it the library instead and call them from test setup and cleanup?

It's also quite confusing that the test saves and restores a value while it's not modifying it at all. It will be less confusing if it's all done in the library.

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

PATCH 3/4 mm/ksm: moving the merge_across_nodes statement in mem.h

In reply to Li Wang

Hi!

Quoted 2 lines

The mem.c take use of this value, so that would be better to declear it in mem.h.

No it does not. If you grep lib/mem.c the only place where this name appears is inside of a string and comment.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH 4/4 mm/oom: enable ksm before OOM-KSM testing

In reply to Li Wang

Hi!

Quoted 1 line

+int ksm_run_orig;

This should be declared as local variable in the testoom() function.

testcases/kernel/mem/ksm/ksm05.c int TST_TOTAL = 1; · line 76

Quoted 13 lines

int max_page_sharing;
int merge_across_nodes;

testcases/kernel/mem/ksm/ksm05.c +0 -2
index 2baca3b..4037ff3 100644
@@ -72,8 +72,6 @@ int TST_TOTAL = 1;
 
 #ifdef HAVE_MADV_MERGEABLE
 
-static int ksm_run_orig;
-

And this shouldn't be touched at all.

Quoted 17 lines
testcases/kernel/mem/ksm/ksm05.c +0 -0
 static void sighandler(int sig);
 
 int main(int argc, char *argv[])
testcases/kernel/mem/lib/mem.c +3 -0
index d37d6a4..0ecde55 100644
@@ -224,7 +224,10 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)
 			 "skip OOM test for KSM pags");
 	} else {
 		tst_resm(TINFO, "start OOM testing for KSM pages.");
+		SAFE_FILE_SCANF(NULL, PATH_KSM "run", "%d", &ksm_run_orig);
+		SAFE_FILE_PRINTF(NULL, PATH_KSM "run", "1");
 		oom(KSM, lite, retcode, allow_sigkill);
+		FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
 	}
 }
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#7 lore raw

PATCH 2/4 mm/ksm: extend 'max_page_sharing' before ksm testing

In reply to Cyril Hrubis

Hi Cyril,

Quoted 7 lines · Cyril Hrubis

Review

Quoted 1 line
(quoted diff) +0 -0

b/testcases/kernel/mem/include/mem.h

testcases/kernel/mem/include/mem.h void testoom(int mempolicy, int lite, int retcode, int

Quoted 4 lines

index 43988fe..fbb11b2 100644

testcases/kernel/mem/include/mem.h +0 -0
@@ -43,6 +43,7 @@ void testoom(int mempolicy, int lite, int retcode, int

allow_sigkill);

Quoted 8 lines

testcases/kernel/mem/include/mem.h void testoom(int mempolicy, int lite, int retcode, int · line 46

Quoted 4 lines
testcases/kernel/mem/include/mem.h +1 -0
 /* KSM */
 
 #define PATH_KSM             "/sys/kernel/mm/ksm/"
+int max_page_sharing;

This variable is not used in the library. It does not make sense to declare it in the header file.

no, it has been used in mem.c file.

see here:
------------

(quoted diff) +0 -0

mem.c b/testcases/kernel/mem/lib/mem.c
index 7b5bb35..d37d6a4 100644

testcases/kernel/mem/lib/mem.c +7 -1
@@ -502,9 +502,12 @@ void create_same_memory(int size, int num, int unit)
        stop_ksm_children(child, num);
 
        tst_resm(TINFO, "KSM merging...");
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+               SAFE_FILE_PRINTF(cleanup, PATH_KSM "max_page_sharing",
+                               "%ld", size * pages * num);
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "pages_to_scan", "%ld",
-                        size * pages *num);
+                        size * pages * num);
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "sleep_millisecs", "0");
 
        resume_ksm_children(child, num);
@@ -595,6 +598,9 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages)
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "sleep_millisecs", "0");
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "pages_to_scan", "%ld",
                         nr_pages * num_nodes);
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+               SAFE_FILE_PRINTF(cleanup, PATH_KSM "max_page_sharing",
+                       "%ld", nr_pages * num_nodes);
 
 
 
Quoted 15 lines

Review

Quoted 3 lines
testcases/kernel/mem/include/mem.h +0 -0
 void test_ksm_merge_across_nodes(unsigned long nr_pages);
 
(quoted diff) +0 -0

b/testcases/kernel/mem/ksm/ksm01.c

Quoted 11 lines

index b62df06..a352abd 100644

testcases/kernel/mem/ksm/ksm01.c +3 -0
@@ -105,6 +105,9 @@ void setup(void)
              tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");
      if (access(PATH_KSM, F_OK) == -1)
              tst_brkm(TCONF, NULL, "KSM configuration is not enabled");
+     if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+             SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+                             "%d", &max_page_sharing);
 
Quoted 16 lines

testcases/kernel/mem/ksm/ksm01.c void cleanup(void) · line 138

Quoted 11 lines
testcases/kernel/mem/ksm/ksm01.c +4 -0
      /*
       * kernel commit 90bd6fd introduced a new KSM sysfs knob
@@ -128,4 +131,8 @@ void cleanup(void)
      if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
              FILE_PRINTF(PATH_KSM "merge_across_nodes",
                               "%d", merge_across_nodes);
+
+     if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+             FILE_PRINTF(PATH_KSM "max_page_sharing",
+                              "%d", max_page_sharing);
 }

You are saving and restoring the file in each test. Why can't you just add two functions to save and restore it the library instead and call them from test setup and cleanup?

ok, that's a better way.

Quoted 9 lines

It's also quite confusing that the test saves and restores a value while it's not modifying it at all. It will be less confusing if it's all done in the library.

--
Cyril Hrubis
[email protected]

Signature · 6 lines
Regards,
Li Wang
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20160322/b998aff0/attachment.html>
author
#8 lore raw

PATCH 2/4 mm/ksm: extend 'max_page_sharing' before ksm testing

Quoted 13 lines · Li Wang

Hi Cyril,

Quoted 9 lines · Cyril Hrubis

Review

Quoted 1 line
(quoted diff) +0 -0

b/testcases/kernel/mem/include/mem.h

testcases/kernel/mem/include/mem.h void testoom(int mempolicy, int lite, int retcode,

Quoted 4 lines

index 43988fe..fbb11b2 100644

testcases/kernel/mem/include/mem.h +0 -0
@@ -43,6 +43,7 @@ void testoom(int mempolicy, int lite, int retcode,

int allow_sigkill);

Quoted 2 lines
testcases/kernel/mem/include/mem.h +0 -0
 /* KSM */
 
Quoted 9 lines
Quoted 6 lines

testcases/kernel/mem/include/mem.h void testoom(int mempolicy, int lite, int retcode, · line 46

Quoted 2 lines
testcases/kernel/mem/include/mem.h +1 -0
 #define PATH_KSM             "/sys/kernel/mm/ksm/"
+int max_page_sharing;

This variable is not used in the library. It does not make sense to declare it in the header file.

no, it has been used in mem.c file.

Oops! you are right, I didn't noticed that it just a string(not the value) in the mem.c codes. sorry for making noise here. I will re-write the patches.

Quoted 86 lines

see here:
------------

(quoted diff) +0 -0

mem.c b/testcases/kernel/mem/lib/mem.c
index 7b5bb35..d37d6a4 100644

testcases/kernel/mem/lib/mem.c +7 -1
@@ -502,9 +502,12 @@ void create_same_memory(int size, int num, int unit)
        stop_ksm_children(child, num);
 
        tst_resm(TINFO, "KSM merging...");
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+               SAFE_FILE_PRINTF(cleanup, PATH_KSM "max_page_sharing",
+                               "%ld", size * pages * num);
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "run", "1");
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "pages_to_scan", "%ld",
-                        size * pages *num);
+                        size * pages * num);
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "sleep_millisecs", "0");
 
        resume_ksm_children(child, num);
@@ -595,6 +598,9 @@ void test_ksm_merge_across_nodes(unsigned long
 nr_pages)
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "sleep_millisecs", "0");
        SAFE_FILE_PRINTF(cleanup, PATH_KSM "pages_to_scan", "%ld",
                         nr_pages * num_nodes);
+       if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+               SAFE_FILE_PRINTF(cleanup, PATH_KSM "max_page_sharing",
+                       "%ld", nr_pages * num_nodes);
 
 
Quoted 17 lines

Review

Quoted 4 lines
testcases/kernel/mem/include/mem.h +0 -0
 void test_ksm_merge_across_nodes(unsigned long nr_pages);
 
(quoted diff) +0 -0

b/testcases/kernel/mem/ksm/ksm01.c

testcases/kernel/mem/ksm/ksm01.c void setup(void) · line 105

Quoted 5 lines

index b62df06..a352abd 100644

testcases/kernel/mem/ksm/ksm01.c +0 -0
@@ -105,6 +105,9 @@ void setup(void)
              tst_brkm(TCONF, NULL, "2.6.32 or greater kernel

required");

Quoted 6 lines
testcases/kernel/mem/ksm/ksm01.c +3 -0
      if (access(PATH_KSM, F_OK) == -1)
              tst_brkm(TCONF, NULL, "KSM configuration is not enabled");
+     if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+             SAFE_FILE_SCANF(NULL, PATH_KSM "max_page_sharing",
+                             "%d", &max_page_sharing);
 
Quoted 16 lines

testcases/kernel/mem/ksm/ksm01.c void cleanup(void) · line 138

Quoted 11 lines
testcases/kernel/mem/ksm/ksm01.c +4 -0
      /*
       * kernel commit 90bd6fd introduced a new KSM sysfs knob
@@ -128,4 +131,8 @@ void cleanup(void)
      if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
              FILE_PRINTF(PATH_KSM "merge_across_nodes",
                               "%d", merge_across_nodes);
+
+     if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+             FILE_PRINTF(PATH_KSM "max_page_sharing",
+                              "%d", max_page_sharing);
 }

You are saving and restoring the file in each test. Why can't you just add two functions to save and restore it the library instead and call them from test setup and cleanup?

ok, that's a better way.

Quoted 9 lines

It's also quite confusing that the test saves and restores a value while it's not modifying it at all. It will be less confusing if it's all done in the library.

--
Cyril Hrubis
[email protected]

--
Regards,
Li Wang
Email: [email protected]

Signature · 6 lines
Regards,
Li Wang
Email: [email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20160322/f174172d/attachment-0001.html>