#include #include #include #include #include #include #include #include #include #include #include #include #include #define HUGEPAGES "/proc/sys/vm/nr_hugepages" #define HUGE_FILE "/mnt/huge/foobar" void *huge; int main(int argc, char **argv) { uint64_t ppte; int fd, maps; if ((fd = open(HUGEPAGES, O_WRONLY, 0)) == -1) { perror(HUGEPAGES); return 1; } write(fd, "20\n", 3); close(fd); if ((fd = open(HUGE_FILE, O_RDWR | O_CREAT, 0)) == -1) { perror(HUGE_FILE); return 1; } huge = mmap((void *) 0x1000000, 0x400000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, 0); if (huge == MAP_FAILED) { perror(HUGE_FILE); return 1; } fprintf(stderr, "huge: 0x%0.*" PRIxPTR "\n", sizeof(huge) * 2, huge); memset(huge, 1, 12345); if ((maps = open("/proc/self/pagemap", O_RDONLY, 0)) < 0) { perror("/proc/self/pagemap"); return 1; } if (pread(maps, &ppte, sizeof(ppte), ((uintptr_t) huge) >> 9) < 0) { perror("pread"); return 1; } fprintf(stderr, "ppte: 0x%0.16" PRIx64 "\n", ppte); return 0; }