linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fs: optimise generic_write_check_limits()
Date: Fri,  6 Aug 2021 12:22:10 +0100	[thread overview]
Message-ID: <dc92d8ac746eaa95e5c22ca5e366b824c210a3f4.1628248828.git.asml.silence@gmail.com> (raw)

Even though ->s_maxbytes is used by generic_write_check_limits() only in
case of O_LARGEFILE, the value is loaded unconditionally, which is heavy
and takes 4 indirect loads. Optimise it by not touching ->s_maxbytes,
if it's not going to be used.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/read_write.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 9db7adf160d2..db662d0c3cfa 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1609,9 +1609,8 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,
  */
 int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count)
 {
-	struct inode *inode = file->f_mapping->host;
-	loff_t max_size = inode->i_sb->s_maxbytes;
 	loff_t limit = rlimit(RLIMIT_FSIZE);
+	loff_t max_size = MAX_NON_LFS;
 
 	if (limit != RLIM_INFINITY) {
 		if (pos >= limit) {
@@ -1621,8 +1620,11 @@ int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count)
 		*count = min(*count, limit - pos);
 	}
 
-	if (!(file->f_flags & O_LARGEFILE))
-		max_size = MAX_NON_LFS;
+	if (file->f_flags & O_LARGEFILE) {
+		struct inode *inode = file->f_mapping->host;
+
+		max_size = inode->i_sb->s_maxbytes;
+	}
 
 	if (unlikely(pos >= max_size))
 		return -EFBIG;
-- 
2.32.0


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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 11:22 Pavel Begunkov [this message]
2021-08-06 13:28 ` [PATCH] fs: optimise generic_write_check_limits() Matthew Wilcox
2021-08-07 10:05   ` Pavel Begunkov
2021-08-08 14:41   ` David Laight
2021-08-08 15:34     ` Matthew Wilcox
2021-08-06 13:46 ` Al Viro

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=dc92d8ac746eaa95e5c22ca5e366b824c210a3f4.1628248828.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).