-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_pages.c
73 lines (59 loc) · 1.86 KB
/
move_pages.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numa.h>
#include <numaif.h> // move_pages()
#include <errno.h>
#include <unistd.h>
#include <assert.h>
#define NODE_0_DRAM 0
#define NODE_1_DRAM 1
#define NODE_2_PMEM 2
#define NODE_3_PMEM 3
int main(int argc, char **argv)
{
if (argc != 5) {
fprintf(stderr, "need 4 args: <pid> <addr> <len> <numa_node>\n");
return -1;
}
if ((numa_available() < 0)) {
fprintf(stderr, "error: not a numa machine\n");
return -1;
}
size_t pid = atol(argv[1]);
size_t addr = atol(argv[2]);
size_t len = atol(argv[3]);
unsigned node = atol(argv[4]);
//struct bitmask *new_nodes = numa_bitmask_alloc(num_nodes);
//numa_bitmask_setbit(new_nodes, node);
int num_nodes = numa_max_node() + 1;
if (num_nodes < 2) {
fprintf(stderr, "error: a minimum of 2 nodes is required\n");
exit(1);
}
// len must be page-aligned
size_t pagesize = getpagesize();
assert((len % pagesize) == 0);
unsigned long page_count = len / pagesize;
void **pages_addr;
int *status;
int *nodes;
pages_addr = malloc(sizeof(char *) * page_count);
status = malloc(sizeof(int *) * page_count);
nodes = malloc(sizeof(int *) * page_count);
if (!pages_addr || !status || !nodes) {
fprintf(stderr, "Unable to allocate memory\n");
exit(1);
}
for (int i = 0; i < page_count; i++) {
pages_addr[i] = (void *) addr + i * pagesize;
nodes[i] = node;
status[i] = -1;
}
printf("Moving pages of process %lu from addr = %lu, len = %lu, to numa node: %d\n", pid, addr, len, node);
if (numa_move_pages(pid, page_count, pages_addr, nodes, status, MPOL_MF_MOVE) == -1) {
fprintf(stderr, "error code: %d\n", errno);
perror("error description:");
}
return 0;
}