From: Namhyung Kim <namhyung@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] dio: simple cleanup for direct_io_worker()
Date: Tue, 11 Jan 2011 21:15:04 +0900 [thread overview]
Message-ID: <1294748104-7866-2-git-send-email-namhyung@gmail.com> (raw)
In-Reply-To: <1294748104-7866-1-git-send-email-namhyung@gmail.com>
Use DIV_ROUND_UP() and offset_in_page() to make code simpler.
Signed-off-by: Namhyung Kim <namhyung@gmail.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
prev parent reply other threads:[~2011-01-11 12:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-11 12:15 [PATCH 1/2] dio: fix typos in comments Namhyung Kim
2011-01-11 12:15 ` Namhyung Kim [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1294748104-7866-2-git-send-email-namhyung@gmail.com \
--to=namhyung@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®