#define _GNU_SOURCE 1 #include #include #include #include #include #include #include #include #include #ifndef MPOL_MF_LAZY #define MPOL_MF_LAZY (1<<3) #endif #define TOTALPAGES 262144 int nbpages, loop; int pagesize; int main(int argc, char **argv) { void *buffer; int i, err; unsigned long nodemask; int maxnode; struct timeval tv1, tv2; unsigned long us; cpu_set_t cset; /* put the thread on node 0 */ CPU_ZERO(&cset); CPU_SET(0, &cset); err = sched_setaffinity(0, sizeof(cset), &cset); if (err < 0) { perror("sched_setaffinity"); exit(-1); } pagesize = getpagesize(); maxnode = numa_max_node(); fprintf(stdout, "# Nb_pages\tCost(ns)\n"); for(nbpages=2 ; nbpages<=TOTALPAGES ; nbpages*=2) { int loops = TOTALPAGES/nbpages; if (loops > 128) loops = 128; buffer = mmap(NULL, TOTALPAGES*pagesize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (buffer == MAP_FAILED) { perror("mmap"); exit(-1); } /* bind to node 1 and prefault */ nodemask = 1<<1; err = mbind(buffer, TOTALPAGES*pagesize, MPOL_BIND, &nodemask, maxnode+2, MPOL_MF_MOVE); if (err < 0) { perror("mbind"); exit(-1); } for(i=0 ; i