From: Ming Lei <ming.lei@canonical.com>
To: linux-kernel@vger.kernel.org, Dave Kleikamp <dave.kleikamp@oracle.com>
Cc: Jens Axboe <axboe@kernel.dk>, Zach Brown <zab@zabbo.net>,
Christoph Hellwig <hch@infradead.org>,
Maxim Patlasov <mpatlasov@parallels.com>,
Andrew Morton <akpm@linux-foundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Tejun Heo <tj@kernel.org>, Dave Chinner <david@fromorbit.com>,
Ming Lei <ming.lei@canonical.com>
Subject: [PATCH v4 1/5] fs: kiocb: introduce IOCB_DONT_DIRTY_PAGE flag for direct IO
Date: Fri, 29 May 2015 14:35:34 +0800 [thread overview]
Message-ID: <1432881338-898-2-git-send-email-ming.lei@canonical.com> (raw)
In-Reply-To: <1432881338-898-1-git-send-email-ming.lei@canonical.com>
When direct IO is submitted from kernel, it is often unnecessary
to dirty pages, for example of loop, dirtying pages have been
considered in the upper filesystem(over loop) side already, and
they don't need to be dirtied again.
So this patch introduces IOCB_DONT_DIRTY_PAGE flag for direct IO,
and other ITER_BVEC and ITER_KVEC cases might benefit from it too,
then it can be used for other dio cases which may have different
rules to deal with page dirtying.
The patch is based on previous Dave's patch.
Cc: Dave Kleikamp <dave.kleikamp@oracle.com>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
fs/direct-io.c | 9 ++++++---
include/linux/fs.h | 1 +
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 745d234..78964c0 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -120,6 +120,7 @@ struct dio {
int page_errors; /* errno from get_user_pages() */
int is_async; /* is IO async ? */
bool defer_completion; /* defer AIO completion to workqueue? */
+ bool should_dirty; /* if pages should be dirtied */
int io_error; /* IO error in completion path */
unsigned long refcount; /* direct_io_worker() and bios */
struct bio *bio_list; /* singly linked via bi_private */
@@ -393,7 +394,7 @@ static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio)
dio->refcount++;
spin_unlock_irqrestore(&dio->bio_lock, flags);
- if (dio->is_async && dio->rw == READ)
+ if (dio->is_async && dio->rw == READ && dio->should_dirty)
bio_set_pages_dirty(bio);
if (sdio->submit_io)
@@ -464,13 +465,14 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio)
if (!uptodate)
dio->io_error = -EIO;
- if (dio->is_async && dio->rw == READ) {
+ if (dio->is_async && dio->rw == READ && dio->should_dirty) {
bio_check_pages_dirty(bio); /* transfers ownership */
} else {
bio_for_each_segment_all(bvec, bio, i) {
struct page *page = bvec->bv_page;
- if (dio->rw == READ && !PageCompound(page))
+ if (dio->rw == READ && !PageCompound(page) &&
+ dio->should_dirty)
set_page_dirty_lock(page);
page_cache_release(page);
}
@@ -1217,6 +1219,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
spin_lock_init(&dio->bio_lock);
dio->refcount = 1;
+ dio->should_dirty = !(iocb->ki_flags & IOCB_DONT_DIRTY_PAGE);
sdio.iter = iter;
sdio.final_block_in_request =
(offset + iov_iter_count(iter)) >> blkbits;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ff4135e..54027ad 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -316,6 +316,7 @@ struct writeback_control;
#define IOCB_EVENTFD (1 << 0)
#define IOCB_APPEND (1 << 1)
#define IOCB_DIRECT (1 << 2)
+#define IOCB_DONT_DIRTY_PAGE (1 << 3)
struct kiocb {
struct file *ki_filp;
--
1.9.1
next prev parent reply other threads:[~2015-05-29 6:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-29 6:35 [PATCH v4 0/4] block: loop: improve loop with AIO Ming Lei
2015-05-29 6:35 ` Ming Lei [this message]
2015-06-05 15:03 ` [PATCH v4 1/5] fs: kiocb: introduce IOCB_DONT_DIRTY_PAGE flag for direct IO Christoph Hellwig
2015-06-06 0:42 ` Ming Lei
2015-06-09 6:29 ` Christoph Hellwig
2015-06-09 9:58 ` Ming Lei
2015-05-29 6:35 ` [PATCH v4 2/5] block: loop: set QUEUE_FLAG_NOMERGES for request queue of loop Ming Lei
2015-05-29 6:35 ` [PATCH v4 3/5] block: loop: use kthread_work Ming Lei
2015-05-29 6:35 ` [PATCH v4 4/5] block: loop: prepare for supporing direct IO Ming Lei
2015-05-29 6:35 ` [PATCH v4 5/5] block: loop: support DIO & AIO Ming Lei
2015-06-05 8:26 ` [PATCH v4 0/4] block: loop: improve loop with AIO Ming Lei
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=1432881338-898-2-git-send-email-ming.lei@canonical.com \
--to=ming.lei@canonical.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=dave.kleikamp@oracle.com \
--cc=david@fromorbit.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatlasov@parallels.com \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zab@zabbo.net \
/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®