#define _GNU_SOURCE #include #include #include #include #include #include #include #include int main(int argc, char* argv[]) { int fd; unsigned long long int const size = 4096 * 1024; unsigned int const size_page = 1024; unsigned long long int offset = 0; unsigned int offset_page = 0; //char* buffer = valloc(size); //memset(buffer, 0, size); if (argc != 2) { printf("usage: %s \n", argv[0]); return 0; } fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE /*| O_DIRECT*/, 0644); if (fd < 0) { perror("open"); return 0; } #ifdef ABUSE pwrite64(fd, "" , 1, offset + size); #else ftruncate64(fd, offset + size); #endif char* mapping = (char*)mmap64(0, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE | MAP_NONBLOCK, fd, offset); memset(mapping, 'a', size); for (;;) { offset += size; offset_page += size_page; #ifdef ABUSE pwrite64(fd, "", 1, offset + size); #else ftruncate64(fd, offset + size); #endif //munmap(mapping, size); //mapping = (char*)mmap64(0, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE | MAP_NONBLOCK, fd, offset); remap_file_pages(mapping, size, 0, offset_page, MAP_NONBLOCK); memset(mapping, 'a', size); } close(fd); return 0; }