Skip to contentSkip to conversation

syscalls/migrate_pages03: skip migratition of shared pages

PATCH New Jan Stancek 3 participants 4 messages Nov 29, 2018 – Feb 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/migrate_pages03: skip migratition of shared pages

Fixes #431

Migrating shared pages (as root) includes also executable pages (glibc, etc.) Kernel might need to invalidate icache, which can be an expensive operation on some architectures (arm64).

This test is repeating migration thousands of times, and because migration (and icache flush) runs for each page, it all stacks up and test is hitting a timeout.

It's enough for this reproducer to migrate pages it allocates and merges (via KSM), so do the migration as unprivileged user and we can avoid the overhead of migrating everything. Such scenario is already covered by migrate_pages02.

---
 testcases/kernel/syscalls/migrate_pages/migrate_pages03.c | 7 +++++++
 1 file changed, 7 insertions(+)
testcases/kernel/syscalls/migrate_pages/migrate_pages03.c +7 -0
index ecfc55288691..7317b11283d8 100644
@@ -33,6 +33,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <pwd.h>
 
 #include "tst_test.h"
 #include "lapi/syscalls.h"
@@ -52,6 +53,8 @@ static void *test_pages[N_PAGES];
 static int num_nodes, max_node;
 static int *nodes;
 static unsigned long *new_nodes[2];
+static const char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
 
 static void setup(void)
 {
@@ -69,6 +72,8 @@ static void setup(void)
 			TEST_NODES);
 	}
 
+	ltpuser = SAFE_GETPWNAM(nobody_uid);
+
 	max_node = LTP_ALIGN(get_max_node(), sizeof(unsigned long) * 8);
 	nodemask_size = max_node / 8;
 	new_nodes[0] = SAFE_MALLOC(nodemask_size);
@@ -125,6 +130,7 @@ static void migrate_test(void)
 {
 	int loop, i, ret;
 
+	SAFE_SETEUID(ltpuser->pw_uid);
 	for (loop = 0; loop < N_LOOPS; loop++) {
 		i = loop % 2;
 		ret = tst_syscall(__NR_migrate_pages, 0, max_node,
@@ -134,6 +140,7 @@ static void migrate_test(void)
 			return;
 		}
 	}
+	SAFE_SETEUID(0);
 
 	tst_res(TPASS, "migrate_pages() passed");
 }
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 syscalls/migrate_pages03: skip migratition of shared pages

Quoted 7 lines · Jan Stancek
Fixes #431

Migrating shared pages (as root) includes also executable pages (glibc, etc.) Kernel might need to invalidate icache, which can be an expensive operation on some architectures (arm64).

Quoted 8 lines

This test is repeating migration thousands of times, and because migration (and icache flush) runs for each page, it all stacks up and test is hitting a timeout.

It's enough for this reproducer to migrate pages it allocates and merges (via KSM), so do the migration as unprivileged user and we can avoid the overhead of migrating everything. Such scenario is already covered by migrate_pages02.

I'm OK to drop privileges before calling migrate_pages() in this testcase, but if we can start a new topic in LKML for more discussion that would be better?

Quoted 2 lines

--
Regards,
Li Wang

#3 lore raw

PATCH 1/1 syscalls/migrate_pages03: skip migratition of shared pages

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

Quoted 2 lines

Hi!
Looks good to me, acked.

Pushed.

Regards,
Jan