All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] [mm] vma01: new testcase
       [not found] <145b91763d3c2670cd736cc7fa3072c9a6db219a.1312043382.git.czhang@redhat.com>
@ 2011-07-30 17:09 ` Caspar Zhang
  2011-08-01  1:20   ` [LTP] [PATCH v2] " Caspar Zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Caspar Zhang @ 2011-07-30 17:09 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 1181 bytes --]


vma01 - test not merging a VMA which cloned from parent process

This program is used for testing the following upstream commit:
965f55dea0e331152fa53941a51e4e16f9f06fae

The cloned VMA shares the anon_vma lock with the parent process's
VMA. If we do the merge, more vmas (even the new range is only
for current process) use the perent process's anon_vma lock. This
introduces scalability issues. find_mergeable_anon_vma() already
considers this case.

This test program clones VMA and checks /proc/$pid/maps file, on
an unpatched kernel, there is a single 6*ps VMA for the child
like this:

7fee32989000-7fee3298f000 -w-p 00000000 00:00 0

On a patched kernel, there are two 3*ps VMAs like this:

7f55bbd47000-7f55bbd4a000 -w-p 00000000 00:00 0
7f55bbd4a000-7f55bbd4d000 -w-p 00000000 00:00 0

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 runtest/mm                        |    2 +
 testcases/kernel/mem/vma/Makefile |   24 ++++++
 testcases/kernel/mem/vma/vma01.c  |  162 +++++++++++++++++++++++++++++++++++++
 3 files changed, 188 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/vma/Makefile
 create mode 100644 testcases/kernel/mem/vma/vma01.c


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-mm-vma01-new-testcase.patch --]
[-- Type: text/x-patch; name="0002-mm-vma01-new-testcase.patch", Size: 5978 bytes --]

diff --git a/runtest/mm b/runtest/mm
index df7d0cb..5b08d15 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -80,3 +80,5 @@ oom03 oom03
 oom04 oom04
 
 thp01 thp01 -I 120
