forked from numactl/numactl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migratepages.c
100 lines (88 loc) · 2.09 KB
/
migratepages.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (C) 2005 Christoph Lameter, Silicon Graphics, Incorporated.
* based on Andi Kleen's numactl.c.
*
* Manual process migration
*
* migratepages 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; version 2.
*
* migratepages 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 find a copy of v2 of the GNU General Public License somewhere
* on your Linux system; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "numa.h"
#include "util.h"
static struct option opts[] = {
{"help", 0, 0, 'h' },
{ 0 }
};
static void usage(void)
{
fprintf(stderr,
"usage: migratepages pid from-nodes to-nodes\n"
"\n"
"nodes is a comma delimited list of node numbers or A-B ranges or all.\n"
);
exit(1);
}
static void checknuma(void)
{
static int numa = -1;
if (numa < 0) {
if (numa_available() < 0)
complain("This system does not support NUMA functionality");
}
numa = 0;
}
int main(int argc, char *argv[])
{
int c;
char *end;
int rc;
int pid;
struct bitmask *fromnodes;
struct bitmask *tonodes;
while ((c = getopt_long(argc,argv,"h", opts, NULL)) != -1) {
switch (c) {
default:
usage();
}
}
argv += optind;
argc -= optind;
if (argc != 3)
usage();
checknuma();
pid = strtoul(argv[0], &end, 0);
if (*end || end == argv[0])
usage();
fromnodes = numa_parse_nodestring(argv[1]);
if (!fromnodes) {
printf ("<%s> is invalid\n", argv[1]);
exit(1);
}
tonodes = numa_parse_nodestring(argv[2]);
if (!tonodes) {
printf ("<%s> is invalid\n", argv[2]);
exit(1);
}
rc = numa_migrate_pages(pid, fromnodes, tonodes);
if (rc < 0) {
perror("migrate_pages");
return 1;
}
return 0;
}