public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/5] mm/oom: extend the coverage of OOM
@ 2013-03-14 16:21 Zhouping Liu
  2013-03-14 16:21 ` [LTP] [PATCH 1/5] lib/mem: modified _gather_cpus() as _gather_node_cpus() Zhouping Liu
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Zhouping Liu @ 2013-03-14 16:21 UTC (permalink / raw)
  To: LTP List

The patch set updated all OOM testcases, and added a new testcase.

Inside old version, OOM only test MPOL_MBIND mempolicy in NUMA
system, and the combination of CPUSET, MEMCG & NUMA is complex,
and not clear. Also CPUSET is only used in NUMA system.

The patch set adjust them, now we can coverage the below tests:
 1) OOM under normal - oom01
 2) OOM under all mempolicy - oom02
 3) OOM under MEMCG - oom03
 4) OOM under CPUSET - oom04
 5) OOM under CPUSET & MEMCG - oom05

I have tested the patch set, no any regressions found.

Zhouping Liu (5):
  lib/mem: modified _gather_cpus() as _gather_node_cpus()
  mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy'
  mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG &
    numa'
  lib/mem: updated testoom() and oom() funcs
  mm/oom05: new testcase

 runtest/mm                         |   1 +
 testcases/kernel/mem/include/mem.h |   6 +-
 testcases/kernel/mem/lib/mem.c     | 101 ++++++++++++++++++-------
 testcases/kernel/mem/oom/oom01.c   |   6 +-
 testcases/kernel/mem/oom/oom02.c   |  20 +++--
 testcases/kernel/mem/oom/oom03.c   |  28 ++++++-
 testcases/kernel/mem/oom/oom04.c   |  63 +++++++---------
 testcases/kernel/mem/oom/oom05.c   | 151 +++++++++++++++++++++++++++++++++++++
 8 files changed, 296 insertions(+), 80 deletions(-)
 create mode 100644 testcases/kernel/mem/oom/oom05.c

-- 
1.7.11.7


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [LTP] [PATCH 1/5] lib/mem: modified _gather_cpus() as _gather_node_cpus()
  2013-03-14 16:21 [LTP] [PATCH 0/5] mm/oom: extend the coverage of OOM Zhouping Liu
@ 2013-03-14 16:21 ` Zhouping Liu
  2013-03-14 16:45   ` chrubis
  2013-03-14 16:21 ` [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy' Zhouping Liu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Zhouping Liu @ 2013-03-14 16:21 UTC (permalink / raw)
  To: LTP List

The previous _gather_cpus() tried to collect all the specified
node's cpus, but it didn't pay attention to the offline cpus,
if one cpu in the specified node were offline, it can't write
the cpu number to cgroups/*.cpus, and return -EINVAL.

The patch fixed it, and modified the function name, as the new
name make more sense.

Signed-off-by: Zhouping Liu <zliu@redhat.com>
---
 testcases/kernel/mem/lib/mem.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index a827b25..29de64a 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -481,20 +481,42 @@ void ksm_usage(void)
 
 /* cpuset/memcg */
 
-static void _gather_cpus(char *cpus, long nd)
+static void _gather_node_cpus(char *cpus, long nd)
 {
 	int ncpus = 0;
-	int i;
+	int fd, i;
+	long online;
 	char buf[BUFSIZ];
+	char path[BUFSIZ], path1[BUFSIZ];
 
 	while (path_exist(PATH_SYS_SYSTEM "/cpu/cpu%d", ncpus))
 		ncpus++;
 
-	for (i = 0; i < ncpus; i++)
-		if (path_exist(PATH_SYS_SYSTEM "/node/node%ld/cpu%d", nd, i)) {
+	for (i = 0; i < ncpus; i++) {
+		snprintf(path, BUFSIZ,
+			 PATH_SYS_SYSTEM "/node/node%ld/cpu%d", nd, i);
+		if (path_exist(path, nd, i)) {
+			snprintf(path1, BUFSIZ, "%s/online", path);
+			/*
+			 * No cpu0/online knob, as it can't support to
+			 * on/offline cpu0, so if the 'nd' node contains
+			 * cpu0, it should skip to check cpu0/online's value.
+			 */
+			if (i == 0)
+				goto  next;
+			fd = open(path1, O_RDONLY);
+			if (fd == -1)
+				tst_brkm(TBROK|TERRNO, cleanup,
+					 "open %s", path1);
+			read_file(path1, buf);
+			online = SAFE_STRTOL(cleanup, buf, 0, 1);
+			if (online == 0)
+				continue;
+next:
 			sprintf(buf, "%d,", i);
 			strcat(cpus, buf);
 		}
+	}
 	/* Remove the trailing comma. */
 	cpus[strlen(cpus) - 1] = '\0';
 }
@@ -563,7 +585,7 @@ void write_cpusets(long nd)
 	snprintf(buf, BUFSIZ, "%ld", nd);
 	write_cpuset_files(CPATH_NEW, "mems", buf);
 
-	_gather_cpus(cpus, nd);
+	_gather_node_cpus(cpus, nd);
 	write_cpuset_files(CPATH_NEW, "cpus", cpus);
 
 	snprintf(buf, BUFSIZ, "%d", getpid());
-- 
1.7.11.7


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy'
  2013-03-14 16:21 [LTP] [PATCH 0/5] mm/oom: extend the coverage of OOM Zhouping Liu
  2013-03-14 16:21 ` [LTP] [PATCH 1/5] lib/mem: modified _gather_cpus() as _gather_node_cpus() Zhouping Liu
@ 2013-03-14 16:21 ` Zhouping Liu
  2013-03-15  3:09   ` Caspar Zhang
  2013-03-14 16:21 ` [LTP] [PATCH 3/5] mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG & numa' Zhouping Liu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Zhouping Liu @ 2013-03-14 16:21 UTC (permalink / raw)
  To: LTP List

NUMA mechanism can be interpreted as 'memory policy', there are
several mempolicys, such as MPOL_BIND, MPOL_INTERLEAVE,
MPOL_PREFERRED etc, not only MPOL_BIND, so the patch extended OOM
on NUMA system, added MPOL_INTERLEAVE and MPOL_PREFERRED mempolicy.

And the patch also moved 'set_mempolicy()' from child process, and
made it executed inside testoom() func, which is easy to control.

Signed-off-by: Zhouping Liu <zliu@redhat.com>
---
 testcases/kernel/mem/lib/mem.c   | 56 ++++++++++++++++++++++++++++------------
 testcases/kernel/mem/oom/oom02.c | 20 +++++++++-----
 2 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 29de64a..a71bc90 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -64,32 +64,17 @@ void oom(int testcase, int mempolicy, int lite)
 {
 	pid_t pid;
 	int status;
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
-	unsigned long nmask = 0;
-	unsigned int node;
-
-	if (mempolicy)
-		node = get_a_numa_node(cleanup);
-	nmask += 1 << node;
-#endif
 
 	switch (pid = fork()) {
 	case -1:
 		tst_brkm(TBROK | TERRNO, cleanup, "fork");
 	case 0:
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
-		if (mempolicy)
-			if (set_mempolicy(MPOL_BIND, &nmask, MAXNODES) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "set_mempolicy");
-#endif
 		_test_alloc(testcase, lite);
 		exit(0);
 	default:
 		break;
 	}
+
 	tst_resm(TINFO, "expected victim is %d.", pid);
 	if (waitpid(-1, &status, 0) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
@@ -107,7 +92,44 @@ void oom(int testcase, int mempolicy, int lite)
 
 void testoom(int mempolicy, int lite, int numa)
 {
-	long nodes[MAXNODES];
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+	&& HAVE_MPOL_CONSTANTS
+	unsigned long nmask = 0;
+	unsigned int num_nodes, nodes[MAXNODES];
+	int ret;
+
+	if (mempolicy) {
+		ret = get_allowed_nodes_arr(NH_MEMS|NH_CPUS, &num_nodes, &nodes);
+		if (ret != 0)
+			tst_brkm(TBROK|TERRNO, cleanup,
+				 "get_allowed_nodes_arr");
+		if (num_nodes < 2) {
+			tst_resm(TINFO, "mempolicy need NUMA system support");
+			return;
+		}
+		switch(mempolicy) {
+		case MPOL_BIND:
+			/* bind the second node */
+			nmask = 1 << nodes[1];
+			break;
+		case MPOL_INTERLEAVE:
+		case MPOL_PREFERRED:
+			if (num_nodes == 2) {
+				tst_resm(TINFO, "The mempolicy need "
+					 "more than 2 numa nodes");
+				return;
+			} else {
+				/* Using the 2nd,3rd node */
+				nmask = (1 << nodes[1]) | (1 << nodes[2]);
+			}
+			break;
+		default:
+			tst_brkm(TBROK|TERRNO, cleanup, "Bad mempolicy mode");
+		}
+		if (set_mempolicy(mempolicy, &nmask, MAXNODES) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "set_mempolicy");
+	}
+#endif
 
 	if (numa && !mempolicy)
 		write_cpusets(get_a_numa_node(cleanup));
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index abd8aa2..31ec73f 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -1,5 +1,5 @@
 /*
- * Out Of Memory (OOM) for NUMA
+ * Out Of Memory (OOM) for mempolicy - need NUMA system support
  *
  * The program is designed to cope with unpredictable like amount and
  * system physical memory, swap size and other VMM technology like KSM,
@@ -44,6 +44,8 @@ int TST_TOTAL = 1;
 
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
+#include <numaif.h>
+
 int main(int argc, char *argv[])
 {
 	char *msg;
@@ -62,11 +64,14 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		tst_resm(TINFO, "process mempolicy.");
-		testoom(1, 0, 1);
+		tst_resm(TINFO, "OOM on MPOL_BIND mempolicy...");
+		testoom(MPOL_BIND, 0, 1);
+
+		tst_resm(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
+		testoom(MPOL_INTERLEAVE, 0, 1);
 
-		tst_resm(TINFO, "process cpuset.");
-		testoom(0, 0, 1);
+		tst_resm(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
+		testoom(MPOL_PREFERRED, 0, 1);
 	}
 	cleanup();
 	tst_exit();
@@ -78,15 +83,16 @@ void setup(void)
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	TEST_PAUSE;
 
+	/* Judge a NUMA system through get_a_numa_node */
+	get_a_numa_node(NULL);
+
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
-	mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
 }
 
 void cleanup(void)
 {
 	set_sys_tune("overcommit_memory", overcommit, 0);
-	umount_mem(CPATH, CPATH_NEW);
 
 	TEST_CLEANUP;
 }
-- 
1.7.11.7


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [LTP] [PATCH 3/5] mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG & numa'
  2013-03-14 16:21 [LTP] [PATCH 0/5] mm/oom: extend the coverage of OOM Zhouping Liu
  2013-03-14 16:21 ` [LTP] [PATCH 1/5] lib/mem: modified _gather_cpus() as _gather_node_cpus() Zhouping Liu
  2013-03-14 16:21 ` [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy' Zhouping Liu
@ 2013-03-14 16:21 ` Zhouping Liu
  2013-03-14 16:51   ` chrubis
  2013-03-14 16:21 ` [LTP] [PATCH 4/5] lib/mem: updated testoom() and oom() funcs Zhouping Liu
  2013-03-14 16:21 ` [LTP] [PATCH 5/5] mm/oom05: new testcase Zhouping Liu
  4 siblings, 1 reply; 12+ messages in thread
From: Zhouping Liu @ 2013-03-14 16:21 UTC (permalink / raw)
  To: LTP List

OOM with the combination of memcg & numa was moved to oom03,
and the case is re-design to be used to test OOM with CPUSET.

The patch also introduce a new global var ISNUMA, which
is easily used to recognize a NUMA system.

Signed-off-by: Zhouping Liu <zliu@redhat.com>
---
 testcases/kernel/mem/include/mem.h |  2 ++
 testcases/kernel/mem/lib/mem.c     |  2 ++
 testcases/kernel/mem/oom/oom03.c   | 24 +++++++++++++++
 testcases/kernel/mem/oom/oom04.c   | 63 ++++++++++++++++----------------------
 4 files changed, 54 insertions(+), 37 deletions(-)

diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 1233493..de51838 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -24,6 +24,8 @@
 #define MLOCK			3
 #define KSM			4
 
+extern int ISNUMA;
+
 long overcommit;
 void oom(int testcase, int mempolicy, int lite);
 void testoom(int mempolicy, int lite, int numa);
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index a71bc90..e99dae7 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -24,6 +24,8 @@
 #include "mem.h"
 #include "numa_helper.h"
 
+int ISNUMA = 0; /* mark a NUMA system */
+
 /* OOM */
 
 static int _alloc_mem(long int length, int testcase)
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index 95e34d5..4365c2b 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -40,6 +40,10 @@
 char *TCID = "oom03";
 int TST_TOTAL = 1;
 
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+	&& HAVE_MPOL_CONSTANTS
+#include <numaif.h>
+
 int main(int argc, char *argv[])
 {
 	char *msg;
@@ -76,6 +80,14 @@ int main(int argc, char *argv[])
 			write_file(MEMCG_SW_LIMIT, mem);
 			testoom(0, 1, 0);
 		}
+
+		/* OOM for MEMCG with mempolicy */
+		if (ISNUMA) {
+			tst_resm(TINFO, "OOM on MEMCG & mempolicy...");
+			testoom(MPOL_BIND, 0, 1);
+			testoom(MPOL_INTERLEAVE, 0, 1);
+			testoom(MPOL_PREFERRED, 0, 1);
+		}
 	}
 	cleanup();
 	tst_exit();
@@ -87,6 +99,10 @@ void setup(void)
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 	TEST_PAUSE;
 
+	/* rough estimate a NUMA system by max_node id */
+	if (numa_max_node() > 0)
+		ISNUMA = 1;
+
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
 	mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
@@ -99,3 +115,11 @@ void cleanup(void)
 
 	TEST_CLEANUP;
 }
+
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
+}
+#endif
+
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index bc51046..6acc783 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -1,5 +1,5 @@
 /*
- * Out Of Memory (OOM) for Memory Resource Controller and NUMA
+ * Out Of Memory (OOM) for CPUSET
  *
  * The program is designed to cope with unpredictable like amount and
  * system physical memory, swap size and other VMM technology like KSM,
@@ -44,12 +44,12 @@ int TST_TOTAL = 1;
 
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
+#include <numa.h>
+
 int main(int argc, char *argv[])
 {
 	char *msg;
 	int lc;
-	int swap_acc_on = 1;
-	char buf[BUFSIZ], mem[BUFSIZ];
 
 	msg = parse_opts(argc, argv, NULL, NULL);
 	if (msg != NULL)
@@ -64,38 +64,19 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		snprintf(buf, BUFSIZ, "%d", getpid());
-		write_file(MEMCG_PATH_NEW "/tasks", buf);
-
-		snprintf(mem, BUFSIZ, "%ld", TESTMEM);
-		write_file(MEMCG_PATH_NEW "/memory.limit_in_bytes", mem);
-
-		if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
-			if (errno == ENOENT) {
-				tst_resm(TCONF,
-					 "memcg swap accounting is disabled");
-				swap_acc_on = 0;
-			} else
-				tst_brkm(TBROK | TERRNO, cleanup, "access");
-		}
-
-		tst_resm(TINFO, "process mempolicy.");
-		testoom(1, 0, 1);
-
-		if (swap_acc_on) {
-			write_file(MEMCG_SW_LIMIT, mem);
-			testoom(1, 1, 1);
-		}
-
-		tst_resm(TINFO, "process cpuset.");
-
-		if (swap_acc_on)
-			write_file(MEMCG_SW_LIMIT, "-1");
-		testoom(0, 0, 1);
-
-		if (swap_acc_on) {
-			write_file(MEMCG_SW_LIMIT, mem);
-			testoom(0, 1, 1);
+		tst_resm(TINFO, "OOM on CPUSET...");
+		testoom(0, 0, 0);
+
+		if (ISNUMA) {
+			/*
+			 * Under NUMA system, the migration of cpuset's memory
+			 * is in charge of cpuset.memory_migrate, we can write
+			 * 1 to cpuset.memory_migrate to enable the migration.
+			 */
+			write_cpuset_files(CPATH_NEW,
+					   "memory_migrate", "1");
+			tst_resm(TINFO, "OOM on CPUSET with mem migrate:");
+			testoom(0, 0, 0);
 		}
 	}
 	cleanup();
