[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1294748104-7866-2-git-send-email-namhyung@gmail.com>
Date: Tue, 11 Jan 2011 21:15:04 +0900
From: Namhyung Kim <namhyung@...il.com>
To: Alexander Viro <viro@...iv.linux.org.uk>
Cc: linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] dio: simple cleanup for direct_io_worker()
Use DIV_ROUND_UP() and offset_in_page() to make code simpler.
Signed-off-by: Namhyung Kim <namhyung@...il.com>
---
fs/direct-io.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 8201c2558d85..7ba681412bd4 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1020,16 +1020,19 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
for (seg = 0; seg < nr_segs; seg++) {
user_addr = (unsigned long)iov[seg].iov_base;
dio->pages_in_io +=
- ((user_addr+iov[seg].iov_len +PAGE_SIZE-1)/PAGE_SIZE
+ (DIV_ROUND_UP(user_addr + iov[seg].iov_len, PAGE_SIZE)
- user_addr/PAGE_SIZE);
}
for (seg = 0; seg < nr_segs; seg++) {
+ unsigned page_offset;
+
user_addr = (unsigned long)iov[seg].iov_base;
dio->size += bytes = iov[seg].iov_len;
+ page_offset = offset_in_page(user_addr);
/* Index into the first page of the first block */
- dio->first_block_in_page = (user_addr & ~PAGE_MASK) >> blkbits;
+ dio->first_block_in_page = page_offset >> blkbits;
dio->final_block_in_request = dio->block_in_file +
(bytes >> blkbits);
/* Page fetching state */
@@ -1038,11 +1041,11 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
dio->curr_page = 0;
dio->total_pages = 0;
- if (user_addr & (PAGE_SIZE-1)) {
+ if (page_offset) {
dio->total_pages++;
- bytes -= PAGE_SIZE - (user_addr & (PAGE_SIZE - 1));
+ bytes -= PAGE_SIZE - page_offset;
}
- dio->total_pages += (bytes + PAGE_SIZE - 1) / PAGE_SIZE;
+ dio->total_pages += DIV_ROUND_UP(bytes, PAGE_SIZE);
dio->curr_user_address = user_addr;
ret = do_direct_IO(dio);
--
1.7.3.4.600.g982838b0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists