[PATCH] 2.6.8-rc2-mm1 dio cleanup

From: Badari Pulavarty
Date: Mon Aug 02 2004 - 14:07:57 EST


Hi Andrew,

I noticed this while testing DIO code on 2.6.8-rc2-mm1.

dio_pages_in_io represents the approximate IO size. We
use this to allocate bio vector. In most common cases
(where buffer is page aligned and size is multiple of pages)
we end up asking for more vectors than what we need. This
sometimes causes allocations from next biovec-pool, there
by wasting memory.

Here is the patch to fix the common case.

Thanks,
Badari


--- linux.org/fs/direct-io.c 2004-07-30 16:25:10.000000000 -0700
+++ linux/fs/direct-io.c 2004-08-02 10:45:56.000000000 -0700
@@ -954,8 +954,16 @@ direct_io_worker(int rw, struct kiocb *i
dio->waiter = NULL;

dio->pages_in_io = 0;
- for (seg = 0; seg < nr_segs; seg++)
- dio->pages_in_io += (iov[seg].iov_len >> blkbits) + 2;
+ for (seg = 0; seg < nr_segs; seg++) {
+ dio->pages_in_io += (iov[seg].iov_len >> blkbits);
+ /*
+ * if address is not page aligned or io-size is not
+ * page multiple, increase pages_in_io by 2.
+ */
+ if (((unsigned long)iov[seg].iov_base & ~PAGE_MASK) ||
+ ((unsigned long)iov[seg].iov_len & ~PAGE_MASK))
+ dio->pages_in_io += 2;
+ }

for (seg = 0; seg < nr_segs; seg++) {
user_addr = (unsigned long)iov[seg].iov_base;