Created
December 4, 2019 18:34
-
-
Save flx42/5378397cb00488e0c6fa5d41d8c5e63f to your computer and use it in GitHub Desktop.
move_pages(2) issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* $ gcc move_pages_bug.c -lnuma -o move_pages_bug */ | |
#define _DEFAULT_SOURCE | |
#include <sys/mman.h> | |
#include <numaif.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
int main(void) | |
{ | |
const long node_id = 1; | |
const long page_size = sysconf(_SC_PAGESIZE); | |
const int64_t num_pages = 8; | |
unsigned long nodemask = 1 << node_id; | |
long ret = set_mempolicy(MPOL_BIND, &nodemask, sizeof(nodemask)); | |
if (ret < 0) | |
return (EXIT_FAILURE); | |
void **pages = malloc(sizeof(void*) * num_pages); | |
for (int i = 0; i < num_pages; ++i) { | |
pages[i] = mmap(NULL, page_size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_POPULATE | MAP_ANONYMOUS, -1, 0); | |
if (pages[i] == MAP_FAILED) | |
return (EXIT_FAILURE); | |
} | |
ret = set_mempolicy(MPOL_DEFAULT, NULL, 0); | |
if (ret < 0) | |
return (EXIT_FAILURE); | |
int *nodes = malloc(sizeof(int) * num_pages); | |
int *status = malloc(sizeof(int) * num_pages); | |
for (int i = 0; i < num_pages; ++i) { | |
nodes[i] = node_id; | |
status[i] = 0xd0; | |
} | |
ret = move_pages(0, num_pages, pages, nodes, status, MPOL_MF_MOVE); | |
printf("move_pages: %ld\n", ret); | |
for (int i = 0; i < num_pages; ++i) | |
printf("status[%d] = %d\n", i, status[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment