All of lore.kernel.org
 help / color / mirror / Atom feed
diff for duplicates of <56A724B1.3000407@redhat.com>

diff --git a/a/1.txt b/N1/1.txt
index cd3c63d..806cd87 100644
--- a/a/1.txt
+++ b/N1/1.txt
@@ -26,10 +26,3 @@ on more systems.
 
 Regards,
 Jan
--------------- next part --------------
-A non-text attachment was scrubbed...
-Name: oom_mlock.c
-Type: text/x-csrc
-Size: 1974 bytes
-Desc: not available
-URL: <http://lists.linux.it/pipermail/ltp/attachments/20160126/f54f7c7b/attachment.c>
diff --git a/N1/2.hdr b/N1/2.hdr
new file mode 100644
index 0000000..2fb5852
--- /dev/null
+++ b/N1/2.hdr
@@ -0,0 +1,5 @@
+Content-Type: text/x-csrc;
+ name="oom_mlock.c"
+Content-Transfer-Encoding: 7bit
+Content-Disposition: attachment;
+ filename="oom_mlock.c"
diff --git a/N1/2.txt b/N1/2.txt
new file mode 100644
index 0000000..63e6536
--- /dev/null
+++ b/N1/2.txt
@@ -0,0 +1,115 @@
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+/*
+ * oom hang reproducer v1
+ *
+ * # gcc oom_mlock.c -pthread -O2
+ * # echo 1 > /proc/sys/vm/overcommit_memory
+ * (optionally) # swapoff -a
+ * # ./a.out
+ */
+
+#define _1GB (1024L*1024*1024)
+
+static do_mlock = 1;
+
+static int alloc_mem(long int length)
+{
+	char *s;
+	long i, pagesz = getpagesize();
+	int loop = 10;
+
+	printf("thread (%lx), allocating %ld bytes, do_mlock: %d\n",
+		(unsigned long) pthread_self(), length, do_mlock);
+
+	s = mmap(NULL, length, PROT_READ | PROT_WRITE,
+		 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+	if (s == MAP_FAILED)
+		return errno;
+
+	if (do_mlock) {
+		while (mlock(s, length) == -1 && loop > 0) {
+			if (EAGAIN != errno)
+				return errno;
+			usleep(300000);
+			loop--;
+		}
+	}
+
+	for (i = 0; i < length; i += pagesz)
+		s[i] = '\a';
+
+	return 0;
+}
+
+void *alloc_thread(void *args)
+{
+	int ret;
+
+	do {
+		ret = alloc_mem(3 * _1GB);
+	} while (ret == 0);
+
+	exit(ret);
+}
+
+int trigger_oom(void)
+{
+	int i, ret, child, status, threads;
+	pthread_t *th;
+
+	threads = sysconf(_SC_NPROCESSORS_ONLN) - 1;
+	th = malloc(sizeof(pthread_t) * threads);
+	if (!th) {
+		printf("malloc failed\n");
+		exit(2);
+	}
+
+	do_mlock = !do_mlock;
+	child = fork();
+	if (child == 0) {
+		for (i = 0; i < threads - 1; i++) {
+			ret = pthread_create(&th[i], NULL, alloc_thread, NULL);
+			if (ret) {
+				printf("pthread_create failed with %d\n", ret);
+				exit(3);
+			}
+		}
+		pause();
+	}
+	
+	if (waitpid(-1, &status, 0) == -1) {
+		perror("waitpid");
+		exit(1);
+	}
+
+	if (WIFSIGNALED(status)) {
+		printf("child killed by %d\n", WTERMSIG(status));
+		if (WTERMSIG(status) != SIGKILL)
+			exit(1);
+	}
+	
+	if (WIFEXITED(status)) {
+		printf("child exited with %d\n", WEXITSTATUS(status));
+		if (WEXITSTATUS(status) != ENOMEM)
+			exit(1);
+	}
+}
+
+int main(void)
+{
+	int i = 1;
+
+	while (1) {
+		printf("starting iteration %d\n", i++);
+		trigger_oom();
+	}
+
+	return 0;
+}
diff --git a/a/content_digest b/N1/content_digest
index 1aa050d..f06a31c 100644
--- a/a/content_digest
+++ b/N1/content_digest
@@ -2,10 +2,12 @@
  "ref\0569E1010.2070806@I-love.SAKURA.ne.jp\0"
  "ref\056A24760.5020503@redhat.com\0"
  "From\0Jan Stancek <jstancek@redhat.com>\0"
- "Subject\0[LTP] [BUG] oom hangs the system, NMI backtrace shows most CPUs in shrink_slab\0"
+ "Subject\0Re: [LTP] [BUG] oom hangs the system, NMI backtrace shows most CPUs in shrink_slab\0"
  "Date\0Tue, 26 Jan 2016 08:48:01 +0100\0"
- "To\0ltp@lists.linux.it\0"
- "\00:1\0"
+ "To\0Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>"
+ " linux-mm@kvack.org\0"
+ "Cc\0ltp@lists.linux.it\0"
+ "\01:1\0"
  "b\0"
  "On 01/22/2016 04:14 PM, Jan Stancek wrote:\n"
  "> On 01/19/2016 11:29 AM, Tetsuo Handa wrote:\n"
@@ -34,13 +36,124 @@
  "on more systems.\n"
  "\n"
  "Regards,\n"
- "Jan\n"
- "-------------- next part --------------\n"
- "A non-text attachment was scrubbed...\n"
- "Name: oom_mlock.c\n"
- "Type: text/x-csrc\n"
- "Size: 1974 bytes\n"
- "Desc: not available\n"
- URL: <http://lists.linux.it/pipermail/ltp/attachments/20160126/f54f7c7b/attachment.c>
+ Jan
+ "\01:2\0"
+ "fn\0oom_mlock.c\0"
+ "b\0"
+ "#include <errno.h>\n"
+ "#include <pthread.h>\n"
+ "#include <stdio.h>\n"
+ "#include <stdlib.h>\n"
+ "#include <unistd.h>\n"
+ "#include <sys/mman.h>\n"
+ "#include <sys/wait.h>\n"
+ "\n"
+ "/*\n"
+ " * oom hang reproducer v1\n"
+ " *\n"
+ " * # gcc oom_mlock.c -pthread -O2\n"
+ " * # echo 1 > /proc/sys/vm/overcommit_memory\n"
+ " * (optionally) # swapoff -a\n"
+ " * # ./a.out\n"
+ " */\n"
+ "\n"
+ "#define _1GB (1024L*1024*1024)\n"
+ "\n"
+ "static do_mlock = 1;\n"
+ "\n"
+ "static int alloc_mem(long int length)\n"
+ "{\n"
+ "\tchar *s;\n"
+ "\tlong i, pagesz = getpagesize();\n"
+ "\tint loop = 10;\n"
+ "\n"
+ "\tprintf(\"thread (%lx), allocating %ld bytes, do_mlock: %d\\n\",\n"
+ "\t\t(unsigned long) pthread_self(), length, do_mlock);\n"
+ "\n"
+ "\ts = mmap(NULL, length, PROT_READ | PROT_WRITE,\n"
+ "\t\t MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);\n"
+ "\tif (s == MAP_FAILED)\n"
+ "\t\treturn errno;\n"
+ "\n"
+ "\tif (do_mlock) {\n"
+ "\t\twhile (mlock(s, length) == -1 && loop > 0) {\n"
+ "\t\t\tif (EAGAIN != errno)\n"
+ "\t\t\t\treturn errno;\n"
+ "\t\t\tusleep(300000);\n"
+ "\t\t\tloop--;\n"
+ "\t\t}\n"
+ "\t}\n"
+ "\n"
+ "\tfor (i = 0; i < length; i += pagesz)\n"
+ "\t\ts[i] = '\\a';\n"
+ "\n"
+ "\treturn 0;\n"
+ "}\n"
+ "\n"
+ "void *alloc_thread(void *args)\n"
+ "{\n"
+ "\tint ret;\n"
+ "\n"
+ "\tdo {\n"
+ "\t\tret = alloc_mem(3 * _1GB);\n"
+ "\t} while (ret == 0);\n"
+ "\n"
+ "\texit(ret);\n"
+ "}\n"
+ "\n"
+ "int trigger_oom(void)\n"
+ "{\n"
+ "\tint i, ret, child, status, threads;\n"
+ "\tpthread_t *th;\n"
+ "\n"
+ "\tthreads = sysconf(_SC_NPROCESSORS_ONLN) - 1;\n"
+ "\tth = malloc(sizeof(pthread_t) * threads);\n"
+ "\tif (!th) {\n"
+ "\t\tprintf(\"malloc failed\\n\");\n"
+ "\t\texit(2);\n"
+ "\t}\n"
+ "\n"
+ "\tdo_mlock = !do_mlock;\n"
+ "\tchild = fork();\n"
+ "\tif (child == 0) {\n"
+ "\t\tfor (i = 0; i < threads - 1; i++) {\n"
+ "\t\t\tret = pthread_create(&th[i], NULL, alloc_thread, NULL);\n"
+ "\t\t\tif (ret) {\n"
+ "\t\t\t\tprintf(\"pthread_create failed with %d\\n\", ret);\n"
+ "\t\t\t\texit(3);\n"
+ "\t\t\t}\n"
+ "\t\t}\n"
+ "\t\tpause();\n"
+ "\t}\n"
+ "\t\n"
+ "\tif (waitpid(-1, &status, 0) == -1) {\n"
+ "\t\tperror(\"waitpid\");\n"
+ "\t\texit(1);\n"
+ "\t}\n"
+ "\n"
+ "\tif (WIFSIGNALED(status)) {\n"
+ "\t\tprintf(\"child killed by %d\\n\", WTERMSIG(status));\n"
+ "\t\tif (WTERMSIG(status) != SIGKILL)\n"
+ "\t\t\texit(1);\n"
+ "\t}\n"
+ "\t\n"
+ "\tif (WIFEXITED(status)) {\n"
+ "\t\tprintf(\"child exited with %d\\n\", WEXITSTATUS(status));\n"
+ "\t\tif (WEXITSTATUS(status) != ENOMEM)\n"
+ "\t\t\texit(1);\n"
+ "\t}\n"
+ "}\n"
+ "\n"
+ "int main(void)\n"
+ "{\n"
+ "\tint i = 1;\n"
+ "\n"
+ "\twhile (1) {\n"
+ "\t\tprintf(\"starting iteration %d\\n\", i++);\n"
+ "\t\ttrigger_oom();\n"
+ "\t}\n"
+ "\n"
+ "\treturn 0;\n"
+ }
 
-37f0fbea6b2b3994481e468c737f9e91aeb7cca1ad3db9fa0c3a97ebb14c20e5
+ee599749afa26322931762fd1b0892bf81d1199f381adae7af613e3620460088

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.