@@ -111,14 +92,22 @@ void setup(void)
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
 	mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
-	mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
+
+	/* rough estimate a NUMA system through max_node */
+	if (numa_max_node() > 0) {
+		ISNUMA = 1;
+		/* For NUMA system, using the first node for cpuset.mems */
+		write_cpusets(get_a_numa_node(cleanup));
+	} else {
+		/* For nonNUMA system, using node0 for cpuset.mems */
+		write_cpusets(0);
+	}
 }
 
 void cleanup(void)
 {
 	set_sys_tune("overcommit_memory", overcommit, 0);
 	umount_mem(CPATH, CPATH_NEW);
-	umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
 
 	TEST_CLEANUP;
 }
-- 
1.7.11.7


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [LTP] [PATCH 4/5] lib/mem: updated testoom() and oom() funcs
  2013-03-14 16:21 [LTP] [PATCH 0/5] mm/oom: extend the coverage of OOM Zhouping Liu
                   ` (2 preceding siblings ...)
  2013-03-14 16:21 ` [LTP] [PATCH 3/5] mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG & numa' Zhouping Liu
@ 2013-03-14 16:21 ` Zhouping Liu
  2013-03-14 16:21 ` [LTP] [PATCH 5/5] mm/oom05: new testcase Zhouping Liu
  4 siblings, 0 replies; 12+ messages in thread
