By default not used (ppl just have to edit the DEFINES in their Makefile) but worth getting into the tree now for later tinkering (specifically, madvise() behavior checking and diff memory copy methods). If anyone happens to have or be running a kernel with chuck lever's madvise() patch, please try with and w/o -DUSE_MADVISE. Otherwise, seeing some good read/write vs. mmap() results should be interesting (although I get the feeling I could have done the memory copy's a little better... hmmm) James
diff -ru tiotest-0.24/ChangeLog tiotest-0.24.mmap/ChangeLog --- tiotest-0.24/ChangeLog Wed Feb 16 10:25:16 2000 +++ tiotest-0.24.mmap/ChangeLog Thu Mar 2 02:34:14 2000 @@ -88,3 +88,8 @@ * 0.24 - prompt to STDERR and not printing ^H s any more - minor tiobench.pl cleanup by James + +2000-03-02 James Manning <[EMAIL PROTECTED]> + + * 0.25 - add optional use of mmap()-based IO ifdef'd on USE_MMAP + - add optional use of madvise() to control kernel paging USE_MADVISE diff -ru tiotest-0.24/Makefile tiotest-0.24.mmap/Makefile --- tiotest-0.24/Makefile Fri Feb 11 18:25:33 2000 +++ tiotest-0.24.mmap/Makefile Thu Mar 2 02:39:56 2000 @@ -3,6 +3,7 @@ CC=gcc #CFLAGS=-O3 -fomit-frame-pointer -Wall CFLAGS=-O2 -Wall +#DEFINES=-DUSE_MMAP -DUSE_MADVISE DEFINES= LINK=gcc EXE=tiotest diff -ru tiotest-0.24/tiotest.c tiotest-0.24.mmap/tiotest.c --- tiotest-0.24/tiotest.c Wed Feb 16 10:25:30 2000 +++ tiotest-0.24.mmap/tiotest.c Thu Mar 2 02:39:45 2000 @@ -19,7 +19,7 @@ #include "tiotest.h" -static const char* versionStr = "tiotest v0.24 (C) Mika Kuoppala <[EMAIL PROTECTED]>"; +static const char* versionStr = "tiotest v0.25 (C) Mika Kuoppala <[EMAIL PROTECTED]>"; /* This is global for easier usage. If you put changing data @@ -513,23 +513,46 @@ off_t blocks=(d->fileSizeInMBytes*MBYTE)/d->blockSize; off_t i; +#ifdef USE_MMAP + off_t bytesize=blocks*d->blockSize; /* truncates down to BS multiple */ + void *file_loc; +#endif + fd = open(d->fileName, O_RDWR | O_CREAT | O_TRUNC, 0600 ); if(fd == -1) perror("Error opening file"); +#ifdef USE_MMAP + ftruncate(fd,bytesize); /* pre-allocate space */ + file_loc=mmap(NULL,bytesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); + if(file_loc == MAP_FAILED) + perror("Error mmap()ing file"); +#ifdef USE_MADVISE + /* madvise(file_loc,bytesize,MADV_DONTNEED); */ + madvise(file_loc,bytesize,MADV_RANDOM); +#endif +#endif + timer_start( &(d->writeTimings) ); for(i = 0; i < blocks; i++) { +#ifdef USE_MMAP + memcpy(file_loc + i * d->blockSize,buf,d->blockSize); +#else if( write( fd, buf, d->blockSize ) != d->blockSize ) { perror("Error writing to file"); break; } - +#endif d->blocksWrite++; } +#ifdef USE_MMAP + munmap(file_loc,bytesize); +#endif + fsync(fd); close(fd); @@ -547,26 +570,44 @@ int fd; off_t blocks=(d->fileSizeInMBytes*MBYTE)/d->blockSize; off_t i; +#ifdef USE_MMAP + off_t bytesize=blocks*d->blockSize; /* truncates down to BS multiple */ + void *file_loc; +#endif fd = open(d->fileName, O_RDONLY); if(fd == -1) perror("Error opening file"); +#ifdef USE_MMAP + file_loc=mmap(NULL,bytesize,PROT_READ,MAP_SHARED,fd,0); +#ifdef USE_MADVISE + /* madvise(file_loc,bytesize,MADV_DONTNEED); */ + madvise(file_loc,bytesize,MADV_RANDOM); +#endif +#endif + timer_start( &(d->readTimings) ); for(i = 0; i < blocks; i++) { +#ifdef USE_MMAP + memcpy(buf,file_loc + i * d->blockSize,d->blockSize); +#else if( read( fd, buf, d->blockSize ) != d->blockSize ) { perror("Error read from file"); break; } - +#endif d->blocksRead++; } timer_stop( &(d->readTimings) ); +#ifdef MMAP + munmap(file_loc,bytesize); +#endif close(fd); return 0; diff -ru tiotest-0.24/tiotest.h tiotest-0.24.mmap/tiotest.h --- tiotest-0.24/tiotest.h Fri Feb 4 14:40:27 2000 +++ tiotest-0.24.mmap/tiotest.h Wed Mar 1 14:19:14 2000 @@ -14,6 +14,10 @@ #include <getopt.h> #endif +#ifdef USE_MMAP +#include <sys/mman.h> +#endif + #define KBYTE 1024 #define MBYTE (1024*KBYTE)