/* Measure Linux overhead from mmap(). * * It doesn’t appear to depend at all on the size of the region being * mapped; it always takes about 4–6 μs per mmap call on my N3700 * laptop, up to a limit of some 65515 mmap calls (a rather suggestive * number). */ #include #include #include #include #include #include int main(int argc, char **argv) { int n = atoi(argv[1]), m = atoi(argv[2]); char *filename = "nk-of-zeroes.tmp"; int fd = open(filename, O_WRONLY | O_CREAT, 0666); if (fd < 0) { perror(filename); return 1; } char zeroes[n]; memset(zeroes, 0, n); if (write(fd, zeroes, sizeof(zeroes)) < 0) { perror("write"); return 1; } close(fd); fd = open(filename, O_RDONLY); if (fd < 0) { perror("read open"); return 1; } for (int i = 0; i < m; i++) { if (MAP_FAILED == mmap(0, n, PROT_READ, MAP_SHARED, fd, 0)) { perror("mmap"); return 1; } } close(fd); unlink(filename); return 0; }