Direct io on block device has performance regression on 2.6.x kernel
OK, last one in the series: user level test programs that stress the kernel I/O stack. Pretty dull stuff.
- Ken
aio_null.c +76 -0
@@ -0,0 +1,76 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <sched.h> +#include <signal.h> +#include <sys/types.h> +#include <linux/ioctl.h> +#include <libaio.h> + +#define MAXAIO 1024 + +char buf[4096] __attribute__((aligned(4096))); + +io_context_t io_ctx; +struct iocb iocbpool[MAXAIO ]; +struct io_event ioevent[MAXAIO ]; + +void aio_setup (int n) +{ +int res =io_queue_init (n, &io_ctx); +if (res !=0 ) { +printf ("io_queue_setup(%d) returned %d (%s)\n" , + n, res,strerror (-res)); +exit (0 ); + } +} + +main(int argc, char* argv[]) +{ + int fd, i, status, batch; +struct iocb * iocbbatch[MAXAIO ]; +int devidx; +off_t offset; +unsigned long start, end; + + batch = argc <2 ?100 :atoi (argv[1 ]); +if (batch >=MAXAIO ) + batch =MAXAIO ; + +aio_setup (MAXAIO ); + fd =open ("/dev/raw/raw1" ,O_RDONLY ); + +if (fd ==-1 ) { +perror ("error opening\n" ); +exit (0 ); + } +for (i=0 ; i<batch; i++) { + iocbbatch[i] = iocbpool+i; +io_prep_pread (iocbbatch[i], fd, buf,4096 ,0 ); + } + +while (1 ) { +struct timespec ts={30 ,0 }; +int bufidx; +int reap; + + status =io_submit (io_ctx, i, iocbbatch); +if (status != i) { +printf ("bad io_submit: %d [%s]\n" , status, +strerror (-status)); + } + +// reap at least batch count back + reap =io_getevents (io_ctx, batch,MAXAIO , ioevent, &ts); +if (reap < batch) { +printf ("io_getevents returned=%d [%s]\n" , reap, +strerror (-reap)); + } + +// check the return result of each event +for (i=0 ; i<reap; i++) +if (ioevent[i].res !=4096 ) +printf ("error in read: %lx\n" , ioevent[i].res); + }/* while (1) */ +}
pread_null.c +27 -0
@@ -0,0 +1,27 @@ +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <malloc.h> + +main(int argc, char* argv[]) +{ + int fd; +char *addr; + + fd =open ("/dev/raw/raw1" ,O_RDONLY ); +if (fd ==-1 ) { +perror ("error opening\n" ); +exit (0 ); + } + + addr =memalign (4096 ,4096 ); +if (addr ==0 ) { +printf ("no memory\n" ); +exit (0 ); + } + +while (1 ) { +pread (fd, addr,4096 ,0 ); + } + +}
makefile +10 -0
@@ -0,0 +1,10 @@ +all: pread_null aio_null + +pread_null: pread_null.c + gcc -O3 -o $@ pread_null.c + +aio_null: aio_null.c + gcc -O3 -o $@ aio_null.c -laio + +clean: + rm -f pread_null aio_null