From: Zhouping Liu @ 2013-03-14 16:21 UTC (permalink / raw)
  To: LTP List

the 'numa' parameter inside testoom() and 'mempolicy' inside oom()
were useless, so removed them.

Signed-off-by: Zhouping Liu <zliu@redhat.com>
---
 testcases/kernel/mem/include/mem.h |  4 ++--
 testcases/kernel/mem/lib/mem.c     | 13 +++++--------
 testcases/kernel/mem/oom/oom01.c   |  6 +++---
 testcases/kernel/mem/oom/oom02.c   |  6 +++---
 testcases/kernel/mem/oom/oom03.c   | 10 +++++-----
 testcases/kernel/mem/oom/oom04.c   |  4 ++--
 6 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index de51838..2fd675b 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -27,8 +27,8 @@
 extern int ISNUMA;
 
 long overcommit;
-void oom(int testcase, int mempolicy, int lite);
-void testoom(int mempolicy, int lite, int numa);
+void oom(int testcase, int lite);
+void testoom(int mempolicy, int lite);
 
 /* KSM */
 
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index e99dae7..438735a 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -62,7 +62,7 @@ static void _test_alloc(int testcase, int lite)
 				return;
 }
 
-void oom(int testcase, int mempolicy, int lite)
+void oom(int testcase, int lite)
 {
 	pid_t pid;
 	int status;
@@ -92,7 +92,7 @@ void oom(int testcase, int mempolicy, int lite)
 	}
 }
 