+
+vma01 vma01
diff --git a/testcases/kernel/mem/vma/Makefile b/testcases/kernel/mem/vma/Makefile
new file mode 100644
index 0000000..6b347c4
--- /dev/null
+++ b/testcases/kernel/mem/vma/Makefile
@@ -0,0 +1,24 @@
+#
+#  Copyright (C) 2011  Red Hat, Inc.
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or (at
+#  your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful, but
+#  WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+#  02110-1301, USA.
+#
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/vma/vma01.c b/testcases/kernel/mem/vma/vma01.c
new file mode 100644
index 0000000..6dd6eba
--- /dev/null
+++ b/testcases/kernel/mem/vma/vma01.c
@@ -0,0 +1,162 @@
+/*
+ * vma01 - test not merging a VMA which cloned from parent process
+ *
+ * This program is used for testing the following upstream commit:
+ * 965f55dea0e331152fa53941a51e4e16f9f06fae
+ *
+ * The cloned VMA shares the anon_vma lock with the parent process's
+ * VMA. If we do the merge, more vmas (even the new range is only
+ * for current process) use the perent process's anon_vma lock. This
+ * introduces scalability issues. find_mergeable_anon_vma() already
+ * considers this case.
+ *
+ * This test program clones VMA and checks /proc/$pid/maps file, on
+ * an unpatched kernel, there is a single 6*ps VMA for the child
+ * like this:
+ *
+ * 7fee32989000-7fee3298f000 -w-p 00000000 00:00 0
+ *
+ * On a patched kernel, there are two 3*ps VMAs like this:
+ *
+ * 7f55bbd47000-7f55bbd4a000 -w-p 00000000 00:00 0
+ * 7f55bbd4a000-7f55bbd4d000 -w-p 00000000 00:00 0
+ *
+ * Copyright (C) 2011  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 <sys/types.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "vma01";
+int TST_TOTAL = 1;
+
+static void check_vma(void);
+static void *get_end_addr(void *addr_s, char *mapfile);
+static void setup(void);
+static void cleanup(void);
+
+static unsigned long ps;
+
+int main(int argc, char **argv)
+{
+	char *msg;
+	int lc;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	ps = sysconf(_SC_PAGE_SIZE);
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+
+		check_vma();
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void check_vma(void)
+{
+	pid_t pid;
+	void *t, *u, *v, *x, *y;
+	char mapfile[BUFSIZ];
+
+	t = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+	if (t == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+	tst_resm(TINFO, "t = %p", t);
+	memset(t, 1, ps);
+	v = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+	if (v == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+	tst_resm(TINFO, "v = %p", v);
+	memset(v, 2, ps);
+
+	switch (pid = fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
+		sprintf(mapfile, "/proc/%u/maps", getpid());
+		memset(t, 2, ps);
+		u = mmap(t + 3*ps, 3*ps, PROT_WRITE,
+			    MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+		if (u == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, NULL, "mmap");
+		tst_resm(TINFO, "u = %p", u);
+		memset(u, 2, 4096);
+		x = get_end_addr(u, mapfile);
+		if (x == u + 6*ps)
+			tst_resm(TFAIL, "A single 6*ps VMA found.");
+		else if (x == u + 3*ps) {
+			y = get_end_addr(x, mapfile);
+			if (y == x + 3*ps)
+				tst_resm(TPASS, "two 3*ps VMAs found.");
+		} else
+			tst_brkm(TBROK, cleanup, "unexpected VMA found.");
+		exit(0);
+	default:
+		break;
+	}
+
+}
+
+static void *get_end_addr(void *addr_s, char *mapfile)
+{
+	FILE *fp;
+	void *s, *t;
+	char buf[BUFSIZ];
+
+	fp = fopen(mapfile, "r+");
+	if (fp == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fopen");
+	while (fgets(buf, BUFSIZ, fp) != NULL) {
+		fscanf(fp, "%p-%p", &s, &t);
+		if (addr_s == s) {
+			tst_resm(TINFO, "s = %p, t = %p", s, t);
+			fclose(fp);
+			return t;
+		}
+	}
+	fclose(fp);
+	tst_brkm(TBROK, cleanup, "no matched s = %p found.", addr_s);
+}
+
+static void setup(void)
+{
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+}

[-- Attachment #3: Type: text/plain, Size: 277 bytes --]

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2] [mm] vma01: new testcase
  2011-07-30 17:09 ` [LTP] [PATCH] [mm] vma01: new testcase Caspar Zhang
@ 2011-08-01  1:20   ` Caspar Zhang
  2011-08-01  1:26     ` [LTP] [PATCH 0/2] mm/mbind01 fix Caspar Zhang
  2011-08-11 13:43     ` [LTP] [PATCH v2] [mm] vma01: new testcase Cyril Hrubis
  0 siblings, 2 replies; 9+ messages in thread
From: Caspar Zhang @ 2011-08-01  1:20 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 1181 bytes --]


vma01 - test not merging a VMA which cloned from parent process

This program is used for testing the following upstream commit:
965f55dea0e331152fa53941a51e4e16f9f06fae

The cloned VMA shares the anon_vma lock with the parent process's
VMA. If we do the merge, more vmas (even the new range is only
for current process) use the perent process's anon_vma lock. This
introduces scalability issues. find_mergeable_anon_vma() already
considers this case.

This test program clones VMA and checks /proc/$pid/maps file, on
an unpatched kernel, there is a single 6*ps VMA for the child
like this:

7fee32989000-7fee3298f000 -w-p 00000000 00:00 0

On a patched kernel, there are two 3*ps VMAs like this:

7f55bbd47000-7f55bbd4a000 -w-p 00000000 00:00 0
7f55bbd4a000-7f55bbd4d000 -w-p 00000000 00:00 0

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 runtest/mm                        |    2 +
 testcases/kernel/mem/vma/Makefile |   24 ++++++
 testcases/kernel/mem/vma/vma01.c  |  163 +++++++++++++++++++++++++++++++++++++
 3 files changed, 189 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/vma/Makefile
 create mode 100644 testcases/kernel/mem/vma/vma01.c


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mm-vma01-new-testcase.patch --]
[-- Type: text/x-patch; name="0001-mm-vma01-new-testcase.patch", Size: 6003 bytes --]

diff --git a/runtest/mm b/runtest/mm
index df7d0cb..5b08d15 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -80,3 +80,5 @@ oom03 oom03
 oom04 oom04
 
 thp01 thp01 -I 120
+
+vma01 vma01
diff --git a/testcases/kernel/mem/vma/Makefile b/testcases/kernel/mem/vma/Makefile
new file mode 100644
index 0000000..6b347c4
--- /dev/null
+++ b/testcases/kernel/mem/vma/Makefile
@@ -0,0 +1,24 @@
+#
+#  Copyright (C) 2011  Red Hat, Inc.
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or (at
+#  your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful, but
+#  WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+#  02110-1301, USA.
+#
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/vma/vma01.c b/testcases/kernel/mem/vma/vma01.c
new file mode 100644
index 0000000..edcd95c
--- /dev/null
+++ b/testcases/kernel/mem/vma/vma01.c
@@ -0,0 +1,163 @@
+/*
+ * vma01 - test not merging a VMA which cloned from parent process
+ *
+ * This program is used for testing the following upstream commit:
+ * 965f55dea0e331152fa53941a51e4e16f9f06fae
+ *
+ * The cloned VMA shares the anon_vma lock with the parent process's
+ * VMA. If we do the merge, more vmas (even the new range is only
+ * for current process) use the perent process's anon_vma lock. This
+ * introduces scalability issues. find_mergeable_anon_vma() already
+ * considers this case.
+ *
+ * This test program clones VMA and checks /proc/$pid/maps file, on
+ * an unpatched kernel, there is a single 6*ps VMA for the child
+ * like this:
+ *
+ * 7fee32989000-7fee3298f000 -w-p 00000000 00:00 0
+ *
+ * On a patched kernel, there are two 3*ps VMAs like this:
+ *
+ * 7f55bbd47000-7f55bbd4a000 -w-p 00000000 00:00 0
+ * 7f55bbd4a000-7f55bbd4d000 -w-p 00000000 00:00 0
+ *
+ * Copyright (C) 2011  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 <sys/types.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "vma01";
+int TST_TOTAL = 1;
+
+static void check_vma(void);
+static void *get_end_addr(void *addr_s, char *mapfile);
+static void setup(void);
+static void cleanup(void);
+
+static unsigned long ps;
+
+int main(int argc, char **argv)
+{
+	char *msg;
+	int lc;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	ps = sysconf(_SC_PAGE_SIZE);
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+
+		check_vma();
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void check_vma(void)
+{
+	pid_t pid;
+	void *t, *u, *v, *x, *y;
+	char mapfile[BUFSIZ];
+
+	t = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+	if (t == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+	tst_resm(TINFO, "t = %p", t);
+	memset(t, 1, ps);
+	v = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+	if (v == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+	tst_resm(TINFO, "v = %p", v);
+	memset(v, 2, ps);
+
+	switch (pid = fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
+		sprintf(mapfile, "/proc/%u/maps", getpid());
+		memset(t, 2, ps);
+		u = mmap(t + 3*ps, 3*ps, PROT_WRITE,
+			    MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+		if (u == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, NULL, "mmap");
+		tst_resm(TINFO, "u = %p", u);
+		memset(u, 2, 4096);
+		x = get_end_addr(u, mapfile);
+		if (x == u + 6*ps)
+			tst_resm(TFAIL, "A single 6*ps VMA found.");
+		else if (x == u + 3*ps) {
+			y = get_end_addr(x, mapfile);
+			if (y == x + 3*ps)
+				tst_resm(TPASS, "two 3*ps VMAs found.");
+		} else
+			tst_brkm(TBROK, cleanup, "unexpected VMA found.");
+		exit(0);
+	default:
+		break;
+	}
+
+}
+
+static void *get_end_addr(void *addr_s, char *mapfile)
+{
+	FILE *fp;
+	void *s, *t;
+	char buf[BUFSIZ];
+
+	fp = fopen(mapfile, "r+");
+	if (fp == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fopen");
+	while (fgets(buf, BUFSIZ, fp) != NULL) {
+		if (sscanf(buf, "%p-%p ", &s, &t) != 2)
+			continue;
+		if (addr_s == s) {
+			tst_resm(TINFO, "s = %p, t = %p", s, t);
+			fclose(fp);
+			return t;
+		}
+	}
+	fclose(fp);
+	tst_brkm(TBROK, cleanup, "no matched s = %p found.", addr_s);
+}
+
+static void setup(void)
+{
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+}

[-- Attachment #3: Type: text/plain, Size: 278 bytes --]

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 0/2] mm/mbind01 fix
  2011-08-01  1:20   ` [LTP] [PATCH v2] " Caspar Zhang
@ 2011-08-01  1:26     ` Caspar Zhang
  2011-08-01  1:26       ` [LTP] [PATCH] mm/mbind01: fix broken testcase Caspar Zhang
  2011-08-11 13:43     ` [LTP] [PATCH v2] [mm] vma01: new testcase Cyril Hrubis
  1 sibling, 1 reply; 9+ messages in thread
From: Caspar Zhang @ 2011-08-01  1:26 UTC (permalink / raw)
  To: LTP List


This fix is an increment of previous vma01 patch, including 
two parts: fix broken testcase and rename testcase to mm/vma02
to avoid name overlapping.

Thanks,
Caspar

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] mm/mbind01: fix broken testcase
  2011-08-01  1:26     ` [LTP] [PATCH 0/2] mm/mbind01 fix Caspar Zhang
@ 2011-08-01  1:26       ` Caspar Zhang
  2011-08-01  1:26         ` [LTP] [PATCH] mm/mbind01: move to mm/vma02 Caspar Zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Caspar Zhang @ 2011-08-01  1:26 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]


the original mm/mbind01 test doesn't work, the patch corrected the
errors and both postive and negative tests passed.

positive: # ./mbind01
mbind01     0  TINFO  :  pid = 6637 addr = 0x7f4c5111f000
mbind01     0  TINFO  :  start = 0x7f4c5111f000, end = 0x7f4c51122000
mbind01     1  TPASS  :  only 1 VMA.

negative: # ./mbind01
mbind01     0  TINFO  :  pid = 21868 addr = 0x7fe6eb374000
mbind01     0  TINFO  :  start = 0x7fe6eb374000, end = 0x7fe6eb375000
mbind01     0  TINFO  :  start = 0x7fe6eb375000, end = 0x7fe6eb376000
mbind01     0  TINFO  :  start = 0x7fe6eb376000, end = 0x7fe6eb377000
mbind01     1  TFAIL  :  >1 unmerged VMAs.

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 testcases/kernel/mem/mbind/mbind01.c |   54 ++++++++++++++++++++++-----------
 1 files changed, 36 insertions(+), 18 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mm-mbind01-fix-broken-testcase.patch --]
[-- Type: text/x-patch; name="0001-mm-mbind01-fix-broken-testcase.patch", Size: 2529 bytes --]

diff --git a/testcases/kernel/mem/mbind/mbind01.c b/testcases/kernel/mem/mbind/mbind01.c
index fc97174..35f26ca 100644
--- a/testcases/kernel/mem/mbind/mbind01.c
+++ b/testcases/kernel/mem/mbind/mbind01.c
@@ -60,11 +60,11 @@ static void usage(void);
 int main(int argc, char** argv)
 {
 	FILE *fp;
-	void* addr;
+	void *addr, *start, *end, *lastend;
 	int node, err, lc;
+	char buf[BUFSIZ];
 	struct bitmask *nmask = numa_allocate_nodemask();
-	char buf[BUFSIZ], start[BUFSIZ], end[BUFSIZ], string[BUFSIZ];
-	char *p, *msg;
+	char *msg;
 
 	pagesize = getpagesize();
 	msg = parse_opts(argc, argv, options, usage);
@@ -81,7 +81,7 @@ int main(int argc, char** argv)
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		Tst_count = 0;
-		addr = mmap(NULL, pagesize*3, PROT_READ|PROT_WRITE,
+		addr = mmap(NULL, pagesize*3, PROT_WRITE,
 			MAP_ANON|MAP_PRIVATE, 0, 0);
 		if (addr == MAP_FAILED)
 			tst_brkm(TBROK|TERRNO, NULL, "mmap");
@@ -108,26 +108,44 @@ int main(int argc, char** argv)
 
 		/* /proc/self/maps in the form of
 		   "00400000-00406000 r-xp 00000000". */
-		sprintf(string, "%p", addr);
 		fp = fopen("/proc/self/maps", "r");
 		if (fp == NULL)
 			tst_brkm(TBROK|TERRNO, NULL, "fopen");
 
 		while (fgets(buf, BUFSIZ, fp) != NULL) {
-			/* Find out the 1st VMAs. */
-			if (sscanf(buf, "%s-%s ", start, end) != 2)
+			if (sscanf(buf, "%p-%p ", &start, &end) != 2)
 				continue;
-			/* Remove leading 0x. */
-			if (strcmp(string + 2, start) != 0)
-				continue;
-			/* Find out the second VMA. */
-			if (fgets(buf, BUFSIZ, fp) == NULL)
-				tst_brkm(TBROK|TERRNO, NULL, "fgets");
-			p = strtok(buf, "-");
-			if (p == NULL || strcmp(p, end) != 0)
-				tst_resm(TPASS, "only 1 VMA.");
-			else
-				tst_resm(TFAIL, "more than 1 VMA.");
+
+			if (start == addr) {
+				tst_resm(TINFO, "start = %p, end = %p",
+					start, end);
+				if (end == addr + pagesize*3) {
+					tst_resm(TPASS, "only 1 VMA.");
+					break;
+				}
+
+				lastend = end;
+				while (fgets(buf, BUFSIZ, fp) != NULL) {
+					/* No more VMAs, break */
+					if (sscanf(buf, "%p-%p ", &start,
+						&end) != 2)
+						break;
+					tst_resm(TINFO, "start = %p, end = %p",
+						start, end);
+
+					/* more VMAs found */
+					if (start == lastend)
+						lastend = end;
+					if (end == addr + pagesize*3) {
+						tst_resm(TFAIL,
+							">1 unmerged VMAs.");
+						break;
+					}
+				}
+				if (end != addr + pagesize*3)
+					tst_resm(TFAIL, "no matched VMAs.");
+				break;
+			}
 		}
 		fclose(fp);
 		if (munmap(addr, pagesize*3) == -1)

[-- Attachment #3: Type: text/plain, Size: 278 bytes --]

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] mm/mbind01: move to mm/vma02
  2011-08-01  1:26       ` [LTP] [PATCH] mm/mbind01: fix broken testcase Caspar Zhang
@ 2011-08-01  1:26         ` Caspar Zhang
  2011-08-11 17:21           ` Cyril Hrubis
  0 siblings, 1 reply; 9+ messages in thread
From: Caspar Zhang @ 2011-08-01  1:26 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 907 bytes --]


why move testcase location:

mm/mbind01 has the same testcase name with syscalls/mbind01, which will
obviously make mm/mbind01 cover syscalls/mbind01 binary when `make
install'. Thus, we must change the testcase name. Since this testcase is
used to test vma merging issue during mbind, I propose to add it to
mm/vma test set.

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 runtest/mm                           |    3 +-
 testcases/kernel/mem/mbind/Makefile  |   26 -----
 testcases/kernel/mem/mbind/mbind01.c |  170 ----------------------------------
 testcases/kernel/mem/vma/Makefile    |    2 +
 testcases/kernel/mem/vma/vma02.c     |  170 ++++++++++++++++++++++++++++++++++
 5 files changed, 173 insertions(+), 198 deletions(-)
 delete mode 100644 testcases/kernel/mem/mbind/Makefile
 delete mode 100644 testcases/kernel/mem/mbind/mbind01.c
 create mode 100644 testcases/kernel/mem/vma/vma02.c


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-mm-mbind01-move-to-mm-vma02.patch --]
[-- Type: text/x-patch; name="0002-mm-mbind01-move-to-mm-vma02.patch", Size: 11803 bytes --]

