/* * cc -o hfill2 hfill2.c */ #include #include #include #include #define __USE_GNU #include #include #include #include #include #define DIRPATH "/dev/hugepages/tdir" #define USAGE "USAGE: %s num_hpages num_files\n" #define H_PAGESIZE (2*1024*1024) long long hpages, tpage; char *del_hpage; int main(int argc, char ** argv) { char *f_name; char *sep; int fd, ret, sys_ret; int i, j; long retry_count; char *addr; int dontfill = 1; char fname[80]; int nfile; int nfiles; pid_t p; if (argc < 3) { printf(USAGE, argv[0]); exit (1); } hpages = strtol(argv[1], &sep, 0); if (errno || hpages < 0) { printf("Invalid number hpages (%s)\n", argv[1]); printf(USAGE, argv[0]); exit (1); } nfiles = atoi(argv[2]); p = getpid(); while (nfiles--) { sprintf(fname, "%s/nf%d", DIRPATH, nfiles); // fd = open(fname, O_CREAT | O_RDWR, 0755); fd = open(fname, O_RDWR, 0755); if (fd < 0) { //perror("Open failed"); //exit(1); continue; } //unlink(fname); // mmap and access addr = mmap(NULL, hpages * H_PAGESIZE, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { perror("mmap"); exit(1); } for (i = 0; i < hpages ; i++) { addr[i * H_PAGESIZE] = 1; } munmap(addr, hpages * H_PAGESIZE); ftruncate(fd, H_PAGESIZE); close(fd); //unlink(fname); } pause(); }