-void testoom(int mempolicy, int lite, int numa)
+void testoom(int mempolicy, int lite)
 {
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
@@ -133,20 +133,17 @@ void testoom(int mempolicy, int lite, int numa)
 	}
 #endif
 
-	if (numa && !mempolicy)
-		write_cpusets(get_a_numa_node(cleanup));
-
 	tst_resm(TINFO, "start normal OOM testing.");
-	oom(NORMAL, mempolicy, lite);
+	oom(NORMAL, lite);
 
 	tst_resm(TINFO, "start OOM testing for mlocked pages.");
-	oom(MLOCK, mempolicy, lite);
+	oom(MLOCK, lite);
 
 	if (access(PATH_KSM, F_OK) == -1)
 		tst_brkm(TCONF, NULL, "KSM configuration is not enabled");
 
 	tst_resm(TINFO, "start OOM testing for KSM pages.");
-	oom(KSM, mempolicy, lite);
+	oom(KSM, lite);
 }
 
 /* KSM */
diff --git a/testcases/kernel/mem/oom/oom01.c b/testcases/kernel/mem/oom/oom01.c
index 0401e31..43a5319 100644
--- a/testcases/kernel/mem/oom/oom01.c
+++ b/testcases/kernel/mem/oom/oom01.c
@@ -61,13 +61,13 @@ int main(int argc, char *argv[])
 		tst_count = 0;
 
 		set_sys_tune("overcommit_memory", 2, 1);
-		oom(OVERCOMMIT, 0, 0);
+		oom(OVERCOMMIT, 0);
 
 		set_sys_tune("overcommit_memory", 0, 1);
-		oom(OVERCOMMIT, 0, 0);
+		oom(OVERCOMMIT, 0);
 
 		set_sys_tune("overcommit_memory", 1, 1);
-		testoom(0, 0, 0);
+		testoom(0, 0);
 	}
 	cleanup();
 	tst_exit();
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index 31ec73f..7566404 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -65,13 +65,13 @@ int main(int argc, char *argv[])
 		tst_count = 0;
 
 		tst_resm(TINFO, "OOM on MPOL_BIND mempolicy...");
-		testoom(MPOL_BIND, 0, 1);
+		testoom(MPOL_BIND, 0);
 
 		tst_resm(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
-		testoom(MPOL_INTERLEAVE, 0, 1);
+		testoom(MPOL_INTERLEAVE, 0);
 
 		tst_resm(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
-		testoom(MPOL_PREFERRED, 0, 1);
+		testoom(MPOL_PREFERRED, 0);
 	}
 	cleanup();
 	tst_exit();
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index 4365c2b..86eff41 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
 
 		snprintf(mem, BUFSIZ, "%ld", TESTMEM);
 		write_file(MEMCG_PATH_NEW "/memory.limit_in_bytes", mem);
-		testoom(0, 0, 0);
+		testoom(0, 0);
 
 		if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
 			if (errno == ENOENT)
@@ -78,15 +78,15 @@ int main(int argc, char *argv[])
 				tst_brkm(TBROK | TERRNO, cleanup, "access");
 		} else {
 			write_file(MEMCG_SW_LIMIT, mem);
-			testoom(0, 1, 0);
+			testoom(0, 1);
 		}
 
 		/* OOM for MEMCG with mempolicy */
 		if (ISNUMA) {
 			tst_resm(TINFO, "OOM on MEMCG & mempolicy...");
-			testoom(MPOL_BIND, 0, 1);
-			testoom(MPOL_INTERLEAVE, 0, 1);
-			testoom(MPOL_PREFERRED, 0, 1);
+			testoom(MPOL_BIND, 0);
+			testoom(MPOL_INTERLEAVE, 0);
+			testoom(MPOL_PREFERRED, 0);
 		}
 	}
 	cleanup();
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index 6acc783..9423d60 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
 		tst_count = 0;
 
 		tst_resm(TINFO, "OOM on CPUSET...");
