All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org
Subject: [RFC] mm: optimise generic_file_read_iter
Date: Fri,  6 Aug 2021 12:42:43 +0100	[thread overview]
Message-ID: <07bd408d6cad95166b776911823b40044160b434.1628248975.git.asml.silence@gmail.com> (raw)

Unless direct I/O path of generic_file_read_iter() ended up with an
error or a short read, it doesn't use inode. So, load inode and size
later, only when they're needed. This cuts two memory reads and also
imrpoves code generation, e.g. loads from stack.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---

NOTE: as a side effect, it reads inode->i_size after ->direct_IO(), and
I'm not sure whether that's valid, so would be great to get feedback
from someone who knows better.

 mm/filemap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index d1458ecf2f51..0030c454ec35 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2658,10 +2658,8 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 	if (iocb->ki_flags & IOCB_DIRECT) {
 		struct file *file = iocb->ki_filp;
 		struct address_space *mapping = file->f_mapping;
-		struct inode *inode = mapping->host;
-		loff_t size;
+		struct inode *inode;
 
-		size = i_size_read(inode);
 		if (iocb->ki_flags & IOCB_NOWAIT) {
 			if (filemap_range_needs_writeback(mapping, iocb->ki_pos,
 						iocb->ki_pos + count - 1))
@@ -2693,8 +2691,10 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 		 * the rest of the read.  Buffered reads will not work for
 		 * DAX files, so don't bother trying.
 		 */
-		if (retval < 0 || !count || iocb->ki_pos >= size ||
-		    IS_DAX(inode))
+		if (retval < 0 || !count)
+			return retval;
+		inode = mapping->host;
+		if (iocb->ki_pos >= i_size_read(inode) || IS_DAX(inode))
 			return retval;
 	}
 
-- 
2.32.0


             reply	other threads:[~2021-08-06 11:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 11:42 Pavel Begunkov [this message]
2021-08-06 13:48 ` [RFC] mm: optimise generic_file_read_iter Al Viro
2021-08-06 17:18   ` Jens Axboe
2021-08-07 10:30   ` Pavel Begunkov
2021-08-06 23:49 ` Dave Chinner

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=07bd408d6cad95166b776911823b40044160b434.1628248975.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.