diff --git a/runtest/mm b/runtest/mm
index 5b08d15..b81ba8c 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -72,8 +72,6 @@ ksm04_1 ksm04 -u 128
 
 cpuset01 cpuset01 -I 3600
 
-mbind01 mbind01
-
 oom01 oom01
 oom02 oom02
 oom03 oom03
@@ -82,3 +80,4 @@ oom04 oom04
 thp01 thp01 -I 120
 
 vma01 vma01
+vma02 vma02
diff --git a/testcases/kernel/mem/mbind/Makefile b/testcases/kernel/mem/mbind/Makefile
deleted file mode 100644
index 27208d1..0000000
--- a/testcases/kernel/mem/mbind/Makefile
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-#  Copyright (C) 2010  Red Hat, Inc.
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or (at
-#  your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful, but
-#  WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-#  02110-1301, USA.
-#
-
-top_srcdir              ?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-LDLIBS 			+= $(NUMA_LIBS)
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/mbind/mbind01.c b/testcases/kernel/mem/mbind/mbind01.c
deleted file mode 100644
index 35f26ca..0000000
--- a/testcases/kernel/mem/mbind/mbind01.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * This is a reproducer from mainline commit
- * 9d8cebd4bcd7c3878462fdfda34bbcdeb4df7ef4:
- *
- * "Strangely, current mbind() doesn't merge vma with neighbor vma
- * although it's possible.  Unfortunately, many vma can reduce
- * performance..."
- *
- * 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 = "mbind01";
-int TST_TOTAL = 1;
-
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
-#include <numaif.h>
-#include <numa.h>
-#include <sys/mman.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#if defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION == 2
-
-static unsigned long pagesize;
-static int opt_node;
-static char *opt_nodestr;
-static option_t options[] = {
-	{ "n:", &opt_node,	&opt_nodestr},
-	{ NULL, NULL,		NULL}
-};
-
-static void usage(void);
-
-int main(int argc, char** argv)
-{
-	FILE *fp;
-	void *addr, *start, *end, *lastend;
-	int node, err, lc;
-	char buf[BUFSIZ];
-	struct bitmask *nmask = numa_allocate_nodemask();
-	char *msg;
-
-	pagesize = getpagesize();
-	msg = parse_opts(argc, argv, options, usage);
-	if (msg != NULL)
-		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	if (opt_node) {
-		node = atoi(optarg);
-		if (node < 1)
-			tst_brkm(TBROK, NULL,
-				"Number of NUMA nodes cannot be less that 1.");
-		numa_bitmask_setbit(nmask, node);
-	} else
-		numa_bitmask_setbit(nmask, 0);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		Tst_count = 0;
-		addr = mmap(NULL, pagesize*3, PROT_WRITE,
-			MAP_ANON|MAP_PRIVATE, 0, 0);
-		if (addr == MAP_FAILED)
-			tst_brkm(TBROK|TERRNO, NULL, "mmap");
-
-		tst_resm(TINFO, "pid = %d addr = %p", getpid(), addr);
-		/* make page populate */
-		memset(addr, 0, pagesize*3);
-
-		/* first mbind */
-		err = mbind(addr+pagesize, pagesize, MPOL_BIND, nmask->maskp,
-			nmask->size, MPOL_MF_MOVE_ALL);
-		if (err != 0) {
-			if (errno != ENOSYS)
-				tst_brkm(TBROK|TERRNO, NULL, "mbind1");
-			else
-				tst_brkm(TCONF, NULL,
-					"mbind syscall not implemented on this system.");
-		}
-
-		/* second mbind */
-		err = mbind(addr, pagesize*3, MPOL_DEFAULT, NULL, 0, 0);
-		if (err != 0)
-			tst_brkm(TBROK|TERRNO, NULL, "mbind2");
-
-		/* /proc/self/maps in the form of
-		   "00400000-00406000 r-xp 00000000". */
-		fp = fopen("/proc/self/maps", "r");
-		if (fp == NULL)
-			tst_brkm(TBROK|TERRNO, NULL, "fopen");
-
-		while (fgets(buf, BUFSIZ, fp) != NULL) {
-			if (sscanf(buf, "%p-%p ", &start, &end) != 2)
-				continue;
-
-			if (start == addr) {
-				tst_resm(TINFO, "start = %p, end = %p",
-					start, end);
-				if (end == addr + pagesize*3) {
-					tst_resm(TPASS, "only 1 VMA.");
-					break;
-				}
-
-				lastend = end;
-				while (fgets(buf, BUFSIZ, fp) != NULL) {
-					/* No more VMAs, break */
-					if (sscanf(buf, "%p-%p ", &start,
-						&end) != 2)
-						break;
-					tst_resm(TINFO, "start = %p, end = %p",
-						start, end);
-
-					/* more VMAs found */
-					if (start == lastend)
-						lastend = end;
-					if (end == addr + pagesize*3) {
-						tst_resm(TFAIL,
-							">1 unmerged VMAs.");
-						break;
-					}
-				}
-				if (end != addr + pagesize*3)
-					tst_resm(TFAIL, "no matched VMAs.");
-				break;
-			}
-		}
-		fclose(fp);
-		if (munmap(addr, pagesize*3) == -1)
-			tst_brkm(TWARN|TERRNO, NULL, "munmap");
-	}
-	tst_exit();
-}
-
-void usage(void)
-{
-	printf("  -n      Number of NUMA nodes\n");
-}
-#else /* libnuma v1 */
-int main(void) {
-	tst_brkm(TCONF, NULL, "XXX: test is only supported on libnuma v2.");
-}
-#endif
-#else /* no NUMA */
-int main(void) {
-	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
-}
-#endif
diff --git a/testcases/kernel/mem/vma/Makefile b/testcases/kernel/mem/vma/Makefile
index 6b347c4..3899fcb 100644
--- a/testcases/kernel/mem/vma/Makefile
+++ b/testcases/kernel/mem/vma/Makefile
@@ -21,4 +21,6 @@ top_srcdir              ?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+LDLIBS 			+= $(NUMA_LIBS)
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/vma/vma02.c b/testcases/kernel/mem/vma/vma02.c
new file mode 100644
index 0000000..a1c8f24
--- /dev/null
+++ b/testcases/kernel/mem/vma/vma02.c
@@ -0,0 +1,170 @@
+/*
+ * This is a reproducer from mainline commit
+ * 9d8cebd4bcd7c3878462fdfda34bbcdeb4df7ef4:
+ *
+ * "Strangely, current mbind() doesn't merge vma with neighbor vma
+ * although it's possible.  Unfortunately, many vma can reduce
+ * performance..."
+ *
+ * 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 = "vma02";
+int TST_TOTAL = 1;
+
+#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
+	&& HAVE_MPOL_CONSTANTS
+#include <numaif.h>
+#include <numa.h>
+#include <sys/mman.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#if defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION == 2
+
+static unsigned long pagesize;
+static int opt_node;
+static char *opt_nodestr;
+static option_t options[] = {
+	{ "n:", &opt_node,	&opt_nodestr},
+	{ NULL, NULL,		NULL}
+};
+
+static void usage(void);
+
+int main(int argc, char** argv)
+{
+	FILE *fp;
+	void *addr, *start, *end, *lastend;
+	int node, err, lc;
+	char buf[BUFSIZ];
+	struct bitmask *nmask = numa_allocate_nodemask();
+	char *msg;
+
+	pagesize = getpagesize();
+	msg = parse_opts(argc, argv, options, usage);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+	if (opt_node) {
+		node = atoi(optarg);
+		if (node < 1)
+			tst_brkm(TBROK, NULL,
+				"Number of NUMA nodes cannot be less that 1.");
+		numa_bitmask_setbit(nmask, node);
+	} else
+		numa_bitmask_setbit(nmask, 0);
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		addr = mmap(NULL, pagesize*3, PROT_WRITE,
+			MAP_ANON|MAP_PRIVATE, 0, 0);
+		if (addr == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, NULL, "mmap");
+
+		tst_resm(TINFO, "pid = %d addr = %p", getpid(), addr);
+		/* make page populate */
+		memset(addr, 0, pagesize*3);
+
+		/* first mbind */
+		err = mbind(addr+pagesize, pagesize, MPOL_BIND, nmask->maskp,
+			nmask->size, MPOL_MF_MOVE_ALL);
+		if (err != 0) {
+			if (errno != ENOSYS)
+				tst_brkm(TBROK|TERRNO, NULL, "mbind1");
+			else
+				tst_brkm(TCONF, NULL,
+					"mbind syscall not implemented on this system.");
+		}
+
+		/* second mbind */
+		err = mbind(addr, pagesize*3, MPOL_DEFAULT, NULL, 0, 0);
+		if (err != 0)
+			tst_brkm(TBROK|TERRNO, NULL, "mbind2");
+
+		/* /proc/self/maps in the form of
+		   "00400000-00406000 r-xp 00000000". */
+		fp = fopen("/proc/self/maps", "r");
+		if (fp == NULL)
+			tst_brkm(TBROK|TERRNO, NULL, "fopen");
+
+		while (fgets(buf, BUFSIZ, fp) != NULL) {
+			if (sscanf(buf, "%p-%p ", &start, &end) != 2)
+				continue;
+
+			if (start == addr) {
+				tst_resm(TINFO, "start = %p, end = %p",
+					start, end);
+				if (end == addr + pagesize*3) {
+					tst_resm(TPASS, "only 1 VMA.");
+					break;
+				}
+
+				lastend = end;
+				while (fgets(buf, BUFSIZ, fp) != NULL) {
+					/* No more VMAs, break */
+					if (sscanf(buf, "%p-%p ", &start,
+						&end) != 2)
+						break;
+					tst_resm(TINFO, "start = %p, end = %p",
+						start, end);
+
+					/* more VMAs found */
+					if (start == lastend)
+						lastend = end;
+					if (end == addr + pagesize*3) {
+						tst_resm(TFAIL,
+							">1 unmerged VMAs.");
+						break;
+					}
+				}
+				if (end != addr + pagesize*3)
+					tst_resm(TFAIL, "no matched VMAs.");
+				break;
+			}
+		}
+		fclose(fp);
+		if (munmap(addr, pagesize*3) == -1)
+			tst_brkm(TWARN|TERRNO, NULL, "munmap");
+	}
+	tst_exit();
+}
+
+void usage(void)
+{
+	printf("  -n      Number of NUMA nodes\n");
+}
+#else /* libnuma v1 */
+int main(void) {
+	tst_brkm(TCONF, NULL, "XXX: test is only supported on libnuma v2.");
+}
+#endif
+#else /* no NUMA */
+int main(void) {
+	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
+}
+#endif

