Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61d0017

Browse files
axboetorvalds
authored andcommitted
mm: don't read i_size of inode unless we need it
We always go through i_size_read(), and we rarely end up needing it. Push the read to down where we need to check it, which avoids it for most cases. It looks like we can even remove this check entirely, which might be worth pursuing. But at least this takes it out of the hot path. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Acked-by: Chris Mason <[email protected]> Cc: Josef Bacik <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Pavel Begunkov <[email protected]> Cc: Jan Kara <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent efee171 commit 61d0017

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

mm/filemap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,9 +2740,7 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
27402740
struct file *file = iocb->ki_filp;
27412741
struct address_space *mapping = file->f_mapping;
27422742
struct inode *inode = mapping->host;
2743-
loff_t size;
27442743

2745-
size = i_size_read(inode);
27462744
if (iocb->ki_flags & IOCB_NOWAIT) {
27472745
if (filemap_range_needs_writeback(mapping, iocb->ki_pos,
27482746
iocb->ki_pos + count - 1))
@@ -2774,8 +2772,9 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
27742772
* the rest of the read. Buffered reads will not work for
27752773
* DAX files, so don't bother trying.
27762774
*/
2777-
if (retval < 0 || !count || iocb->ki_pos >= size ||
2778-
IS_DAX(inode))
2775+
if (retval < 0 || !count || IS_DAX(inode))
2776+
return retval;
2777+
if (iocb->ki_pos >= i_size_read(inode))
27792778
return retval;
27802779
}
27812780

0 commit comments

Comments
 (0)