From: Daniel McNeil <daniel@osdl.org>

More testing on AIO with O_DIRECT and /dev/raw/.  Doing AIO reads was
using a lot more cpu time than using dd on the raw partition even with
the io_queue_wait patch.  Found out that aio is doing readahead even
for O_DIRECT.  Here's a patch that fixes it.



 fs/aio.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff -puN fs/aio.c~aio-dio-no-readahead fs/aio.c
--- 25/fs/aio.c~aio-dio-no-readahead	2003-08-30 15:42:30.000000000 -0700
+++ 25-akpm/fs/aio.c	2003-08-30 15:42:30.000000000 -0700
@@ -1353,15 +1353,21 @@ ssize_t aio_setup_iocb(struct kiocb *kio
 			break;
 		ret = -EINVAL;
 		if (file->f_op->aio_read) {
-			struct address_space *mapping =
-				file->f_dentry->d_inode->i_mapping;
-			unsigned long index = kiocb->ki_pos >> PAGE_CACHE_SHIFT;
-			unsigned long end = (kiocb->ki_pos + kiocb->ki_left)
-				>> PAGE_CACHE_SHIFT;
-
-			for (; index < end; index++) {
-				page_cache_readahead(mapping, &file->f_ra,
-							file, index);
+			/*
+			 * Do not do readahead for DIRECT i/o
+			 */
+			if (!(file->f_flags & O_DIRECT)) {
+				struct address_space *mapping;
+				unsigned long index;
+				unsigned long end;
+
+				mapping = file->f_dentry->d_inode->i_mapping;
+				index = kiocb->ki_pos >> PAGE_CACHE_SHIFT;
+				end = (kiocb->ki_pos + kiocb->ki_left) >>
+						PAGE_CACHE_SHIFT;
+				for (; index < end; index++)
+					page_cache_readahead(mapping,
+						&file->f_ra, file, index);
 			}
 			kiocb->ki_retry = aio_pread;
 		}

_