Skip to contentSkip to conversation

new syscall testcases: migrate_pages

PATCH Superseded Jan Stancek 2 participants 9 messages Oct 18, 2012 – Oct 24, 2012

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover new syscall testcases: migrate_pages

Changes in v2:
- add parse_opts
- add new testcases to runtest/syscalls
- add parenthesis to else blocks where needed
- replace drop_caches with check for free memory

Jan Stancek (3):
numa_helper: export get_max_node()
new syscall test: migrate_pages01
new syscall test: migrate_pages02

 runtest/syscalls                                   |    3 +
 testcases/kernel/include/numa_helper.h             |    1 +
 testcases/kernel/lib/numa_helper.c                 |    6 +-
 testcases/kernel/syscalls/migrate_pages/Makefile   |   32 ++
 .../syscalls/migrate_pages/migrate_pages01.c       |  280 +++++++++++++++
 .../syscalls/migrate_pages/migrate_pages02.c       |  363 ++++++++++++++++++++
 .../syscalls/migrate_pages/migrate_pages_common.c  |   62 ++++
 .../syscalls/migrate_pages/migrate_pages_common.h  |   33 ++
 8 files changed, 778 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/migrate_pages/Makefile
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h

------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#1 lore raw

PATCH v2 1/3 numa_helper: export get_max_node()

Allow tests to use get_max_node().

---
 testcases/kernel/include/numa_helper.h |    1 +
 testcases/kernel/lib/numa_helper.c     |    6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/include/numa_helper.h +1 -0
index 463019a..0be7a28 100644
@@ -30,6 +30,7 @@
 #define NH_MEMS (1 << 0)
 #define NH_CPUS (1 << 1)
 
+unsigned long get_max_node();
 int get_allowed_nodes_arr(int flag, int *num_nodes, int **nodes);
 int get_allowed_nodes(int flag, int count, ...);
 void nh_dump_nodes();
testcases/kernel/lib/numa_helper.c +4 -2
index aa98522..32d81a9 100644
@@ -37,10 +37,10 @@
 #include "numa_helper.h"
 #include "linux_syscall_numbers.h"
 
-#if HAVE_NUMA_H
-static unsigned long get_max_node()
+unsigned long get_max_node()
 {
 	unsigned long max_node = 0;
+#if HAVE_NUMA_H
 #if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
 	max_node = NUMA_NUM_NODES;
 	/*
@@ -53,9 +53,11 @@ static unsigned long get_max_node()
 #else
 	max_node = numa_max_possible_node() + 1;
 #endif
+#endif /* HAVE_NUMA_H */
 	return max_node;
 }
 
