Skip to contentSkip to conversation

Migrate pages - v0.2 - some demos

PATCH Zoltan Menyhart 1 participant 1 message Apr 2, 2004

lore
Share & tools
lore
#0 lore raw

I include some demo programs:

test/ph.c:      migrates some of its pages by use of their physical addresses
test/v.c:       migrates a part of its virtual address range
test/vmig.c:    migrates a part of the virtual address range of "test/victim.c"
test/migstat.c: displays some internal counters if the kernel has been compiled

with "_NEED_STATISTICS_" defined

They are not too much portable, many hard coded numbers,...

Zoltán Menyhárt

test/makefile +3 -0
diff -Nur 2.4.6.ref/test/makefile 2.6.4.mig/test/makefile
@@ -0,0 +1,3 @@
+CFLAGS+=-I../include/linux -I- -I../include
+
+all:	v ph migstat victim vmig
test/migstat.c +128 -0

128 lines not on this page · raw message

test/ph.c +94 -0

94 lines not on this page · raw message

test/v.c +78 -0

78 lines not on this page · raw message

test/victim.c +36 -0
diff -Nur 2.4.6.ref/test/victim.c 2.6.4.mig/test/victim.c
@@ -0,0 +1,36 @@
+/*
+ * Victim process for "vmig".
+ */
+
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+
+#define	MMAPSIZE	(1024 * 1024 * 1024L)
+#define	N		MMAPSIZE / sizeof(long)
+
+
+main()
+{
+	int		i;
+	volatile long	*p0, *p;
+	long		sum0, sum;
+
+	printf("victim: pid = %d\n", getpid());
+	p0 = p = mmap(NULL, MMAPSIZE, PROT_READ | PROT_WRITE,
+					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	if (p == MAP_FAILED){
+		perror("\nmmap()");
+		return 1;
+	}
+	printf("address: %p, size: 0x%lx\n", p, MMAPSIZE);
+	for (i = 0, sum0 = 0; i < N; i++)
+		sum0 += *p++ = random();
+	do {
+		for (i = 0, sum = 0, p = p0; i < N; i++)
+			sum += *p++;
+		printf("\nvictim: pid = %d, sum: %ld\n", getpid(), sum);
+	} while (sum0 == sum);
+}
test/vmig.c +36 -0
diff -Nur 2.4.6.ref/test/vmig.c 2.6.4.mig/test/vmig.c
@@ -0,0 +1,36 @@
+/*
+ * Migrate the victim process by hand.
+ */
+
+
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include "page_migrate.h"
+
+// Who cares for the SH library ?
+#define	SH_ADDRESS	(2UL << 60)
+#define	SH_SIZE		(16UL * 1024 * 1024 * 1024 * 1024)
+
+struct _un_success_count_ u_s;
+
+main(const int argc, const char * const argv[])
+{
+	int	node;
+	pid_t	pid;
+	int	rc;
+
+	if (argc != 3){
+		fprintf(stderr, "usage: vmig <pid> <node>\n");
+		return 1;
+	}
+	pid = atoi(argv[1]);
+	node = atoi(argv[2]);
+	rc = migrate_virt_addr_range((caddr_t) SH_ADDRESS, SH_SIZE, node, &u_s, pid);
+	if (rc < 0)
+		perror("migrate_virt_addr_range()");
+	else
+		printf("successful: %d failed: %d\n", u_s.successful, u_s.failed);
+	return 0;
+}