Skip to content

Commit 0a9164c

Browse files
krisman-at-collaborajankara
authored andcommitted
direct-io: don't force writeback for reads beyond EOF
If a DIO read starts past EOF, the kernel won't attempt it, so we don't need to flush dirty pages before failing the syscall. Link: https://lore.kernel.org/r/[email protected] Suggested-by: Jan Kara <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 46d7160 commit 0a9164c

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

fs/direct-io.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,19 +1188,9 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
11881188
memset(dio, 0, offsetof(struct dio, pages));
11891189

11901190
dio->flags = flags;
1191-
if (dio->flags & DIO_LOCKING) {
1192-
if (iov_iter_rw(iter) == READ) {
1193-
struct address_space *mapping =
1194-
iocb->ki_filp->f_mapping;
1195-
1196-
/* will be released by direct_io_worker */
1197-
inode_lock(inode);
1198-
1199-
retval = filemap_write_and_wait_range(mapping, offset,
1200-
end - 1);
1201-
if (retval)
1202-
goto fail_dio;
1203-
}
1191+
if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) {
1192+
/* will be released by direct_io_worker */
1193+
inode_lock(inode);
12041194
}
12051195

12061196
/* Once we sampled i_size check for reads beyond EOF */
@@ -1210,6 +1200,14 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
12101200
goto fail_dio;
12111201
}
12121202

1203+
if (dio->flags & DIO_LOCKING && iov_iter_rw(iter) == READ) {
1204+
struct address_space *mapping = iocb->ki_filp->f_mapping;
1205+
1206+
retval = filemap_write_and_wait_range(mapping, offset, end - 1);
1207+
if (retval)
1208+
goto fail_dio;
1209+
}
1210+
12131211
/*
12141212
* For file extending writes updating i_size before data writeouts
12151213
* complete can expose uninitialized blocks in dumb filesystems.

0 commit comments

Comments
 (0)