Skip to content

Commit 53cbf3b

Browse files
Ming Leiaxboe
authored andcommitted
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5948edb commit 53cbf3b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fs/direct-io.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct dio {
120120
int page_errors; /* errno from get_user_pages() */
121121
int is_async; /* is IO async ? */
122122
bool defer_completion; /* defer AIO completion to workqueue? */
123+
bool should_dirty; /* if pages should be dirtied */
123124
int io_error; /* IO error in completion path */
124125
unsigned long refcount; /* direct_io_worker() and bios */
125126
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)
393394
dio->refcount++;
394395
spin_unlock_irqrestore(&dio->bio_lock, flags);
395396

396-
if (dio->is_async && dio->rw == READ)
397+
if (dio->is_async && dio->rw == READ && dio->should_dirty)
397398
bio_set_pages_dirty(bio);
398399

399400
if (sdio->submit_io)
@@ -464,14 +465,15 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio)
464465
if (bio->bi_error)
465466
dio->io_error = -EIO;
466467

467-
if (dio->is_async && dio->rw == READ) {
468+
if (dio->is_async && dio->rw == READ && dio->should_dirty) {
468469
bio_check_pages_dirty(bio); /* transfers ownership */
469470
err = bio->bi_error;
470471
} else {
471472
bio_for_each_segment_all(bvec, bio, i) {
472473
struct page *page = bvec->bv_page;
473474

474-
if (dio->rw == READ && !PageCompound(page))
475+
if (dio->rw == READ && !PageCompound(page) &&
476+
dio->should_dirty)
475477
set_page_dirty_lock(page);
476478
page_cache_release(page);
477479
}
@@ -1219,6 +1221,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
12191221
spin_lock_init(&dio->bio_lock);
12201222
dio->refcount = 1;
12211223

1224+
dio->should_dirty = (iter->type == ITER_IOVEC);
12221225
sdio.iter = iter;
12231226
sdio.final_block_in_request =
12241227
(offset + iov_iter_count(iter)) >> blkbits;

0 commit comments

Comments
 (0)