From d08565c651b03a9ad1f4f9612d98737aa5fdcd62 Mon Sep 17 00:00:00 2001 From: Erez_Zadok Date: Sat, 14 Jul 2007 03:46:13 -0400 Subject: [PATCH] In the mmap-testing backend program, read the mmap'ed file completely. Instead of reading just the first byte of the file, read a few bytes in each page, all the way to the end of the file, so we touch the entire file. This is useful to simulate memory-pressure conditions. --- progs/mapper.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/progs/mapper.c b/progs/mapper.c index c18e157..411f141 100644 --- a/progs/mapper.c +++ b/progs/mapper.c @@ -30,11 +30,10 @@ #include #define BASE 0 -#define SIZE 10 #ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) -#endif +#endif /* not MAP_FAILED */ void usage(void) { @@ -50,6 +49,8 @@ main(int argc, char *argv[]) caddr_t pa; int rw_flag = -1; /* 0=read, 1=read+write */ char *filename, byte; + int i, size; + struct stat buf; /* check input args */ if (argc != 3) @@ -63,6 +64,13 @@ main(int argc, char *argv[]) filename = argv[2]; + /* find size of file */ + if (stat(filename, &buf) < 0) { + perror("stat"); + exit(1); + } + size = buf.st_size; + /* open input file */ if (rw_flag) fd = open(filename, O_RDWR); @@ -76,7 +84,7 @@ main(int argc, char *argv[]) /* mmap the input file */ pa = mmap((caddr_t) 0, - SIZE, + size, (rw_flag ? (PROT_READ | PROT_WRITE) : PROT_READ), MAP_SHARED, fd, @@ -87,24 +95,28 @@ main(int argc, char *argv[]) } printf("file is mapped with address %p\n", pa); - /* now read the first byte of that file */ - byte = pa[0]; - printf("byte 0 is decimal %03d (\'%c\')\n", - byte, isprint(byte) ? byte : '.'); + /* now read every 1024-th byte */ + for (i=0; i