-		testoom(0, 0, 0);
+		testoom(0, 0);
 
 		if (ISNUMA) {
 			/*
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
 			write_cpuset_files(CPATH_NEW,
 					   "memory_migrate", "1");
 			tst_resm(TINFO, "OOM on CPUSET with mem migrate:");
-			testoom(0, 0, 0);
+			testoom(0, 0);
 		}
 	}
 	cleanup();
-- 
1.7.11.7


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [LTP] [PATCH 5/5] mm/oom05: new testcase
  2013-03-14 16:21 [LTP] [PATCH 0/5] mm/oom: extend the coverage of OOM Zhouping Liu
                   ` (3 preceding siblings ...)
  2013-03-14 16:21 ` [LTP] [PATCH 4/5] lib/mem: updated testoom() and oom() funcs Zhouping Liu
@ 2013-03-14 16:21 ` Zhouping Liu
  4 siblings, 0 replies; 12+ messages in thread
From: Zhouping Liu @ 2013-03-14 16:21 UTC (permalink / raw)
  To: LTP List

added a new case to test OOM under the combination
of MEMCG and CPUSET.

Signed-off-by: Zhouping Liu <zliu@redhat.com>
---
 runtest/mm                       |   1 +
 testcases/kernel/mem/oom/oom05.c | 151 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 152 insertions(+)
 create mode 100644 testcases/kernel/mem/oom/oom05.c

diff --git a/runtest/mm b/runtest/mm
index a8bd605..56b83f8 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -77,6 +77,7 @@ oom01 oom01
 oom02 oom02
 oom03 oom03
 oom04 oom04
+oom05 oom05
 
 swapping01 swapping01 -i 5
 
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
new file mode 100644
index 0000000..89ce08c
--- /dev/null
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -0,0 +1,151 @@
+/*
+ * Out Of Memory (OOM) for MEMCG and CPUSET
+ *
+ * The program is designed to cope with unpredictable like amount and
+ * system physical memory, swap size and other VMM technology like KSM,
+ * memcg, memory hotplug and so on which may affect the OOM
+ * behaviours. It simply increase the memory consumption 3G each time
+ * until all the available memory is consumed and OOM is triggered.
+ *
+ * Copyright (C) 2013  Red Hat, Inc.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "config.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include "test.h"
+#include "usctest.h"
+#include "mem.h"
+
+char *TCID = "oom05";
+int TST_TOTAL = 1;
+
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+	&& HAVE_MPOL_CONSTANTS
+#include <numa.h>
+
+int main(int argc, char *argv[])
+{
+	char *msg;
+	int lc;
+	int swap_acc_on = 1;
+	char mem[BUFSIZ];
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+#if __WORDSIZE == 32
+	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
+#endif
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		tst_resm(TINFO, "OOM on CPUSET & MEMCG...");
+		testoom(0, 0);
+
+		/*
+		 * Under NUMA system, the migration of cpuset's memory
+ 		 * is in charge of cpuset.memory_migrate, we can write
+		 * 1 to cpuset.memory_migrate to enable the migration.
+		 */
+		if (ISNUMA) {
+			write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
+			tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
+					"cpuset.memory_migrate=1");
+			testoom(0, 0);
+		}
+
+		if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
+			if (errno == ENOENT) {
+				tst_resm(TCONF,
+					 "memcg swap accounting is disabled");
+				swap_acc_on = 0;
+			} else
+				tst_brkm(TBROK|TERRNO, cleanup, "access");
+		}
+
+		if (swap_acc_on) {
+			tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
+					"special memswap limitation:");
+			snprintf(mem, BUFSIZ, "%ld", TESTMEM);
+			write_file(MEMCG_SW_LIMIT, mem);
+			testoom(0, 0);
+
+			tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
+					"disabled memswap limitation:");
+			write_file(MEMCG_SW_LIMIT, "-1");
+			testoom(0, 0);
+		}
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+void setup(void)
+{
+	tst_require_root(NULL);
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+
+	mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
+	mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
+	write_memcg();
+
+	set_sys_tune("overcommit_memory", 1, 1);
+
+	/* rough estimate a NUMA system through max_node */
+	if (numa_max_node() > 0) {
+		ISNUMA = 1;
+		/* For NUMA system, using the first node for cpuset.mems */
+		write_cpusets(get_a_numa_node(cleanup));
+	} else {
+		/* For nonNUMA system, using node0 for cpuset.mems */
+		write_cpusets(0);
+	}
+
+	overcommit = get_sys_tune("overcommit_memory");
+
+}
+
+void cleanup(void)
+{
+	set_sys_tune("overcommit_memory", overcommit, 0);
+	umount_mem(CPATH, CPATH_NEW);
+	umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
+
+	TEST_CLEANUP;
+}
+
+#else /* no NUMA */
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
+}
+#endif
-- 
1.7.11.7


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [LTP] [PATCH 1/5] lib/mem: modified _gather_cpus() as _gather_node_cpus()
  2013-03-14 16:21 ` [LTP] [PATCH 1/5] lib/mem: modified _gather_cpus() as _gather_node_cpus() Zhouping Liu
@ 2013-03-14 16:45   ` chrubis
  0 siblings, 0 replies; 12+ messages in thread
From: chrubis @ 2013-03-14 16:45 UTC (permalink / raw)
  To: Zhouping Liu; +Cc: LTP List