[-- Attachment #3: Type: text/plain, Size: 278 bytes --]

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH v2] [mm] vma01: new testcase
  2011-08-01  1:20   ` [LTP] [PATCH v2] " Caspar Zhang
  2011-08-01  1:26     ` [LTP] [PATCH 0/2] mm/mbind01 fix Caspar Zhang
@ 2011-08-11 13:43     ` Cyril Hrubis
  2011-08-11 14:03       ` [LTP] [PATCH v3] mm/vma01: " Caspar Zhang
  1 sibling, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2011-08-11 13:43 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

Hi!
> +	case 0:
> +		sprintf(mapfile, "/proc/%u/maps", getpid());

You could use /proc/self/maps instead.

> +		memset(t, 2, ps);
> +		u = mmap(t + 3*ps, 3*ps, PROT_WRITE,
> +			    MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
> +		if (u == MAP_FAILED)
> +			tst_brkm(TBROK|TERRNO, NULL, "mmap");
> +		tst_resm(TINFO, "u = %p", u);
> +		memset(u, 2, 4096);
> +		x = get_end_addr(u, mapfile);
> +		if (x == u + 6*ps)
> +			tst_resm(TFAIL, "A single 6*ps VMA found.");
> +		else if (x == u + 3*ps) {
> +			y = get_end_addr(x, mapfile);
> +			if (y == x + 3*ps)
> +				tst_resm(TPASS, "two 3*ps VMAs found.");
> +		} else
> +			tst_brkm(TBROK, cleanup, "unexpected VMA found.");
> +		exit(0);
> +	default:
> +		break;
> +	}
> +
> +}
> +
> +static void *get_end_addr(void *addr_s, char *mapfile)
> +{
> +	FILE *fp;
> +	void *s, *t;
> +	char buf[BUFSIZ];
> +
> +	fp = fopen(mapfile, "r+");

Hmm, "r+" opens the file for reading and writing (and sets the possition
on the start of the file). Shouldn't just "r" be sufficient?


-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. 
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v3] mm/vma01: new testcase
  2011-08-11 13:43     ` [LTP] [PATCH v2] [mm] vma01: new testcase Cyril Hrubis
@ 2011-08-11 14:03       ` Caspar Zhang
  2011-08-11 14:20         ` Cyril Hrubis
  0 siblings, 1 reply; 9+ messages in thread
From: Caspar Zhang @ 2011-08-11 14:03 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 1180 bytes --]


vma01 - test not merging a VMA which cloned from parent process

This program is used for testing the following upstream commit:
965f55dea0e331152fa53941a51e4e16f9f06fae

The cloned VMA shares the anon_vma lock with the parent process's
VMA. If we do the merge, more vmas (even the new range is only
for current process) use the perent process's anon_vma lock. This
introduces scalability issues. find_mergeable_anon_vma() already
considers this case.

This test program clones VMA and checks /proc/$pid/maps file, on
an unpatched kernel, there is a single 6*ps VMA for the child
like this:

7fee32989000-7fee3298f000 -w-p 00000000 00:00 0

On a patched kernel, there are two 3*ps VMAs like this:

7f55bbd47000-7f55bbd4a000 -w-p 00000000 00:00 0
7f55bbd4a000-7f55bbd4d000 -w-p 00000000 00:00 0

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 runtest/mm                        |    2 +
 testcases/kernel/mem/vma/Makefile |   24 +++++
 testcases/kernel/mem/vma/vma01.c  |  167 +++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/vma/Makefile
 create mode 100644 testcases/kernel/mem/vma/vma01.c


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mm-vma01-new-testcase.patch --]
[-- Type: text/x-patch; name="0001-mm-vma01-new-testcase.patch", Size: 6079 bytes --]

diff --git a/runtest/mm b/runtest/mm
index df7d0cb..5b08d15 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -80,3 +80,5 @@ oom03 oom03
 oom04 oom04
 
 thp01 thp01 -I 120
+
+vma01 vma01
diff --git a/testcases/kernel/mem/vma/Makefile b/testcases/kernel/mem/vma/Makefile
new file mode 100644
index 0000000..6b347c4
--- /dev/null
+++ b/testcases/kernel/mem/vma/Makefile
@@ -0,0 +1,24 @@
+#
+#  Copyright (C) 2011  Red Hat, Inc.
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or (at
+#  your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful, but
+#  WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+#  02110-1301, USA.
+#
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/vma/vma01.c b/testcases/kernel/mem/vma/vma01.c
new file mode 100644
index 0000000..86e1276
--- /dev/null
+++ b/testcases/kernel/mem/vma/vma01.c
@@ -0,0 +1,167 @@
+/*
+ * vma01 - test not merging a VMA which cloned from parent process
+ *
+ * This program is used for testing the following upstream commit:
+ * 965f55dea0e331152fa53941a51e4e16f9f06fae
+ *
+ * The cloned VMA shares the anon_vma lock with the parent process's
+ * VMA. If we do the merge, more vmas (even the new range is only
+ * for current process) use the perent process's anon_vma lock. This
+ * introduces scalability issues. find_mergeable_anon_vma() already
+ * considers this case.
+ *
+ * This test program clones VMA and checks /proc/self/maps file, on
+ * an unpatched kernel, there is a single 6*ps VMA for the child
+ * like this:
+ *
+ * 7fee32989000-7fee3298f000 -w-p 00000000 00:00 0
+ *
+ * On a patched kernel, there are two 3*ps VMAs like this:
+ *
+ * 7f55bbd47000-7f55bbd4a000 -w-p 00000000 00:00 0
+ * 7f55bbd4a000-7f55bbd4d000 -w-p 00000000 00:00 0
+ *
+ * Copyright (C) 2011  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 <sys/types.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test.h"
+#include "usctest.h"
+
+#define MAPS_FILE "/proc/self/maps"
+
+char *TCID = "vma01";
+int TST_TOTAL = 1;
+
+static void check_vma(void);
+static void *get_end_addr(void *addr_s, char *mapfile);
+static void setup(void);
+static void cleanup(void);
+
+static unsigned long ps;
+
+int main(int argc, char **argv)
+{
+	char *msg;
+	int lc;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	ps = sysconf(_SC_PAGE_SIZE);
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+
+		check_vma();
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void check_vma(void)
+{
+	int status;
+	void *t, *u, *v, *x, *y;
+
+	t = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+	if (t == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+	tst_resm(TINFO, "t = %p", t);
+	memset(t, 1, ps);
+
+	v = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+	if (v == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+	tst_resm(TINFO, "v = %p", v);
+	memset(v, 2, ps);
+
+	switch (fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
+		memset(t, 2, ps);
+		u = mmap(t + 3*ps, 3*ps, PROT_WRITE,
+			    MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+		if (u == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, NULL, "mmap");
+		tst_resm(TINFO, "u = %p", u);
+		memset(u, 2, 4096);
+		x = get_end_addr(u, MAPS_FILE);
+		if (x == u + 6*ps)
+			tst_resm(TFAIL, "A single 6*ps VMA found.");
+		else if (x == u + 3*ps) {
+			y = get_end_addr(x, MAPS_FILE);
+			if (y == x + 3*ps)
+				tst_resm(TPASS, "two 3*ps VMAs found.");
+		} else
+			tst_brkm(TBROK, cleanup, "unexpected VMA found.");
+		exit(0);
+	default:
+		if (waitpid(-1, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		break;
+	}
+
+}
+
+static void *get_end_addr(void *addr_s, char *mapfile)
+{
+	FILE *fp;
+	void *s, *t;
+	char buf[BUFSIZ];
+
+	fp = fopen(mapfile, "r");
+	if (fp == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fopen");
+	while (fgets(buf, BUFSIZ, fp) != NULL) {
+		if (sscanf(buf, "%p-%p ", &s, &t) != 2)
+			continue;
+		if (addr_s == s) {
+			tst_resm(TINFO, "s = %p, t = %p", s, t);
+			fclose(fp);
+			return t;
+		}
+	}
+	fclose(fp);
+	tst_brkm(TBROK, cleanup, "no matched s = %p found.", addr_s);
+}
+
+static void setup(void)
+{
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+}

[-- Attachment #3: Type: text/plain, Size: 335 bytes --]

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. 
http://p.sf.net/sfu/wandisco-dev2dev

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH v3] mm/vma01: new testcase
  2011-08-11 14:03       ` [LTP] [PATCH v3] mm/vma01: " Caspar Zhang
