Signed-off-by: CAI Qian <[email protected]>
---
v3: use common functions.
v2: code cleanup and skip 32-bit since there is no guarantee of running out of
virtual memory address space there.
testcases/kernel/mem/oom/oom04.c | 174 ++++++++++++++++++++++++++++++++++++++
1 files changed, 174 insertions(+), 0 deletions(-)
create mode 100644 testcases/kernel/mem/oom/oom04.c
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
new file mode 100644
index 0000000..11b9769
--- /dev/null
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -0,0 +1,174 @@
+/*
+ * Out Of Memory (OOM) for Memory Resource Controller and NUMA
+ *
+ * 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) 2010 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 "test.h"
+#include "usctest.h"
+#include "config.h"
+
+char *TCID = "oom04";
+int TST_TOTAL = 1;
+extern int Tst_count;
+
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+ && HAVE_MPOL_CONSTANTS
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include "lib/oom.h"
+
+static void setup(void);
+
+int main(int argc, char *argv[])
+{
+ char *msg;
+ int lc, fd;
+ unsigned long nnodes = 1;
+ char buf[BUFSIZ], mem[BUFSIZ];
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+#ifdef __i386__
+ tst_brkm(TCONF, tst_exit,
+ "test is not designed for 32-bit system.");
+#endif /* __i386__ */
+
+ nnodes = count_numa();
+ if (count_numa() == 1)
+ tst_brkm(TCONF, tst_exit, "required a NUMA system.");
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ Tst_count = 0;
+ fd = open(SYSFS_OVER, O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open");
+ if (write(fd, "1", 1) != 1)
+ tst_brkm(TBROK|TERRNO, cleanup, "write");
+ close(fd);
+
+ fd = open(MEMCG_PATH_NEW "/memory.limit_in_bytes", O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ sprintf(mem, "%ld", TESTMEM);
+ if (write(fd, mem, strlen(mem)) != strlen(mem))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+
+ fd = open(MEMCG_PATH_NEW "/tasks", O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ snprintf(buf, BUFSIZ, "%d", getpid());
+ if (write(fd, buf, strlen(buf)) != strlen(buf))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+
+ tst_resm(TINFO, "process mempolicy.");
+ testoom(1, 0);
+
+ fd = open(MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes",
+ O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ if (write(fd, mem, strlen(mem)) != strlen(mem))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+ testoom(1, 1);
+
+ tst_resm(TINFO, "process cpuset.");
+ fd = open(MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes",
+ O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ sprintf(mem, "%ld", TESTMEM);
+ if (write(fd, "-1", 2) != 2)
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+ testoom(0, 0);
+
+ fd = open(MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes",
+ O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ if (write(fd, mem, strlen(mem)) != strlen(mem))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+ testoom(0, 1);
+ }
+ cleanup();
+}
+
+void setup(void)
+{
+ int fd;
+
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+ TEST_PAUSE;
+
+ fd = open(SYSFS_OVER, O_RDONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open");
+ if (read(fd, &overcommit, 1) != 1)
+ tst_brkm(TBROK|TERRNO, cleanup, "read");
+ close(fd);
+
+ mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
+ mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
+}
+
+void cleanup(void)
+{
+ int fd;
+
+ fd = open(SYSFS_OVER, O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open");
+ if (write(fd, &overcommit, 1) != 1)
+ tst_brkm(TBROK|TERRNO, cleanup, "write");
+ close(fd);
+
+ umount_mem(CPATH, CPATH_NEW);
+ umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
+
+ TEST_CLEANUP;
+ tst_exit();
+}
+
+#else /* no NUMA */
+int main(void)
+{
+ tst_resm(TCONF, "no NUMA development packages installed.");
+ tst_exit();
+}
+#endif
--
1.7.3.2From c49b0f8d3a723f71820f3eeb1d0e7d3b7cd1773d Mon Sep 17 00:00:00 2001
From: CAI Qian <[email protected]>
Date: Mon, 27 Dec 2010 12:30:27 +0800
Subject: [PATCH v3 4/5] oom04: test OOM for NUMA with memcg
Signed-off-by: CAI Qian <[email protected]>
---
v3: use common functions.
v2: code cleanup and skip 32-bit since there is no guarantee of running out of
virtual memory address space there.
testcases/kernel/mem/oom/oom04.c | 174 ++++++++++++++++++++++++++++++++++++++
1 files changed, 174 insertions(+), 0 deletions(-)
create mode 100644 testcases/kernel/mem/oom/oom04.c
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
new file mode 100644
index 0000000..11b9769
--- /dev/null
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -0,0 +1,174 @@
+/*
+ * Out Of Memory (OOM) for Memory Resource Controller and NUMA
+ *
+ * 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) 2010 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 "test.h"
+#include "usctest.h"
+#include "config.h"
+
+char *TCID = "oom04";
+int TST_TOTAL = 1;
+extern int Tst_count;
+
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+ && HAVE_MPOL_CONSTANTS
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include "lib/oom.h"
+
+static void setup(void);
+
+int main(int argc, char *argv[])
+{
+ char *msg;
+ int lc, fd;
+ unsigned long nnodes = 1;
+ char buf[BUFSIZ], mem[BUFSIZ];
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+#ifdef __i386__
+ tst_brkm(TCONF, tst_exit,
+ "test is not designed for 32-bit system.");
+#endif /* __i386__ */
+
+ nnodes = count_numa();
+ if (count_numa() == 1)
+ tst_brkm(TCONF, tst_exit, "required a NUMA system.");
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ Tst_count = 0;
+ fd = open(SYSFS_OVER, O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open");
+ if (write(fd, "1", 1) != 1)
+ tst_brkm(TBROK|TERRNO, cleanup, "write");
+ close(fd);
+
+ fd = open(MEMCG_PATH_NEW "/memory.limit_in_bytes", O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ sprintf(mem, "%ld", TESTMEM);
+ if (write(fd, mem, strlen(mem)) != strlen(mem))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+
+ fd = open(MEMCG_PATH_NEW "/tasks", O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ snprintf(buf, BUFSIZ, "%d", getpid());
+ if (write(fd, buf, strlen(buf)) != strlen(buf))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+
+ tst_resm(TINFO, "process mempolicy.");
+ testoom(1, 0);
+
+ fd = open(MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes",
+ O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ if (write(fd, mem, strlen(mem)) != strlen(mem))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+ testoom(1, 1);
+
+ tst_resm(TINFO, "process cpuset.");
+ fd = open(MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes",
+ O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ sprintf(mem, "%ld", TESTMEM);
+ if (write(fd, "-1", 2) != 2)
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+ testoom(0, 0);
+
+ fd = open(MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes",
+ O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+ if (write(fd, mem, strlen(mem)) != strlen(mem))
+ tst_brkm(TBROK|TERRNO, cleanup, "write %s", buf);
+ close(fd);
+ testoom(0, 1);
+ }
+ cleanup();
+}
+
+void setup(void)
+{
+ int fd;
+
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+ TEST_PAUSE;
+
+ fd = open(SYSFS_OVER, O_RDONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open");
+ if (read(fd, &overcommit, 1) != 1)
+ tst_brkm(TBROK|TERRNO, cleanup, "read");
+ close(fd);
+
+ mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
+ mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
+}
+
+void cleanup(void)
+{
+ int fd;
+
+ fd = open(SYSFS_OVER, O_WRONLY);
+ if (fd == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "open");
+ if (write(fd, &overcommit, 1) != 1)
+ tst_brkm(TBROK|TERRNO, cleanup, "write");
+ close(fd);
+
+ umount_mem(CPATH, CPATH_NEW);
+ umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
+
+ TEST_CLEANUP;
+ tst_exit();
+}
+
+#else /* no NUMA */
+int main(void)
+{
+ tst_resm(TCONF, "no NUMA development packages installed.");
+ tst_exit();
+}
+#endif
--
1.7.3.2
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list