Hi!
> -static void _gather_cpus(char *cpus, long nd)
> +static void _gather_node_cpus(char *cpus, long nd)

I know that the function name starting with underscore was there
allready but can we please get rid of them (idealy in separate patch
either before or after this patch).

>  {
>  	int ncpus = 0;
> -	int i;
> +	int fd, i;
> +	long online;
>  	char buf[BUFSIZ];
> +	char path[BUFSIZ], path1[BUFSIZ];
>  
>  	while (path_exist(PATH_SYS_SYSTEM "/cpu/cpu%d", ncpus))
>  		ncpus++;
>  
> -	for (i = 0; i < ncpus; i++)
> -		if (path_exist(PATH_SYS_SYSTEM "/node/node%ld/cpu%d", nd, i)) {
> +	for (i = 0; i < ncpus; i++) {
> +		snprintf(path, BUFSIZ,
> +			 PATH_SYS_SYSTEM "/node/node%ld/cpu%d", nd, i);
> +		if (path_exist(path, nd, i)) {
> +			snprintf(path1, BUFSIZ, "%s/online", path);
> +			/*
> +			 * No cpu0/online knob, as it can't support to
> +			 * on/offline cpu0, so if the 'nd' node contains
> +			 * cpu0, it should skip to check cpu0/online's value.
> +			 */
> +			if (i == 0)
> +				goto  next;

There are two spaces before the next.

> +			fd = open(path1, O_RDONLY);
> +			if (fd == -1)
> +				tst_brkm(TBROK|TERRNO, cleanup,
> +					 "open %s", path1);
> +			read_file(path1, buf);
> +			online = SAFE_STRTOL(cleanup, buf, 0, 1);
> +			if (online == 0)
> +				continue;

This part can be done with SAFE_FILE_SCANF() see include/safe_file_ops.h

> +next:
>  			sprintf(buf, "%d,", i);
>  			strcat(cpus, buf);
>  		}
> +	}
>  	/* Remove the trailing comma. */
>  	cpus[strlen(cpus) - 1] = '\0';
>  }
> @@ -563,7 +585,7 @@ void write_cpusets(long nd)
>  	snprintf(buf, BUFSIZ, "%ld", nd);
>  	write_cpuset_files(CPATH_NEW, "mems", buf);
>  
> -	_gather_cpus(cpus, nd);
> +	_gather_node_cpus(cpus, nd);
>  	write_cpuset_files(CPATH_NEW, "cpus", cpus);
>  
>  	snprintf(buf, BUFSIZ, "%d", getpid());

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LTP] [PATCH 3/5] mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG & numa'
  2013-03-14 16:21 ` [LTP] [PATCH 3/5] mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG & numa' Zhouping Liu
@ 2013-03-14 16:51   ` chrubis
       [not found]     ` <507561236.18941341.1363282016883.JavaMail.root@redhat.com>
  0 siblings, 1 reply; 12+ messages in thread
From: chrubis @ 2013-03-14 16:51 UTC (permalink / raw)
  To: Zhouping Liu; +Cc: LTP List

Hi!
>  testcases/kernel/mem/include/mem.h |  2 ++
>  testcases/kernel/mem/lib/mem.c     |  2 ++
>  testcases/kernel/mem/oom/oom03.c   | 24 +++++++++++++++
>  testcases/kernel/mem/oom/oom04.c   | 63 ++++++++++++++++----------------------
>  4 files changed, 54 insertions(+), 37 deletions(-)
> 
> diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
> index 1233493..de51838 100644
> --- a/testcases/kernel/mem/include/mem.h
> +++ b/testcases/kernel/mem/include/mem.h
> @@ -24,6 +24,8 @@
>  #define MLOCK			3
>  #define KSM			4
>  
> +extern int ISNUMA;
> +
>  long overcommit;
>  void oom(int testcase, int mempolicy, int lite);
>  void testoom(int mempolicy, int lite, int numa);
> diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
> index a71bc90..e99dae7 100644
> --- a/testcases/kernel/mem/lib/mem.c
> +++ b/testcases/kernel/mem/lib/mem.c
> @@ -24,6 +24,8 @@
>  #include "mem.h"
>  #include "numa_helper.h"
>  
> +int ISNUMA = 0; /* mark a NUMA system */

So you have added variable to the library that is initialized in the
test setup? That is just too messy :(.

> +	/* rough estimate a NUMA system through max_node */
> +	if (numa_max_node() > 0) {
> +		ISNUMA = 1;
> +		/* For NUMA system, using the first node for cpuset.mems */
> +		write_cpusets(get_a_numa_node(cleanup));
> +	} else {
> +		/* For nonNUMA system, using node0 for cpuset.mems */
> +		write_cpusets(0);
> +	}

Why couldn't we have a function is_numa() in the library that would do
something like this snippet of code, i.e. return numa_max_node() > 0
(assuming that the code is needed in other test than this one.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LTP] [PATCH 3/5] mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG & numa'
       [not found]     ` <507561236.18941341.1363282016883.JavaMail.root@redhat.com>
