mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-03 21:44:33 +00:00 
			
		
		
		
	Check if we get huge pages on linux. Larry Meadows piece of magic.
This commit is contained in:
		@@ -63,4 +63,37 @@ void *PointerCache::Lookup(size_t bytes) {
 | 
				
			|||||||
  return NULL;
 | 
					  return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void check_huge_pages(void *Buf,uint64_t BYTES)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#ifdef __linux__
 | 
				
			||||||
 | 
					  int fd = open("/proc/self/pagemap", O_RDONLY);
 | 
				
			||||||
 | 
					  assert(fd >= 0);
 | 
				
			||||||
 | 
					  const int page_size = 4096;
 | 
				
			||||||
 | 
					  uint64_t virt_pfn = (uint64_t)Buf / page_size;
 | 
				
			||||||
 | 
					  off_t offset = sizeof(uint64_t) * virt_pfn;
 | 
				
			||||||
 | 
					  uint64_t npages = (BYTES + page_size-1) / page_size;
 | 
				
			||||||
 | 
					  uint64_t pagedata[npages];
 | 
				
			||||||
 | 
					  uint64_t ret = lseek(fd, offset, SEEK_SET);
 | 
				
			||||||
 | 
					  assert(ret == offset);
 | 
				
			||||||
 | 
					  ret = ::read(fd, pagedata, sizeof(uint64_t)*npages);
 | 
				
			||||||
 | 
					  assert(ret == sizeof(uint64_t) * npages);
 | 
				
			||||||
 | 
					  int nhugepages = npages / 512;
 | 
				
			||||||
 | 
					  int n4ktotal, nnothuge;
 | 
				
			||||||
 | 
					  n4ktotal = 0;
 | 
				
			||||||
 | 
					  nnothuge = 0;
 | 
				
			||||||
 | 
					  for (int i = 0; i < nhugepages; ++i) {
 | 
				
			||||||
 | 
					    uint64_t baseaddr = (pagedata[i*512] & 0x7fffffffffffffULL) * page_size;
 | 
				
			||||||
 | 
					    for (int j = 0; j < 512; ++j) {
 | 
				
			||||||
 | 
					      uint64_t pageaddr = (pagedata[i*512+j] & 0x7fffffffffffffULL) * page_size;
 | 
				
			||||||
 | 
					      ++n4ktotal;
 | 
				
			||||||
 | 
					      if (pageaddr != baseaddr + j * page_size)
 | 
				
			||||||
 | 
						++nnothuge;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  int rank = CartesianCommunicator::RankWorld();
 | 
				
			||||||
 | 
					  printf("rank %d Allocated %d 4k pages, %d not in huge pages\n", rank, n4ktotal, nnothuge);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,6 +64,8 @@ namespace Grid {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void check_huge_pages(void *Buf,uint64_t BYTES);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
////////////////////////////////////////////////////////////////////
 | 
					////////////////////////////////////////////////////////////////////
 | 
				
			||||||
// A lattice of something, but assume the something is SIMDized.
 | 
					// A lattice of something, but assume the something is SIMDized.
 | 
				
			||||||
////////////////////////////////////////////////////////////////////
 | 
					////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user