@ 2011-08-11 14:20         ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2011-08-11 14:20 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

Hi!
Commited, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. 
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mm/mbind01: move to mm/vma02
  2011-08-01  1:26         ` [LTP] [PATCH] mm/mbind01: move to mm/vma02 Caspar Zhang
@ 2011-08-11 17:21           ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2011-08-11 17:21 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP List

Hi!
Commited both.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. 
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2011-08-11 18:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <145b91763d3c2670cd736cc7fa3072c9a6db219a.1312043382.git.czhang@redhat.com>
2011-07-30 17:09 ` [LTP] [PATCH] [mm] vma01: new testcase Caspar Zhang
2011-08-01  1:20   ` [LTP] [PATCH v2] " Caspar Zhang
2011-08-01  1:26     ` [LTP] [PATCH 0/2] mm/mbind01 fix Caspar Zhang
2011-08-01  1:26       ` [LTP] [PATCH] mm/mbind01: fix broken testcase Caspar Zhang
2011-08-01  1:26         ` [LTP] [PATCH] mm/mbind01: move to mm/vma02 Caspar Zhang
2011-08-11 17:21           ` Cyril Hrubis
2011-08-11 13:43     ` [LTP] [PATCH v2] [mm] vma01: new testcase Cyril Hrubis
2011-08-11 14:03       ` [LTP] [PATCH v3] mm/vma01: " Caspar Zhang
2011-08-11 14:20         ` Cyril Hrubis

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.