aboutsummaryrefslogtreecommitdiffstats
path: root/fs/direct-io.c
diff options
context:
space:
mode:
authorMing Lei <ming.lei@canonical.com>2015-08-16 22:31:46 -0400
committerJens Axboe <axboe@fb.com>2015-09-23 13:00:57 -0400
commit53cbf3b157a0428d40989ab1c7df9228a1976fc2 (patch)
tree70f1e0c29c0e8d07b1d0e7d03ce8d09a95c9cb1d /fs/direct-io.c
parent5948edbcbf43759586cdf2656d293ea7de310280 (diff)
fs: direct-io: don't dirtying pages for ITER_BVEC/ITER_KVEC direct read
When direct read 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 doesn't dirtying pages for ITER_BVEC/ITER_KVEC direct read, and loop should be the 1st case to use ITER_BVEC/ITER_KVEC for direct read I/O. The patch is based on previous Dave's patch. Reviewed-by: Dave Kleikamp <dave.kleikamp@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lei <ming.lei@canonical.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'fs/direct-io.c')
-rw-r--r--fs/direct-io.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 11256291642e..3ae0e0427191 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -120,6 +120,7 @@ struct dio {
120 int page_errors; /* errno from get_user_pages() */ 120 int page_errors; /* errno from get_user_pages() */
121 int is_async; /* is IO async ? */ 121 int is_async; /* is IO async ? */
122 bool defer_completion; /* defer AIO completion to workqueue? */ 122 bool defer_completion; /* defer AIO completion to workqueue? */
123 bool should_dirty; /* if pages should be dirtied */
123 int io_error; /* IO error in completion path */ 124 int io_error; /* IO error in completion path */
124 unsigned long refcount; /* direct_io_worker() and bios */ 125 unsigned long refcount; /* direct_io_worker() and bios */
125 struct bio *bio_list; /* singly linked via bi_private */ 126 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)
393 dio->refcount++; 394 dio->refcount++;
394 spin_unlock_irqrestore(&dio->bio_lock, flags); 395 spin_unlock_irqrestore(&dio->bio_lock, flags);
395 396
396 if (dio->is_async && dio->rw == READ) 397 if (dio->is_async && dio->rw == READ && dio->should_dirty)
397 bio_set_pages_dirty(bio); 398 bio_set_pages_dirty(bio);
398 399
399 if (sdio->submit_io) 400 if (sdio->submit_io)
@@ -464,14 +465,15 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio)
464 if (bio->bi_error) 465 if (bio->bi_error)
465 dio->io_error = -EIO; 466 dio->io_error = -EIO;
466 467
467 if (dio->is_async && dio->rw == READ) { 468 if (dio->is_async && dio->rw == READ && dio->should_dirty) {
468 bio_check_pages_dirty(bio); /* transfers ownership */ 469 bio_check_pages_dirty(bio); /* transfers ownership */
469 err = bio->bi_error; 470 err = bio->bi_error;
470 } else { 471 } else {
471 bio_for_each_segment_all(bvec, bio, i) { 472 bio_for_each_segment_all(bvec, bio, i) {
472 struct page *page = bvec->bv_page; 473 struct page *page = bvec->bv_page;
473 474
474 if (dio->rw == READ && !PageCompound(page)) 475 if (dio->rw == READ && !PageCompound(page) &&
476 dio->should_dirty)
475 set_page_dirty_lock(page); 477 set_page_dirty_lock(page);
476 page_cache_release(page); 478 page_cache_release(page);
477 } 479 }
@@ -1219,6 +1221,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
1219 spin_lock_init(&dio->bio_lock); 1221 spin_lock_init(&dio->bio_lock);
1220 dio->refcount = 1; 1222 dio->refcount = 1;
1221 1223
1224 dio->should_dirty = (iter->type == ITER_IOVEC);
1222 sdio.iter = iter; 1225 sdio.iter = iter;
1223 sdio.final_block_in_request = 1226 sdio.final_block_in_request =
1224 (offset + iov_iter_count(iter)) >> blkbits; 1227 (offset + iov_iter_count(iter)) >> blkbits;