#include #include #include #include #include #include #define SIZE (256 * 1024 * 1024) int main(int argc, char **argv) { char *ptr; int fd, i; if (argc < 2) { printf("Usage: %s \n", argv[0]); return 1; } fd = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { perror("Failed to open file"); return 1; } if (ftruncate(fd, SIZE)) { perror("Failed to truncate to full size"); return 1; } ptr = mmap(NULL, SIZE, PROT_WRITE, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED) { perror("Failed to mmap"); return 1; } /* touch each page */ for (i = 0; i < SIZE; i += 4096) ptr[i] = 1; /* Uncommenting the below line masks the problem */ /* msync(ptr, SIZE, MS_SYNC); */ if (munmap(ptr, SIZE)) { perror("Failed to munmap"); return 1; } close(fd); return 0; }