+#if HAVE_NUMA_H
 static void get_nodemask_allnodes(nodemask_t *nodemask,
 	unsigned long max_node)
 {
Signature · 12 lines
1.7.1


------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#2 lore raw

PATCH v2 2/3 new syscall test: migrate_pages01

In reply to Jan Stancek

errno tests for migrate_pages(2).
Note, that older kernels (~2.6.18) are likely to panic during this test.

---
 runtest/syscalls                                   |    2 +
 testcases/kernel/syscalls/migrate_pages/Makefile   |   32 +++
 .../syscalls/migrate_pages/migrate_pages01.c       |  280 ++++++++++++++++++++
 .../syscalls/migrate_pages/migrate_pages_common.c  |   62 +++++
 .../syscalls/migrate_pages/migrate_pages_common.h  |   33 +++
 5 files changed, 409 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/migrate_pages/Makefile
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h
runtest/syscalls +2 -0
index 6973aaa..9daf234 100644
@@ -517,6 +517,8 @@ memset01 memset01
 memcmp01 memcmp01
 memcpy01 memcpy01
 
+migrate_pages01 migrate_pages01
+
 mlockall01 mlockall01
 mlockall02 mlockall02
 mlockall03 mlockall03
testcases/kernel/syscalls/migrate_pages/Makefile new file +32 -0
new file mode 100644
index 0000000..7168cd6
@@ -0,0 +1,32 @@
+#
+#  Copyright (C) 2012 Linux Test Project, 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+MAKE_TARGETS		:= $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*[0-9].c))
+$(MAKE_TARGETS): %: %.o migrate_pages_common.o
+
+ifeq ($(NUMA_LIBS),)
+CPPFLAGS		+= -Wno-unused
+endif
+CPPFLAGS		+= -I$(abs_srcdir)/../utils/
+
+include $(top_srcdir)/testcases/kernel/include/lib.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/migrate_pages/migrate_pages01.c new file +280 -0

280 lines not on this page · raw message

testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c new file +62 -0

62 lines not on this page · raw message

testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h new file +33 -0
new file mode 100644
index 0000000..d821b07
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 Linux Test Project, 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.
+ */
+
+#ifndef MIGRATE_PAGES_COMMON_H
+#define MIGRATE_PAGES_COMMON_H
+
+#define bitsperlong (8 * sizeof(unsigned long))
+
+void set_bit(unsigned long *b, unsigned int n, unsigned int v);
+int check_ret(long expected_ret);
+int check_errno(long expected_errno);
+#endif
Signature · 12 lines
1.7.1


------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw

Re: [LTP] [PATCH v2 2/3] new syscall test: migrate_pages01

Hi Jan,

Quoted 389 lines · Jan Stancek

errno tests for migrate_pages(2).
Note, that older kernels (~2.6.18) are likely to panic during this test.

---
  runtest/syscalls                                   |    2 +
  testcases/kernel/syscalls/migrate_pages/Makefile   |   32 +++
  .../syscalls/migrate_pages/migrate_pages01.c       |  280 ++++++++++++++++++++
  .../syscalls/migrate_pages/migrate_pages_common.c  |   62 +++++
  .../syscalls/migrate_pages/migrate_pages_common.h  |   33 +++
  5 files changed, 409 insertions(+), 0 deletions(-)

create mode 100644 testcases/kernel/syscalls/migrate_pages/Makefile create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages01.c create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h

runtest/syscalls +2 -0
index 6973aaa..9daf234 100644
@@ -517,6 +517,8 @@ memset01 memset01
  memcmp01 memcmp01
  memcpy01 memcpy01
 
+migrate_pages01 migrate_pages01
+
  mlockall01 mlockall01
  mlockall02 mlockall02
  mlockall03 mlockall03
testcases/kernel/syscalls/migrate_pages/Makefile new file +32 -0
new file mode 100644
index 0000000..7168cd6
@@ -0,0 +1,32 @@
+#
+#  Copyright (C) 2012 Linux Test Project, 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+MAKE_TARGETS		:= $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*[0-9].c))
+$(MAKE_TARGETS): %: %.o migrate_pages_common.o
+
+ifeq ($(NUMA_LIBS),)
+CPPFLAGS		+= -Wno-unused
+endif
+CPPFLAGS		+= -I$(abs_srcdir)/../utils/
+
+include $(top_srcdir)/testcases/kernel/include/lib.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/migrate_pages/migrate_pages01.c new file +280 -0
new file mode 100644
index 0000000..53ced25
@@ -0,0 +1,280 @@
+/*
+ * Copyright (C) 2012 Linux Test Project, 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.
+ */
+
+/*
+ * errno tests for migrate_pages() syscall
+ */
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <errno.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+#if HAVE_NUMAIF_H
+#include <numaif.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pwd.h>
+#include "config.h"
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "linux_syscall_numbers.h"
+#include "numa_helper.h"
+#include "migrate_pages_common.h"
+
+char *TCID = "migrate_pages01";
+int  TST_TOTAL = 1;
+
+option_t options[] = {
+	{ NULL, NULL, NULL }
+};
+
+#if defined(__NR_migrate_pages) && defined(HAVE_NUMA_H)
+static unsigned long *sane_old_nodes;
+static unsigned long *sane_new_nodes;
+static int sane_nodemask_size;
+static int sane_max_node;
+
+static void setup(void);
+static void cleanup(void);
+
+static void test_sane_nodes(void)
+{
+	tst_resm(TINFO, "test_empty_mask");
+	TEST(syscall(__NR_migrate_pages, 0, sane_max_node,
+		sane_old_nodes, sane_new_nodes));
+	check_ret(0);
+}
+
+static void test_invalid_pid(void)
+{
+	const char pid_max[] = "/proc/sys/kernel/pid_max";
+	FILE *fp;
+	char buff[512];
+	pid_t invalid_pid = -1;
+
+	tst_resm(TINFO, "test_invalid_pid -1");
+	TEST(syscall(__NR_migrate_pages, invalid_pid, sane_max_node,
+		sane_old_nodes, sane_new_nodes));
+	check_ret(-1);
+	check_errno(ESRCH);
+
+	tst_resm(TINFO, "test_invalid_pid pid_max+1");
+	fp = fopen(pid_max, "r");
+	if (fp == NULL)
+		tst_brkm(TBROK, cleanup,
+			"Could not open %s", pid_max);
+	if (!fgets(buff, sizeof(buff), fp))
+		tst_brkm(TBROK, cleanup,
+			"Could not read %s", pid_max);
+	fclose(fp);
+	invalid_pid = atol(buff) + 1;
+	TEST(syscall(__NR_migrate_pages, invalid_pid, sane_max_node,
+		sane_old_nodes, sane_new_nodes));
+	check_ret(-1);
+	check_errno(ESRCH);
+}
+
+static void test_invalid_masksize(void)
+{
+	tst_resm(TINFO, "test_invalid_masksize");
+	TEST(syscall(__NR_migrate_pages, 0, -1, sane_old_nodes,
+		sane_new_nodes));
+	check_ret(-1);
+	check_errno(EINVAL);
+}
+
+static void test_invalid_mem(void)
+{
+	unsigned long *p;
+
+	tst_resm(TINFO, "test_invalid_mem -1");
+	TEST(syscall(__NR_migrate_pages, 0, sane_max_node, -1, -1));
+	check_ret(-1);
+	check_errno(EFAULT);
+
+	tst_resm(TINFO, "test_invalid_mem invalid prot");
+	p = mmap(NULL, getpagesize(), PROT_NONE,
+		MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+	if (p == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+	TEST(syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
+	check_ret(-1);
+	check_errno(EFAULT);
+
+	if (munmap(p, getpagesize()) < 0)
+		tst_brkm(TBROK|TERRNO, cleanup, "munmap");
+	tst_resm(TINFO, "test_invalid_mem unmmaped");
+	TEST(syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
+	check_ret(-1);
+	check_errno(EFAULT);
+}
+
+static void test_invalid_nodes(void)
+{
+	int *nodes;
+	int num_nodes, ret, i;
+	int invalid_node = 0;
+	unsigned long *old_nodes, *new_nodes;
+
+	tst_resm(TINFO, "test_invalid_nodes");
+	ret = get_allowed_nodes_arr(NH_MEMS, &num_nodes, &nodes);
+	if (ret < 0)
+		tst_brkm(TBROK|TERRNO, cleanup,
+			"get_allowed_nodes_arr: %d", ret);
+
+	/* get first node which is not in nodes */
+	for (i = 0; i < num_nodes; i++, invalid_node++)
+		if (invalid_node != nodes[i])
+			break;
+	if (invalid_node < sane_max_node) {
+		old_nodes = SAFE_MALLOC(NULL, sane_nodemask_size);
+		new_nodes = SAFE_MALLOC(NULL, sane_nodemask_size);
+		memcpy(old_nodes, sane_old_nodes, sane_nodemask_size);
+		memset(new_nodes, 0, sane_nodemask_size);
+		set_bit(new_nodes, invalid_node, 1);
+
+		TEST(syscall(__NR_migrate_pages, 0, sane_max_node,
+			old_nodes, new_nodes));
+		check_ret(-1);
+		check_errno(EINVAL);
+		free(old_nodes);
+		free(new_nodes);
+	} else {
+		tst_resm(TCONF, "All possible nodes are present");
+	}
+
+	free(nodes);
+}
+
+static void test_invalid_perm(void)
+{
+	char nobody_uid[] = "nobody";
+	struct passwd *ltpuser;
+	int status;
+	pid_t child_pid;
+	pid_t parent_pid;
+	int ret = 0;
+
+	tst_resm(TINFO, "test_invalid_perm");
+	parent_pid = getpid();
+	fflush(stdout);
+	child_pid = fork();
+	switch (child_pid) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		break;
+	case 0:
+		ltpuser = getpwnam(nobody_uid);
+		if (ltpuser == NULL)
+			tst_brkm(TBROK|TERRNO, NULL,
+					"getpwnam failed");
+		if (setuid(ltpuser->pw_uid) == -1)
+			tst_brkm(TBROK|TERRNO, NULL,
+					"setuid(%u) failed",
+					ltpuser->pw_uid);
+		TEST(syscall(__NR_migrate_pages, parent_pid,
+			sane_max_node, sane_old_nodes,
+			sane_new_nodes));
+		ret |= check_ret(-1);
+		ret |= check_errno(EPERM);
+		exit(ret);
+	default:
+		if (waitpid(child_pid, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "child returns %d", status);
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+
+	msg = parse_opts(argc, argv, options, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		test_sane_nodes();
+		test_invalid_pid();
+		test_invalid_masksize();
+		test_invalid_mem();
+		test_invalid_nodes();
+		test_invalid_perm();
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	int node, ret;
+
+	tst_require_root(NULL);
+	TEST(syscall(__NR_migrate_pages, 0, 0, NULL, NULL));
+
+	if (numa_available() == -1)
+		tst_brkm(TCONF, NULL, "NUMA not available");
+
+	ret = get_allowed_nodes(NH_MEMS, 1, &node);
+	if (ret < 0)
+		tst_brkm(TBROK|TERRNO, NULL, "get_allowed_nodes_arr: %d", ret);
+
+	sane_max_node = get_max_node();
+	sane_nodemask_size = sane_max_node/8+1;
+	sane_old_nodes = SAFE_MALLOC(NULL, sane_nodemask_size);
+	sane_new_nodes = SAFE_MALLOC(NULL, sane_nodemask_size);
+	memset(sane_old_nodes, 0, sane_nodemask_size);
+	memset(sane_new_nodes, 0, sane_nodemask_size);
+
+	set_bit(sane_old_nodes, node, 1);
+	set_bit(sane_new_nodes, node, 1);
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	free(sane_old_nodes);
+	free(sane_new_nodes);
+	TEST_CLEANUP;
+}
+
+#else /* __NR_migrate_pages */
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages"
+			" or libnuma is not available");
+}
+#endif
testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c new file +30 -0
new file mode 100644
index 0000000..00b512a
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 Linux Test Project, 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 "migrate_pages_common.h"
+
+void set_bit(unsigned long *b, unsigned int n, unsigned int v)
+{

testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c line 40

Quoted 10 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c new file +10 -0
+	if (v)
+		b[n/bitsperlong] |= 1UL << (n % bitsperlong);
+	else
+		b[n/bitsperlong] &= ~(1UL << (n % bitsperlong));
+}
+
+int check_ret(long expected_ret)
+{
+	if (expected_ret == TEST_RETURN) {
+		tst_resm(TPASS, "expected ret success - "

here maybe changing it as
tst_resm(TPASS, "expected ret success: "
^
looks more friendly:

e.g: migrate_pages01 14 TPASS : expected ret success: returned
value = -1

others look good for me, and I tested it on normal, 2/8 NUMA system, they are all good.

so Reviewed-by: ZhoupingLiu <[email protected]>

Thanks,
Zhouping

Quoted 51 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c new file +22 -0
+			"returned value = %ld", TEST_RETURN);
+		return 0;
+	} else
+		tst_resm(TFAIL, "unexpected failure - "
+			"returned value = %ld, expected: %ld",
+			TEST_RETURN, expected_ret);
+	return 1;
+}
+
+int check_errno(long expected_errno)
+{
+	if (TEST_ERRNO == expected_errno) {
+		tst_resm(TPASS|TTERRNO, "expected failure");
+		return 0;
+	} else if (TEST_ERRNO == 0)
+		tst_resm(TFAIL, "call succeeded unexpectedly");
+	else
+		tst_resm(TFAIL|TTERRNO, "unexpected failure - "
+			"expected = %ld : %s, actual",
+			expected_errno, strerror(expected_errno));
+	return 1;
+}
testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h new file +23 -0
new file mode 100644
index 0000000..d821b07
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 Linux Test Project, 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.
+ */

testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h line 33

Quoted 10 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages_common.h new file +10 -0
+
+#ifndef MIGRATE_PAGES_COMMON_H
+#define MIGRATE_PAGES_COMMON_H
+
+#define bitsperlong (8 * sizeof(unsigned long))
+
+void set_bit(unsigned long *b, unsigned int n, unsigned int v);
+int check_ret(long expected_ret);
+int check_errno(long expected_errno);
+#endif

------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw

PATCH v2 3/3 new syscall test: migrate_pages02

In reply to Jan Stancek

Use migrate_pages() syscall and check that shared/non-shared memory is migrated to desired node.

---
 runtest/syscalls                                   |    1 +
 .../syscalls/migrate_pages/migrate_pages02.c       |  363 ++++++++++++++++++++
 2 files changed, 364 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
runtest/syscalls +1 -0
index 9daf234..78f3bd3 100644
@@ -518,6 +518,7 @@ memcmp01 memcmp01
 memcpy01 memcpy01
 
 migrate_pages01 migrate_pages01
+migrate_pages02 migrate_pages02
 
 mlockall01 mlockall01
 mlockall02 mlockall02
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +363 -0

363 lines not on this page · raw message

Signature · 12 lines
1.7.1


------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw

Re: [LTP] [PATCH 3/3 v2] new syscall test: migrate_pages02

Hi Jan,

Quoted 74 lines · Jan Stancek

Use migrate_pages() syscall and check that shared/non-shared memory is migrated to desired node.

---
  runtest/syscalls                                   |    1 +
  .../syscalls/migrate_pages/migrate_pages02.c       |  363 ++++++++++++++++++++
  2 files changed, 364 insertions(+), 0 deletions(-)

create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages02.c

runtest/syscalls +1 -0
index 9daf234..78f3bd3 100644
@@ -518,6 +518,7 @@ memcmp01 memcmp01
  memcpy01 memcpy01
 
  migrate_pages01 migrate_pages01
+migrate_pages02 migrate_pages02
 
  mlockall01 mlockall01
  mlockall02 mlockall02
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +46 -0
new file mode 100644
index 0000000..840aa2b
@@ -0,0 +1,363 @@
+/*
+ * Copyright (C) 2012 Linux Test Project, 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.
+ */
+
+/*
+ * use migrate_pages() and check that address is on correct node
+ * 1. process A can migrate its non-shared mem with CAP_SYS_NICE
+ * 2. process A can migrate its non-shared mem without CAP_SYS_NICE
+ * 3. process A can migrate shared mem only with CAP_SYS_NICE
+ * 4. process A can migrate non-shared mem in process B with same effective uid
+ * 5. process A can migrate non-shared mem in process B with CAP_SYS_NICE
+ */
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <errno.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+#if HAVE_NUMAIF_H
+#include <numaif.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 56

Quoted 10 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +10 -0
+#include <pwd.h>
+#include "config.h"
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "linux_syscall_numbers.h"
+#include "numa_helper.h"
+#include "migrate_pages_common.h"
+
+#define NODE_MIN_FREEMEM 32*1024*1024

I think we can give some comments to explain why the minimum free memory is 32M.

Quoted 39 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +39 -0
+
+char *TCID = "migrate_pages02";
+int  TST_TOTAL = 1;
+
+#if defined(__NR_migrate_pages) && HAVE_NUMA_H && HAVE_NUMAIF_H
+static char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
+static int *nodes, nodeA, nodeB;
+static int num_nodes;
+
+static void setup(void);
+static void cleanup(void);
+
+option_t options[] = {
+	{ NULL, NULL, NULL }
+};
+
+static int migrate_to_node(int pid, int node)
+{
+	unsigned long nodemask_size, max_node;
+	unsigned long *old_nodes, *new_nodes;
+	int i;
+
+	tst_resm(TPASS, "pid(%d) migrate pid %d to node -> %d",
+		getpid(), pid, node);
+	max_node = get_max_node();
+	nodemask_size = max_node/8+1;
+	old_nodes = SAFE_MALLOC(NULL, nodemask_size);
+	new_nodes = SAFE_MALLOC(NULL, nodemask_size);
+
+	memset(old_nodes, 0, nodemask_size);
+	memset(new_nodes, 0, nodemask_size);
+	for (i = 0; i < num_nodes; i++)
+		set_bit(old_nodes, nodes[i], 1);
+	set_bit(new_nodes, node, 1);
+
+	TEST(syscall(__NR_migrate_pages, pid, max_node, old_nodes, new_nodes));
+	if (TEST_RETURN == -1)
+		tst_resm(TFAIL|TERRNO, "migrate_pages failed ");

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 105

Quoted 10 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +10 -0
+	return TEST_RETURN;
+}
+
+static int addr_on_node(void *addr)
+{
+	int node;
+	int ret;
+
+	ret = syscall(__NR_get_mempolicy, &node, NULL, (unsigned long)0,
+			(unsigned long) addr, MPOL_F_NODE | MPOL_F_ADDR);

get_mempolicy() syscall is defined as

int get_mempolicy(int *mode, unsigned long *nodemask,
unsigned long maxnode, unsigned long addr, unsigned long flags);

and the 1st arg is the policy of memory, the 2nd arg is nodemask, but in your codes, the 1st arg is '&node', I'm confusing how it can implement to get the node id of address?

Thanks,
Zhouping

Quoted 248 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +248 -0
+	if (ret == -1) {
+		tst_resm(TBROK | TERRNO, "error getting memory policy "
+				"for page %p", addr);
+	}
+	return node;
+}
+
+static int check_addr_on_node(void *addr, int exp_node)
+{
+	int node;
+
+	node = addr_on_node(addr);
+	if (node == exp_node) {
+		tst_resm(TPASS, "pid(%d) addr %p is on expected node: %d",
+				getpid(), addr, exp_node);
+		return 0;
+	} else {
+		tst_resm(TFAIL, "pid(%d) addr %p not on expected node: %d "
+				", expected %d", getpid(), addr, node,
+				exp_node);
+		return 1;
+	}
+}
+
+static void test_migrate_current_process(int node1, int node2,
+	int cap_sys_nice)
+{
+	char *testp, *testp2;
+	int ret, status;
+	pid_t child;
+
+	/* parent can migrate its non-shared memory */
+	tst_resm(TINFO, "current_process, cap_sys_nice: %d", cap_sys_nice);
+	testp = SAFE_MALLOC(NULL, getpagesize());
+	testp[0] = 0;
+	tst_resm(TINFO, "private anonymous: %p", testp);
+	migrate_to_node(0, node2);
+	check_addr_on_node(testp, node2);
+	migrate_to_node(0, node1);
+	check_addr_on_node(testp, node1);
+	free(testp);
+
+	/* parent can migrate shared memory with CAP_SYS_NICE */
+	testp2 = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
+		MAP_ANONYMOUS|MAP_SHARED, 0, 0);
+	if (testp2 == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap failed");
+	testp2[0] = 1;
+	tst_resm(TINFO, "shared anonymous: %p", testp2);
+	migrate_to_node(0, node2);
+	check_addr_on_node(testp2, node2);
+
+	/* shared mem is on node2, try to migrate in child to node1 */
+	fflush(stdout);
+	child = fork();
+	switch (child) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		break;
+	case 0:
+		tst_resm(TINFO, "child shared anonymous, cap_sys_nice: %d",
+			cap_sys_nice);
+		testp = SAFE_MALLOC(NULL, getpagesize());
+		testp[0] = 1;
+		testp2[0] = 1;
+		if (!cap_sys_nice)
+			if (seteuid(ltpuser->pw_uid) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		migrate_to_node(0, node1);
+		/* child can migrate non-shared memory */
+		ret = check_addr_on_node(testp, node1);
+
+		free(testp);
+		munmap(testp2, getpagesize());
+		exit(ret);
+	default:
+		if (waitpid(child, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "child returns %d", status);
+		if (cap_sys_nice)
+			/* child can migrate shared memory only
+			 * with CAP_SYS_NICE */
+			check_addr_on_node(testp2, node1);
+		else
+			check_addr_on_node(testp2, node2);
+		munmap(testp2, getpagesize());
+	}
+}
+
+static void test_migrate_other_process(int node1, int node2,
+	int cap_sys_nice)
+{
+	char *testp;
+	int status, ret, tmp;
+	pid_t child;
+	int child_ready[2];
+	int pages_migrated[2];
+
+	/* setup pipes to synchronize child/parent */
+	if (pipe(child_ready) == -1)
+		tst_resm(TBROK | TERRNO, "pipe #1 failed");
+	if (pipe(pages_migrated) == -1)
+		tst_resm(TBROK | TERRNO, "pipe #2 failed");
+
+	tst_resm(TINFO, "other_process, cap_sys_nice: %d", cap_sys_nice);
+
+	fflush(stdout);
+	child = fork();
+	switch (child) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		break;
+	case 0:
+		close(child_ready[0]);
+		close(pages_migrated[1]);
+
+		testp = SAFE_MALLOC(NULL, getpagesize());
+		testp[0] = 0;
+
+		/* make sure we are on node1 */
+		migrate_to_node(0, node1);
+		check_addr_on_node(testp, node1);
+
+		if (seteuid(ltpuser->pw_uid) == -1)
+			tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		/* signal parent it's OK to migrate child and wait */
+		if (write(child_ready[1], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "write #1 failed");
+		if (read(pages_migrated[0], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "read #1 failed");
+
+		/* parent can migrate child process with same euid */
+		/* parent can migrate child process with CAP_SYS_NICE */
+		ret = check_addr_on_node(testp, node2);
+
+		free(testp);
+		close(child_ready[1]);
+		close(pages_migrated[0]);
+		exit(ret);
+	default:
+		close(child_ready[1]);
+		close(pages_migrated[0]);
+
+		if (!cap_sys_nice)
+			if (seteuid(ltpuser->pw_uid) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		/* wait until child is ready on node1, then migrate and
+		 * signal to check current node */
+		if (read(child_ready[0], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "read #2 failed");
+		migrate_to_node(child, node2);
+		if (write(pages_migrated[1], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "write #2 failed");
+
+		if (waitpid(child, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "child returns %d", status);
+		close(child_ready[0]);
+		close(pages_migrated[1]);
+
+		/* reset euid, so this testcase can be used in loop */
+		if (!cap_sys_nice)
+			if (seteuid(0) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+
+	msg = parse_opts(argc, argv, options, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		test_migrate_current_process(nodeA, nodeB, 1);
+		test_migrate_current_process(nodeA, nodeB, 0);
+		test_migrate_other_process(nodeA, nodeB, 1);
+		test_migrate_other_process(nodeA, nodeB, 0);
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	int ret, i;
+	long long freep, maxA, maxB, node_size;
+
+	tst_require_root(NULL);
+	TEST(syscall(__NR_migrate_pages, 0, 0, NULL, NULL));
+
+	if (numa_available() == -1)
+		tst_brkm(TCONF, NULL, "NUMA not available");
+
+	ret = get_allowed_nodes_arr(NH_MEMS, &num_nodes, &nodes);
+	if (ret < 0)
+		tst_brkm(TBROK|TERRNO, NULL, "get_allowed_nodes(): %d", ret);
+
+	if (num_nodes < 2)
+		tst_brkm(TCONF, NULL, "at least 2 allowed NUMA nodes"
+				" are required");
+	else if (tst_kvercmp(2, 6, 18) < 0)
+		tst_brkm(TCONF, NULL, "2.6.18 or greater kernel required");
+
+	/* get 2 nodes with max free mem */
+	maxA = maxB = 0;
+	nodeA = nodeB = -1;
+	for (i=0; i<num_nodes; i++) {
+		node_size = numa_node_size64(nodes[i], &freep);
+		if (node_size < 0)
+			tst_brkm(TBROK|TERRNO, NULL, "numa_node_size64 failed");
+		if (freep > NODE_MIN_FREEMEM) {
+			if (freep > maxA) {
+				maxB = maxA;
+				nodeB = nodeA;
+				maxA = freep;
+				nodeA = nodes[i];
+			} else if (freep > maxB) {
+				maxB = freep;
+				nodeB = nodes[i];
+			}
+		}
+	}
+
+	if (nodeA == -1 || nodeB == -1)
+		tst_brkm(TCONF, NULL, "at least 2 NUMA nodes with free mem > %d are needed", NODE_MIN_FREEMEM);
+	tst_resm(TINFO, "Using nodes: %d %d", nodeA, nodeB);
+
+	ltpuser = getpwnam(nobody_uid);
+	if (ltpuser == NULL)
+		tst_brkm(TBROK|TERRNO, NULL, "getpwnam failed");
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	free(nodes);

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 363

Quoted 10 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +10 -0
+	TEST_CLEANUP;
+}
+
+#else /* __NR_migrate_pages */
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages"
+			" or libnuma is not available");
+}
+#endif

------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#6 lore raw

Re: [LTP] [PATCH 3/3 v2] new syscall test: migrate_pages02

----- Original Message -----

Quoted 103 lines

From: "Zhouping Liu" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Friday, 19 October, 2012 11:48:15 AM
Subject: Re: [LTP] [PATCH 3/3 v2] new syscall test: migrate_pages02

Hi Jan,

Quoted 94 lines · Jan Stancek

Use migrate_pages() syscall and check that shared/non-shared memory is migrated to desired node.

---
  runtest/syscalls                                   |    1 +
  .../syscalls/migrate_pages/migrate_pages02.c       |  363
  ++++++++++++++++++++
  2 files changed, 364 insertions(+), 0 deletions(-)

create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages02.c

runtest/syscalls +1 -0
index 9daf234..78f3bd3 100644
@@ -518,6 +518,7 @@ memcmp01 memcmp01
  memcpy01 memcpy01
 
  migrate_pages01 migrate_pages01
+migrate_pages02 migrate_pages02
 
  mlockall01 mlockall01
  mlockall02 mlockall02

diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file mode 100644
index 0000000..840aa2b

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +5 -0
@@ -0,0 +1,363 @@
+/*
+ * Copyright (C) 2012 Linux Test Project, 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.
+ */

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +5 -0
+
+/*
+ * use migrate_pages() and check that address is on correct node
+ * 1. process A can migrate its non-shared mem with CAP_SYS_NICE
+ * 2. process A can migrate its non-shared mem without

CAP_SYS_NICE
+ * 3. process A can migrate shared mem only with CAP_SYS_NICE
+ * 4. process A can migrate non-shared mem in process B with same effective uid
+ * 5. process A can migrate non-shared mem in process B with CAP_SYS_NICE
+ */

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +20 -0
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <errno.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+#if HAVE_NUMAIF_H
+#include <numaif.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pwd.h>
+#include "config.h"
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "linux_syscall_numbers.h"
Quoted 8 lines

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 56

Quoted 4 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +4 -0
+#include "numa_helper.h"
+#include "migrate_pages_common.h"
+
+#define NODE_MIN_FREEMEM 32*1024*1024

I think we can give some comments to explain why the minimum free memory
is 32M.

It's mostly a guessed number. migrate_pages will fail if there is not enough free space on node. So while running this test on x86_64 I counted 2048 pages (total VM, not just RSS). Largest (non-huge) page size I've seen was 16k (ia64), so 2048*16k == 32M should be safe limit.

Thinking about it more, we could parse Vm* from /proc/pid/status to be more accurate, but then if we come too close to real minimum required some background process can grab few pages and test can easily fail.

Regardless of how we set lower limit, it would be useful to check/print free mem on each node if migrate_pages() fails.

Quoted 54 lines
Quoted 41 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +37 -0
+
+char *TCID = "migrate_pages02";
+int  TST_TOTAL = 1;
+
+#if defined(__NR_migrate_pages) && HAVE_NUMA_H && HAVE_NUMAIF_H
+static char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
+static int *nodes, nodeA, nodeB;
+static int num_nodes;
+
+static void setup(void);
+static void cleanup(void);
+
+option_t options[] = {
+	{ NULL, NULL, NULL }
+};
+
+static int migrate_to_node(int pid, int node)
+{
+	unsigned long nodemask_size, max_node;
+	unsigned long *old_nodes, *new_nodes;
+	int i;
+
+	tst_resm(TPASS, "pid(%d) migrate pid %d to node -> %d",
+		getpid(), pid, node);
+	max_node = get_max_node();
+	nodemask_size = max_node/8+1;
+	old_nodes = SAFE_MALLOC(NULL, nodemask_size);
+	new_nodes = SAFE_MALLOC(NULL, nodemask_size);
+
+	memset(old_nodes, 0, nodemask_size);
+	memset(new_nodes, 0, nodemask_size);
+	for (i = 0; i < num_nodes; i++)
+		set_bit(old_nodes, nodes[i], 1);
+	set_bit(new_nodes, node, 1);
+
+	TEST(syscall(__NR_migrate_pages, pid, max_node, old_nodes,

new_nodes));

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +2 -0
+	if (TEST_RETURN == -1)
+		tst_resm(TFAIL|TERRNO, "migrate_pages failed ");

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 105

Quoted 10 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +10 -0
+	return TEST_RETURN;
+}
+
+static int addr_on_node(void *addr)
+{
+	int node;
+	int ret;
+
+	ret = syscall(__NR_get_mempolicy, &node, NULL, (unsigned long)0,
+			(unsigned long) addr, MPOL_F_NODE | MPOL_F_ADDR);

get_mempolicy() syscall is defined as

Quoted 7 lines

int get_mempolicy(int *mode, unsigned long *nodemask,
unsigned long maxnode, unsigned long addr, unsigned long flags);

and the 1st arg is the policy of memory, the 2nd arg is nodemask, but in your codes, the 1st arg is '&node', I'm confusing how it can implement to get the node id of address?

get_mempolicy(2):
If flags specifies both MPOL_F_NODE and MPOL_F_ADDR, get_mempolicy() will return the node ID of the node on which the address addr is allocated into the location pointed to by mode.

Regards,
Jan

Quoted 255 lines

Thanks,
Zhouping

Quoted 252 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +33 -0
+	if (ret == -1) {
+		tst_resm(TBROK | TERRNO, "error getting memory policy "
+				"for page %p", addr);
+	}
+	return node;
+}
+
+static int check_addr_on_node(void *addr, int exp_node)
+{
+	int node;
+
+	node = addr_on_node(addr);
+	if (node == exp_node) {
+		tst_resm(TPASS, "pid(%d) addr %p is on expected node: %d",
+				getpid(), addr, exp_node);
+		return 0;
+	} else {
+		tst_resm(TFAIL, "pid(%d) addr %p not on expected node: %d "
+				", expected %d", getpid(), addr, node,
+				exp_node);
+		return 1;
+	}
+}
+
+static void test_migrate_current_process(int node1, int node2,
+	int cap_sys_nice)
+{
+	char *testp, *testp2;
+	int ret, status;
+	pid_t child;
+
+	/* parent can migrate its non-shared memory */
+	tst_resm(TINFO, "current_process, cap_sys_nice: %d",

cap_sys_nice);

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +203 -0
+	testp = SAFE_MALLOC(NULL, getpagesize());
+	testp[0] = 0;
+	tst_resm(TINFO, "private anonymous: %p", testp);
+	migrate_to_node(0, node2);
+	check_addr_on_node(testp, node2);
+	migrate_to_node(0, node1);
+	check_addr_on_node(testp, node1);
+	free(testp);
+
+	/* parent can migrate shared memory with CAP_SYS_NICE */
+	testp2 = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
+		MAP_ANONYMOUS|MAP_SHARED, 0, 0);
+	if (testp2 == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap failed");
+	testp2[0] = 1;
+	tst_resm(TINFO, "shared anonymous: %p", testp2);
+	migrate_to_node(0, node2);
+	check_addr_on_node(testp2, node2);
+
+	/* shared mem is on node2, try to migrate in child to node1 */
+	fflush(stdout);
+	child = fork();
+	switch (child) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		break;
+	case 0:
+		tst_resm(TINFO, "child shared anonymous, cap_sys_nice: %d",
+			cap_sys_nice);
+		testp = SAFE_MALLOC(NULL, getpagesize());
+		testp[0] = 1;
+		testp2[0] = 1;
+		if (!cap_sys_nice)
+			if (seteuid(ltpuser->pw_uid) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		migrate_to_node(0, node1);
+		/* child can migrate non-shared memory */
+		ret = check_addr_on_node(testp, node1);
+
+		free(testp);
+		munmap(testp2, getpagesize());
+		exit(ret);
+	default:
+		if (waitpid(child, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "child returns %d", status);
+		if (cap_sys_nice)
+			/* child can migrate shared memory only
+			 * with CAP_SYS_NICE */
+			check_addr_on_node(testp2, node1);
+		else
+			check_addr_on_node(testp2, node2);
+		munmap(testp2, getpagesize());
+	}
+}
+
+static void test_migrate_other_process(int node1, int node2,
+	int cap_sys_nice)
+{
+	char *testp;
+	int status, ret, tmp;
+	pid_t child;
+	int child_ready[2];
+	int pages_migrated[2];
+
+	/* setup pipes to synchronize child/parent */
+	if (pipe(child_ready) == -1)
+		tst_resm(TBROK | TERRNO, "pipe #1 failed");
+	if (pipe(pages_migrated) == -1)
+		tst_resm(TBROK | TERRNO, "pipe #2 failed");
+
+	tst_resm(TINFO, "other_process, cap_sys_nice: %d", cap_sys_nice);
+
+	fflush(stdout);
+	child = fork();
+	switch (child) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		break;
+	case 0:
+		close(child_ready[0]);
+		close(pages_migrated[1]);
+
+		testp = SAFE_MALLOC(NULL, getpagesize());
+		testp[0] = 0;
+
+		/* make sure we are on node1 */
+		migrate_to_node(0, node1);
+		check_addr_on_node(testp, node1);
+
+		if (seteuid(ltpuser->pw_uid) == -1)
+			tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		/* signal parent it's OK to migrate child and wait */
+		if (write(child_ready[1], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "write #1 failed");
+		if (read(pages_migrated[0], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "read #1 failed");
+
+		/* parent can migrate child process with same euid */
+		/* parent can migrate child process with CAP_SYS_NICE */
+		ret = check_addr_on_node(testp, node2);
+
+		free(testp);
+		close(child_ready[1]);
+		close(pages_migrated[0]);
+		exit(ret);
+	default:
+		close(child_ready[1]);
+		close(pages_migrated[0]);
+
+		if (!cap_sys_nice)
+			if (seteuid(ltpuser->pw_uid) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		/* wait until child is ready on node1, then migrate and
+		 * signal to check current node */
+		if (read(child_ready[0], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "read #2 failed");
+		migrate_to_node(child, node2);
+		if (write(pages_migrated[1], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "write #2 failed");
+
+		if (waitpid(child, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "child returns %d", status);
+		close(child_ready[0]);
+		close(pages_migrated[1]);
+
+		/* reset euid, so this testcase can be used in loop */
+		if (!cap_sys_nice)
+			if (seteuid(0) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+
+	msg = parse_opts(argc, argv, options, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		test_migrate_current_process(nodeA, nodeB, 1);
+		test_migrate_current_process(nodeA, nodeB, 0);
+		test_migrate_other_process(nodeA, nodeB, 1);
+		test_migrate_other_process(nodeA, nodeB, 0);
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	int ret, i;
+	long long freep, maxA, maxB, node_size;
+
+	tst_require_root(NULL);
+	TEST(syscall(__NR_migrate_pages, 0, 0, NULL, NULL));
+
+	if (numa_available() == -1)
+		tst_brkm(TCONF, NULL, "NUMA not available");
+
+	ret = get_allowed_nodes_arr(NH_MEMS, &num_nodes, &nodes);
+	if (ret < 0)
+		tst_brkm(TBROK|TERRNO, NULL, "get_allowed_nodes(): %d", ret);
+
+	if (num_nodes < 2)
+		tst_brkm(TCONF, NULL, "at least 2 allowed NUMA nodes"
+				" are required");
+	else if (tst_kvercmp(2, 6, 18) < 0)
+		tst_brkm(TCONF, NULL, "2.6.18 or greater kernel required");
+
+	/* get 2 nodes with max free mem */
+	maxA = maxB = 0;
+	nodeA = nodeB = -1;
+	for (i=0; i<num_nodes; i++) {
+		node_size = numa_node_size64(nodes[i], &freep);
+		if (node_size < 0)
+			tst_brkm(TBROK|TERRNO, NULL, "numa_node_size64 failed");
+		if (freep > NODE_MIN_FREEMEM) {
+			if (freep > maxA) {
+				maxB = maxA;
+				nodeB = nodeA;
+				maxA = freep;
+				nodeA = nodes[i];
+			} else if (freep > maxB) {
+				maxB = freep;
+				nodeB = nodes[i];
+			}
+		}
+	}
+
+	if (nodeA == -1 || nodeB == -1)
+		tst_brkm(TCONF, NULL, "at least 2 NUMA nodes with free mem > %d

are needed", NODE_MIN_FREEMEM);

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +14 -0
+	tst_resm(TINFO, "Using nodes: %d %d", nodeA, nodeB);
+
+	ltpuser = getpwnam(nobody_uid);
+	if (ltpuser == NULL)
+		tst_brkm(TBROK|TERRNO, NULL, "getpwnam failed");
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	free(nodes);
+	TEST_CLEANUP;
+}
Quoted 10 lines

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 363

Quoted 8 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +8 -0
+
+#else /* __NR_migrate_pages */
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages"
+			" or libnuma is not available");
+}
+#endif

------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reviewed-by
#7 lore raw

Re: [LTP] [PATCH 3/3 v2] new syscall test: migrate_pages02

Quoted 112 lines · Jan Stancek

----- Original Message -----

Quoted 102 lines

From: "Zhouping Liu" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Friday, 19 October, 2012 11:48:15 AM
Subject: Re: [LTP] [PATCH 3/3 v2] new syscall test: migrate_pages02

Hi Jan,

Quoted 93 lines · Jan Stancek

Use migrate_pages() syscall and check that shared/non-shared memory is migrated to desired node.

---
   runtest/syscalls                                   |    1 +
   .../syscalls/migrate_pages/migrate_pages02.c       |  363
   ++++++++++++++++++++
   2 files changed, 364 insertions(+), 0 deletions(-)

create mode 100644 testcases/kernel/syscalls/migrate_pages/migrate_pages02.c

runtest/syscalls +1 -0
index 9daf234..78f3bd3 100644
@@ -518,6 +518,7 @@ memcmp01 memcmp01
   memcpy01 memcpy01
 
   migrate_pages01 migrate_pages01
+migrate_pages02 migrate_pages02
 
   mlockall01 mlockall01
   mlockall02 mlockall02

diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file mode 100644
index 0000000..840aa2b

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +5 -0
@@ -0,0 +1,363 @@
+/*
+ * Copyright (C) 2012 Linux Test Project, 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.
+ */

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +5 -0
+
+/*
+ * use migrate_pages() and check that address is on correct node
+ * 1. process A can migrate its non-shared mem with CAP_SYS_NICE
+ * 2. process A can migrate its non-shared mem without

CAP_SYS_NICE
+ * 3. process A can migrate shared mem only with CAP_SYS_NICE
+ * 4. process A can migrate non-shared mem in process B with same effective uid
+ * 5. process A can migrate non-shared mem in process B with CAP_SYS_NICE
+ */

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +19 -0
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <errno.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+#if HAVE_NUMAIF_H
+#include <numaif.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pwd.h>
+#include "config.h"
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
Quoted 8 lines

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 56

Quoted 5 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +5 -0
+#include "linux_syscall_numbers.h"
+#include "numa_helper.h"
+#include "migrate_pages_common.h"
+
+#define NODE_MIN_FREEMEM 32*1024*1024

I think we can give some comments to explain why the minimum free memory
is 32M.

Quoted 4 lines

It's mostly a guessed number. migrate_pages will fail if there is not enough free space on node. So while running this test on x86_64 I counted 2048 pages (total VM, not just RSS). Largest (non-huge) page size I've seen was 16k (ia64), so 2048*16k == 32M should be safe limit.

OK, I have no doubt now.

Quoted 7 lines

Thinking about it more, we could parse Vm* from /proc/pid/status to be more accurate, but then if we come too close to real minimum required some background process can grab few pages and test can easily fail.

Regardless of how we set lower limit, it would be useful to check/print free mem on each node if migrate_pages() fails.

yes, agreed.

Quoted 57 lines
Quoted 57 lines
Quoted 41 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +37 -0
+
+char *TCID = "migrate_pages02";
+int  TST_TOTAL = 1;
+
+#if defined(__NR_migrate_pages) && HAVE_NUMA_H && HAVE_NUMAIF_H
+static char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
+static int *nodes, nodeA, nodeB;
+static int num_nodes;
+
+static void setup(void);
+static void cleanup(void);
+
+option_t options[] = {
+	{ NULL, NULL, NULL }
+};
+
+static int migrate_to_node(int pid, int node)
+{
+	unsigned long nodemask_size, max_node;
+	unsigned long *old_nodes, *new_nodes;
+	int i;
+
+	tst_resm(TPASS, "pid(%d) migrate pid %d to node -> %d",
+		getpid(), pid, node);
+	max_node = get_max_node();
+	nodemask_size = max_node/8+1;
+	old_nodes = SAFE_MALLOC(NULL, nodemask_size);
+	new_nodes = SAFE_MALLOC(NULL, nodemask_size);
+
+	memset(old_nodes, 0, nodemask_size);
+	memset(new_nodes, 0, nodemask_size);
+	for (i = 0; i < num_nodes; i++)
+		set_bit(old_nodes, nodes[i], 1);
+	set_bit(new_nodes, node, 1);
+
+	TEST(syscall(__NR_migrate_pages, pid, max_node, old_nodes,

new_nodes));

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +2 -0
+	if (TEST_RETURN == -1)
+		tst_resm(TFAIL|TERRNO, "migrate_pages failed ");

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 105

Quoted 10 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +10 -0
+	return TEST_RETURN;
+}
+
+static int addr_on_node(void *addr)
+{
+	int node;
+	int ret;
+
+	ret = syscall(__NR_get_mempolicy, &node, NULL, (unsigned long)0,
+			(unsigned long) addr, MPOL_F_NODE | MPOL_F_ADDR);

get_mempolicy() syscall is defined as

int get_mempolicy(int *mode, unsigned long *nodemask,
unsigned long maxnode, unsigned long addr, unsigned long flags);

Quoted 7 lines
Quoted 3 lines

and the 1st arg is the policy of memory, the 2nd arg is nodemask, but in your codes, the 1st arg is '&node', I'm confusing how it can implement to get the node id of address?

get_mempolicy(2):
If flags specifies both MPOL_F_NODE and MPOL_F_ADDR, get_mempolicy() will return the node ID of the node on which the address addr is allocated into the location pointed to by mode.

I admit I was lazy for not checking full man page, sorry for that :(

Quoted 236 lines

Regards,
Jan

Quoted 232 lines

Thanks,
Zhouping

Quoted 230 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +33 -0
+	if (ret == -1) {
+		tst_resm(TBROK | TERRNO, "error getting memory policy "
+				"for page %p", addr);
+	}
+	return node;
+}
+
+static int check_addr_on_node(void *addr, int exp_node)
+{
+	int node;
+
+	node = addr_on_node(addr);
+	if (node == exp_node) {
+		tst_resm(TPASS, "pid(%d) addr %p is on expected node: %d",
+				getpid(), addr, exp_node);
+		return 0;
+	} else {
+		tst_resm(TFAIL, "pid(%d) addr %p not on expected node: %d "
+				", expected %d", getpid(), addr, node,
+				exp_node);
+		return 1;
+	}
+}
+
+static void test_migrate_current_process(int node1, int node2,
+	int cap_sys_nice)
+{
+	char *testp, *testp2;
+	int ret, status;
+	pid_t child;
+
+	/* parent can migrate its non-shared memory */
+	tst_resm(TINFO, "current_process, cap_sys_nice: %d",

cap_sys_nice);

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +196 -0
+	testp = SAFE_MALLOC(NULL, getpagesize());
+	testp[0] = 0;
+	tst_resm(TINFO, "private anonymous: %p", testp);
+	migrate_to_node(0, node2);
+	check_addr_on_node(testp, node2);
+	migrate_to_node(0, node1);
+	check_addr_on_node(testp, node1);
+	free(testp);
+
+	/* parent can migrate shared memory with CAP_SYS_NICE */
+	testp2 = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
+		MAP_ANONYMOUS|MAP_SHARED, 0, 0);
+	if (testp2 == MAP_FAILED)
+		tst_brkm(TBROK|TERRNO, cleanup, "mmap failed");
+	testp2[0] = 1;
+	tst_resm(TINFO, "shared anonymous: %p", testp2);
+	migrate_to_node(0, node2);
+	check_addr_on_node(testp2, node2);
+
+	/* shared mem is on node2, try to migrate in child to node1 */
+	fflush(stdout);
+	child = fork();
+	switch (child) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		break;
+	case 0:
+		tst_resm(TINFO, "child shared anonymous, cap_sys_nice: %d",
+			cap_sys_nice);
+		testp = SAFE_MALLOC(NULL, getpagesize());
+		testp[0] = 1;
+		testp2[0] = 1;
+		if (!cap_sys_nice)
+			if (seteuid(ltpuser->pw_uid) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		migrate_to_node(0, node1);
+		/* child can migrate non-shared memory */
+		ret = check_addr_on_node(testp, node1);
+
+		free(testp);
+		munmap(testp2, getpagesize());
+		exit(ret);
+	default:
+		if (waitpid(child, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "child returns %d", status);
+		if (cap_sys_nice)
+			/* child can migrate shared memory only
+			 * with CAP_SYS_NICE */
+			check_addr_on_node(testp2, node1);
+		else
+			check_addr_on_node(testp2, node2);
+		munmap(testp2, getpagesize());
+	}
+}
+
+static void test_migrate_other_process(int node1, int node2,
+	int cap_sys_nice)
+{
+	char *testp;
+	int status, ret, tmp;
+	pid_t child;
+	int child_ready[2];
+	int pages_migrated[2];
+
+	/* setup pipes to synchronize child/parent */
+	if (pipe(child_ready) == -1)
+		tst_resm(TBROK | TERRNO, "pipe #1 failed");
+	if (pipe(pages_migrated) == -1)
+		tst_resm(TBROK | TERRNO, "pipe #2 failed");
+
+	tst_resm(TINFO, "other_process, cap_sys_nice: %d", cap_sys_nice);
+
+	fflush(stdout);
+	child = fork();
+	switch (child) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+		break;
+	case 0:
+		close(child_ready[0]);
+		close(pages_migrated[1]);
+
+		testp = SAFE_MALLOC(NULL, getpagesize());
+		testp[0] = 0;
+
+		/* make sure we are on node1 */
+		migrate_to_node(0, node1);
+		check_addr_on_node(testp, node1);
+
+		if (seteuid(ltpuser->pw_uid) == -1)
+			tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		/* signal parent it's OK to migrate child and wait */
+		if (write(child_ready[1], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "write #1 failed");
+		if (read(pages_migrated[0], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "read #1 failed");
+
+		/* parent can migrate child process with same euid */
+		/* parent can migrate child process with CAP_SYS_NICE */
+		ret = check_addr_on_node(testp, node2);
+
+		free(testp);
+		close(child_ready[1]);
+		close(pages_migrated[0]);
+		exit(ret);
+	default:
+		close(child_ready[1]);
+		close(pages_migrated[0]);
+
+		if (!cap_sys_nice)
+			if (seteuid(ltpuser->pw_uid) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+
+		/* wait until child is ready on node1, then migrate and
+		 * signal to check current node */
+		if (read(child_ready[0], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "read #2 failed");
+		migrate_to_node(child, node2);
+		if (write(pages_migrated[1], &tmp, 1) != 1)
+			tst_brkm(TBROK|TERRNO, NULL, "write #2 failed");
+
+		if (waitpid(child, &status, 0) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+			tst_resm(TFAIL, "child returns %d", status);
+		close(child_ready[0]);
+		close(pages_migrated[1]);
+
+		/* reset euid, so this testcase can be used in loop */
+		if (!cap_sys_nice)
+			if (seteuid(0) == -1)
+				tst_brkm(TBROK|TERRNO, NULL, "seteuid failed");
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+
+	msg = parse_opts(argc, argv, options, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		test_migrate_current_process(nodeA, nodeB, 1);
+		test_migrate_current_process(nodeA, nodeB, 0);
+		test_migrate_other_process(nodeA, nodeB, 1);
+		test_migrate_other_process(nodeA, nodeB, 0);
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	int ret, i;
+	long long freep, maxA, maxB, node_size;
+
+	tst_require_root(NULL);
+	TEST(syscall(__NR_migrate_pages, 0, 0, NULL, NULL));
+
+	if (numa_available() == -1)
+		tst_brkm(TCONF, NULL, "NUMA not available");
+
+	ret = get_allowed_nodes_arr(NH_MEMS, &num_nodes, &nodes);
+	if (ret < 0)
+		tst_brkm(TBROK|TERRNO, NULL, "get_allowed_nodes(): %d", ret);
+
+	if (num_nodes < 2)
+		tst_brkm(TCONF, NULL, "at least 2 allowed NUMA nodes"
+				" are required");
+	else if (tst_kvercmp(2, 6, 18) < 0)
+		tst_brkm(TCONF, NULL, "2.6.18 or greater kernel required");
+
+	/* get 2 nodes with max free mem */
+	maxA = maxB = 0;
+	nodeA = nodeB = -1;
+	for (i=0; i<num_nodes; i++) {
+		node_size = numa_node_size64(nodes[i], &freep);
+		if (node_size < 0)
+			tst_brkm(TBROK|TERRNO, NULL, "numa_node_size64 failed");
+		if (freep > NODE_MIN_FREEMEM) {
+			if (freep > maxA) {
+				maxB = maxA;
+				nodeB = nodeA;
+				maxA = freep;
+				nodeA = nodes[i];
+			} else if (freep > maxB) {
+				maxB = freep;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +7 -0
+				nodeB = nodes[i];
+			}
+		}
+	}
+
+	if (nodeA == -1 || nodeB == -1)
+		tst_brkm(TCONF, NULL, "at least 2 NUMA nodes with free mem > %d

are needed", NODE_MIN_FREEMEM);

there's a litter cavil, this line exceed 80 characters.

the rest look good for me, so

Thanks,
Zhouping

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +15 -0
+	tst_resm(TINFO, "Using nodes: %d %d", nodeA, nodeB);
+
+	ltpuser = getpwnam(nobody_uid);
+	if (ltpuser == NULL)
+		tst_brkm(TBROK|TERRNO, NULL, "getpwnam failed");
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	free(nodes);
+	TEST_CLEANUP;
+}
+
Quoted 8 lines
Quoted 8 lines

testcases/kernel/syscalls/migrate_pages/migrate_pages02.c line 363

Quoted 7 lines
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c new file +7 -0
+#else /* __NR_migrate_pages */
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages"
+			" or libnuma is not available");
+}
+#endif

------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#8 lore raw

Re: [LTP] [PATCH 3/3 v2] new syscall test: migrate_pages02

----- Original Message -----

Quoted 7 lines

From: "Zhouping Liu" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Sunday, 21 October, 2012 10:51:49 AM
Subject: Re: [LTP] [PATCH 3/3 v2] new syscall test: migrate_pages02

Quoted 7 lines

the rest look good for me, so

Thanks,
Zhouping

Thanks, I'll send v3 with your suggestions. I came across one scenario where migrate_pages() reports success, but pages are not moved. I'm trying to figure out whether this is real bug or something wrong with testcase.

Regards,
Jan

------------------------------------------------------------------------------
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_sfd2d_oct
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list