32 clarg::argBool mig_mp(
"-mig_mp",
"Use move_pages when migrating pages.");
33 clarg::argBool mig_mbind(
"-mig_mbind",
"Use mbind when migrating pages.");
40 clarg::argBool mig_hwloc(
"-mig_hwloc",
"Use hwloc when migrating pages.");
48 hwloc_topology_init(&hw_topo);
49 hwloc_topology_load(hw_topo);
53 for (obj = hwloc_get_obj_by_type(hw_topo, HWLOC_OBJ_PU, 0);
obj; obj = obj->parent)
54 if (obj->type == HWLOC_OBJ_CACHE)
55 HwCacheSize += obj->attr->cache.size;
64 hwloc_topology_destroy(hw_topo);
68 #if defined (USING_HWLOC) || defined (USING_LIBNUMA) 75 void TPZPageMigrationManager::MigrateToLocal(
char* start, uint64_t size_in_bytes) {
77 if (mig_mp.was_set()) {
78 MigrateToLocalMovePages(start, size_in_bytes);
81 else if (mig_mbind.was_set()) {
82 MigrateToLocalMbind(start, size_in_bytes);
88 if (mig_hwloc.was_set()) {
89 MigrateToLocalHwloc(start, size_in_bytes);
97 const int64_t PAGE_EXP = 12;
98 const int64_t PAGE_SZ = (1<<12);
99 const int64_t PAGE_MSK = ((1<<PAGE_EXP)-1);
106 void TPZPageMigrationManager::MigrateToLocalMovePages(
char* start, uint64_t size_in_bytes) {
109 if ( (ret=sched_getcpu()) < 0) {
110 printf(
"sched_getcpu(...) returned %d\n", ret);
117 uint64_t nodemask = 1 << node;
118 uint64_t maxnode = 9;
119 int64_t page_start = (int64_t) start;
120 page_start = page_start & ~PAGE_MSK;
121 int64_t last_page = (int64_t) start + (int64_t) size_in_bytes;
122 last_page = last_page & ~PAGE_MSK;
123 int64_t count = (last_page - page_start + PAGE_SZ) >> PAGE_EXP;
124 void** pages = (
void**) malloc(count*
sizeof(
void*));
125 int* nodes = (
int*) malloc(count*
sizeof(
int));
126 int*
status = (
int*) malloc(count*
sizeof(
int));
127 for (
int i=0; i<count; i++) {
128 pages[i] = (
void*) (page_start + PAGE_SZ*i);
132 if ( (ret = move_pages(0 , count , pages, nodes, status, MPOL_MF_MOVE)) != 0) {
134 fprintf(stderr,
"move_pages(0, npages(%ld), pages, nodes (%u), status, MPOL_MF_MOVE) = %d (cpu=%d, node=%d)\n",
135 count, node, ret, cpu, node);
136 fprintf(stderr,
"errno (%d) = %s\n", err, strerror(err));
146 void TPZPageMigrationManager::MigrateToLocalMbind(
char* start, uint64_t size_in_bytes) {
149 if ( (ret=sched_getcpu()) < 0) {
150 printf(
"sched_getcpu(...) returned %d\n", ret);
157 uint64_t nodemask = 1 << node;
160 uint64_t maxnode = 9;
161 int64_t page_start = (int64_t) start;
162 page_start = page_start & ~PAGE_MSK;
163 int64_t last_page = (int64_t) start + (int64_t) size_in_bytes;
164 last_page = last_page & ~PAGE_MSK;
165 int64_t nbytes = last_page - page_start + PAGE_SZ;
166 #ifndef MPOL_F_STATIC_NODES 167 #define MPOL_F_STATIC_NODES (1 << 15) 169 if ( (ret = mbind((
void*) page_start, nbytes, MPOL_BIND , &nodemask, maxnode, MPOL_MF_MOVE) ) != 0 ) {
172 fprintf(stderr,
"ERROR: mbind(start=%ld, sz=%ld, MPOL_BIND, nodemask = %08ld (node = %u), maxnode = %lu, MPOL_MF_MOVE) = %d\n",
173 page_start, nbytes, nodemask, node, maxnode, ret);
174 fprintf(stderr,
"errno (%d) = %s\n", err, strerror(err));
180 fprintf(stderr,
"mbind(start=%ld, sz=%ld, MPOL_BIND, nodemask = %08ld (node = %d), maxnode = %lu, MPOL_MF_MOVE) = %d\n",
181 page_start, nbytes, nodemask, node, maxnode, ret);
194 void TPZPageMigrationManager::MigrateToLocalHwloc(
char* start, uint64_t size_in_bytes) {
200 hwloc_cpuset_t last = hwloc_bitmap_alloc();
201 if ( (ret=hwloc_get_last_cpu_location(hw_topo, last, HWLOC_CPUBIND_THREAD)) != 0) {
202 fprintf(stderr,
"ERROR: hwloc_get_last_cpu_location(...) returned %d\n", ret);
204 if (hwloc_bitmap_iszero(last)) {
205 fprintf(stderr,
"ERROR: hwloc_get_last_cpu_location returned a zeroed bit vector.\n");
208 int64_t page_start = (int64_t) start;
209 int64_t last_page = (int64_t) start + (int64_t) size_in_bytes;
210 page_start = page_start & ~PAGE_MSK;
211 last_page = last_page & ~PAGE_MSK;
212 int64_t nbytes = last_page - page_start + PAGE_SZ;
214 if ( (ret=sched_getcpu()) < 0) {
215 printf(
"getcpu(...) returned %d\n",ret);
222 hwloc_bitmap_snprintf(buffer,256,last);
224 printf(
"migrate: start = 0x%ld, page_start = 0x%ld, #bytes = %ld (nbytes = %ld), last = %s, getcpu(cpu=%d,node=%d)\n",
225 (int64_t) start, (int64_t) page_start, (int64_t) size_in_bytes, nbytes, buffer,cpu,node);
227 if ( (ret = hwloc_set_area_membind(hw_topo, (
const void*) page_start, nbytes,
228 (hwloc_const_cpuset_t)last, HWLOC_MEMBIND_BIND,
229 HWLOC_MEMBIND_MIGRATE )) != 0 ) {
231 fprintf(stderr,
"hwloc_set_area_membind(hw_topo, page_start=0x%ld, sz=%ld, set, HWLOC_MEMBIND_BIND, HWLOC_MEMBIND_MIGRAGE) = %d\n",
232 page_start, nbytes, ret);
233 fprintf(stderr,
"errno (%d) = %s\n", err, strerror(err));
235 hwloc_bitmap_free(last);
242 #if defined (USING_HWLOC) || defined (USING_LIBNUMA) 243 MigrationManager.MigrateToLocal(start, sz_in_bytes);
245 fprintf(stderr,
"PZ compiled without page migration support. Compile with USING_HWLOC or USING_LIBNUMA.");
Contains declaration of the TPZPageMigrationManager class which implements methods to migrate data in...
~TPZPageMigrationManager()
Destroy hwloc topology when the lib is enabled.
void migrate_to_local(char *start, uint64_t sz_in_bytes)
TPZPageMigrationManager MigrationManager
TPZPageMigrationManager()
Initialize hwloc tolopology when the lib is enabled.