@ 2013-03-14 18:32       ` chrubis
  0 siblings, 0 replies; 12+ messages in thread
From: chrubis @ 2013-03-14 18:32 UTC (permalink / raw)
  To: Jan Stancek; +Cc: LTP List

Hi!
> We added numa_helper library to be able to get number of nodes, as well
> as list of nodes (with memory, cpu or both). numa_max_node() > 0 doesn't
> tell you how many nodes you have.
> 
> Here's sample use to get just node count:
> ----------------------------------------------------------------
> #include <stdio.h>
> #include "numa_helper.h"
> 
> const char *TCID="test";
> int main()
> {
>         int num_nodes;
>         int ret = get_allowed_nodes_arr(NH_MEMS | NH_CPUS, &num_nodes, NULL);
>         printf("ret: %d, nodes:%d\n", ret, num_nodes);
>         return 0;
> }
> ----------------------------------------------------------------
> 
> We could add a simple function to numa_helper, but I'm not sure what
> it would return as default, some tests care about nodes with memory.

Maybe we misunderstand about what I see as a problem here. This patch
adds integer variable to the lib/mem.c library and that variable is then
only used within the tests. That just looks like wrong desing to me.

The code snippet "numa_max_node() > 0" was take from one of the tests
that initializes the variable in question (the pattern seems to repeat
in them). So I wasn't proposing any functional changes in the code just
requesting cleaner desing.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy'
  2013-03-14 16:21 ` [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy' Zhouping Liu
@ 2013-03-15  3:09   ` Caspar Zhang
  2013-03-15  3:57     ` Zhouping Liu
  0 siblings, 1 reply; 12+ messages in thread
From: Caspar Zhang @ 2013-03-15  3:09 UTC (permalink / raw)
  To: Zhouping Liu; +Cc: LTP List

On 03/15/2013 12:21 AM, Zhouping Liu wrote:
>
> diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
> index 29de64a..a71bc90 100644
> --- a/testcases/kernel/mem/lib/mem.c
> +++ b/testcases/kernel/mem/lib/mem.c
> @@ -64,32 +64,17 @@ void oom(int testcase, int mempolicy, int lite)

you've moved all mempolicy check stuff to testoom(), so you can 
completely remove this variable.

>   {
>   	pid_t pid;
>   	int status;
> -#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
> -	&& HAVE_MPOL_CONSTANTS
> -	unsigned long nmask = 0;
> -	unsigned int node;
> -
> -	if (mempolicy)
> -		node = get_a_numa_node(cleanup);
> -	nmask += 1 << node;
> -#endif
>
>   	switch (pid = fork()) {
>   	case -1:
>   		tst_brkm(TBROK | TERRNO, cleanup, "fork");
>   	case 0:
> -#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
> -	&& HAVE_MPOL_CONSTANTS
> -		if (mempolicy)
> -			if (set_mempolicy(MPOL_BIND, &nmask, MAXNODES) == -1)
> -				tst_brkm(TBROK | TERRNO, cleanup,
> -					 "set_mempolicy");
> -#endif
>   		_test_alloc(testcase, lite);
>   		exit(0);
>   	default:
>   		break;
>   	}
> +
>   	tst_resm(TINFO, "expected victim is %d.", pid);
>   	if (waitpid(-1, &status, 0) == -1)
>   		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
> @@ -107,7 +92,44 @@ void oom(int testcase, int mempolicy, int lite)
>
>   void testoom(int mempolicy, int lite, int numa)
>   {
> -	long nodes[MAXNODES];
> +#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
> +	&& HAVE_MPOL_CONSTANTS
> +	unsigned long nmask = 0;
> +	unsigned int num_nodes, nodes[MAXNODES];
> +	int ret;
> +
> +	if (mempolicy) {
> +		ret = get_allowed_nodes_arr(NH_MEMS|NH_CPUS, &num_nodes, &nodes);
> +		if (ret != 0)
> +			tst_brkm(TBROK|TERRNO, cleanup,
> +				 "get_allowed_nodes_arr");
> +		if (num_nodes < 2) {
> +			tst_resm(TINFO, "mempolicy need NUMA system support");
> +			return;
> +		}
> +		switch(mempolicy) {
> +		case MPOL_BIND:
> +			/* bind the second node */
> +			nmask = 1 << nodes[1];
> +			break;
> +		case MPOL_INTERLEAVE:
> +		case MPOL_PREFERRED:
> +			if (num_nodes == 2) {
> +				tst_resm(TINFO, "The mempolicy need "
> +					 "more than 2 numa nodes");
> +				return;
> +			} else {
> +				/* Using the 2nd,3rd node */
> +				nmask = (1 << nodes[1]) | (1 << nodes[2]);
> +			}
> +			break;
> +		default:
> +			tst_brkm(TBROK|TERRNO, cleanup, "Bad mempolicy mode");
> +		}
> +		if (set_mempolicy(mempolicy, &nmask, MAXNODES) == -1)
> +			tst_brkm(TBROK|TERRNO, cleanup, "set_mempolicy");
> +	}
> +#endif
>
>   	if (numa && !mempolicy)
>   		write_cpusets(get_a_numa_node(cleanup));
>

The remaining concern to me is that, mempolicy set in parent process, 
can it be inherited by child? I see this patch changed the behavior that 
in new test, set_mempolicy happen in parent and oom happen in child.

Caspar

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy'
  2013-03-15  3:09   ` Caspar Zhang
@ 2013-03-15  3:57     ` Zhouping Liu
  2013-03-15  4:33       ` Caspar Zhang
  0 siblings, 1 reply; 12+ messages in thread
From: Zhouping Liu @ 2013-03-15  3:57 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List



----- Original Message -----
> From: "Caspar Zhang" <caspar@casparzhang.com>
> To: "Zhouping Liu" <zliu@redhat.com>
> Cc: "LTP List" <ltp-list@lists.sourceforge.net>
> Sent: Friday, March 15, 2013 11:09:33 AM
> Subject: Re: [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy'
> 
> On 03/15/2013 12:21 AM, Zhouping Liu wrote:
> >
> > diff --git a/testcases/kernel/mem/lib/mem.c
> > b/testcases/kernel/mem/lib/mem.c
> > index 29de64a..a71bc90 100644
> > --- a/testcases/kernel/mem/lib/mem.c
> > +++ b/testcases/kernel/mem/lib/mem.c
> > @@ -64,32 +64,17 @@ void oom(int testcase, int mempolicy, int lite)
> 
> you've moved all mempolicy check stuff to testoom(), so you can
> completely remove this variable.

I'm not sure which variable you mean, pid and status variable? but they are needed.

> 
> >   {
> >   	pid_t pid;
> >   	int status;
> > -#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
> > -	&& HAVE_MPOL_CONSTANTS
> > -	unsigned long nmask = 0;
> > -	unsigned int node;
> > -
> > -	if (mempolicy)
> > -		node = get_a_numa_node(cleanup);
> > -	nmask += 1 << node;
> > -#endif
> >
> >   	switch (pid = fork()) {
> >   	case -1:
> >   		tst_brkm(TBROK | TERRNO, cleanup, "fork");
> >   	case 0:
> > -#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
> > -	&& HAVE_MPOL_CONSTANTS
> > -		if (mempolicy)
> > -			if (set_mempolicy(MPOL_BIND, &nmask, MAXNODES) == -1)
> > -				tst_brkm(TBROK | TERRNO, cleanup,
> > -					 "set_mempolicy");
> > -#endif
> >   		_test_alloc(testcase, lite);
> >   		exit(0);
> >   	default:
> >   		break;
> >   	}
> > +
> >   	tst_resm(TINFO, "expected victim is %d.", pid);
> >   	if (waitpid(-1, &status, 0) == -1)
> >   		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
> > @@ -107,7 +92,44 @@ void oom(int testcase, int mempolicy, int lite)
> >
> >   void testoom(int mempolicy, int lite, int numa)
> >   {
> > -	long nodes[MAXNODES];
> > +#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
> > +	&& HAVE_MPOL_CONSTANTS
> > +	unsigned long nmask = 0;
> > +	unsigned int num_nodes, nodes[MAXNODES];
> > +	int ret;
> > +
> > +	if (mempolicy) {
> > +		ret = get_allowed_nodes_arr(NH_MEMS|NH_CPUS, &num_nodes,
> > &nodes);
> > +		if (ret != 0)
> > +			tst_brkm(TBROK|TERRNO, cleanup,
> > +				 "get_allowed_nodes_arr");
> > +		if (num_nodes < 2) {
> > +			tst_resm(TINFO, "mempolicy need NUMA system support");
> > +			return;
> > +		}
> > +		switch(mempolicy) {
> > +		case MPOL_BIND:
> > +			/* bind the second node */
> > +			nmask = 1 << nodes[1];
> > +			break;
> > +		case MPOL_INTERLEAVE:
> > +		case MPOL_PREFERRED:
> > +			if (num_nodes == 2) {
> > +				tst_resm(TINFO, "The mempolicy need "
> > +					 "more than 2 numa nodes");
> > +				return;
> > +			} else {
> > +				/* Using the 2nd,3rd node */
> > +				nmask = (1 << nodes[1]) | (1 << nodes[2]);
> > +			}
> > +			break;
> > +		default:
> > +			tst_brkm(TBROK|TERRNO, cleanup, "Bad mempolicy mode");
> > +		}
> > +		if (set_mempolicy(mempolicy, &nmask, MAXNODES) == -1)
> > +			tst_brkm(TBROK|TERRNO, cleanup, "set_mempolicy");
> > +	}
> > +#endif
> >
> >   	if (numa && !mempolicy)
> >   		write_cpusets(get_a_numa_node(cleanup));
> >
> 
> The remaining concern to me is that, mempolicy set in parent process,
> can it be inherited by child? I see this patch changed the behavior
> that
> in new test, set_mempolicy happen in parent and oom happen in child.

The following words from the manual page can tell us the child inherit the father's mempolicy:

SET_MEMPOLICY(2)
...
The process memory policy is preserved across an execve(2), and is inherited by child processes created using fork(2) or clone(2).
...

-- 
Thanks,
Zhouping

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy'
  2013-03-15  3:57     ` Zhouping Liu
@ 2013-03-15  4:33       ` Caspar Zhang
  0 siblings, 0 replies; 12+ messages in thread
From: Caspar Zhang @ 2013-03-15  4:33 UTC (permalink / raw)
  To: Zhouping Liu; +Cc: LTP List

On 03/15/2013 11:57 AM, Zhouping Liu wrote:
>> >you've moved all mempolicy check stuff to testoom(), so you can
>> >completely remove this variable.
> I'm not sure which variable you mean, pid and status variable? but they are needed.
>
never mind, I see the 4/5 patch that removed this variable :)

Caspar

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-03-15  4:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-14 16:21 [LTP] [PATCH 0/5] mm/oom: extend the coverage of OOM Zhouping Liu
2013-03-14 16:21 ` [LTP] [PATCH 1/5] lib/mem: modified _gather_cpus() as _gather_node_cpus() Zhouping Liu
2013-03-14 16:45   ` chrubis
2013-03-14 16:21 ` [LTP] [PATCH 2/5] mm/oom02: modified 'OOM for NUMA' as 'OOM for mempolicy' Zhouping Liu
2013-03-15  3:09   ` Caspar Zhang
2013-03-15  3:57     ` Zhouping Liu
2013-03-15  4:33       ` Caspar Zhang
2013-03-14 16:21 ` [LTP] [PATCH 3/5] mm/oom0[3|4]: added 'OOM for CPUSET' and updated 'OOM with MEMCG & numa' Zhouping Liu
2013-03-14 16:51   ` chrubis
     [not found]     ` <507561236.18941341.1363282016883.JavaMail.root@redhat.com>
2013-03-14 18:32       ` chrubis
2013-03-14 16:21 ` [LTP] [PATCH 4/5] lib/mem: updated testoom() and oom() funcs Zhouping Liu
2013-03-14 16:21 ` [LTP] [PATCH 5/5] mm/oom05: new testcase Zhouping Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox