From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fs/namei.c: micro-optimize acl_permission_check
Date: Wed, 13 Nov 2019 22:45:21 +0100 [thread overview]
Message-ID: <20191113214521.20931-1-linux@rasmusvillemoes.dk> (raw)
System-installed files are usually 0755 or 0644, so in most cases, we
can avoid the binary search and the cost of pulling the cred->groups
array and in_group_p() .text into the cpu cache.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
Ballpark numbers: For example, building a random package like
util-linux with "make -j8" causes about 300000 calls/s of
generic_permission, with root-owned files (binaries, shared libraries,
system headers, and walking the directories from / to those)
outnumbering the user-owned files about 10:1, so in that case one
avoids, say, 250000 calls/s of in_group_p(). Assuming that the net
saving is about 20 instructions, that's 5M insn/s, which is of course
too small to measure (it's in the .1% range), but might still be
enough to justify this.
fs/namei.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/namei.c b/fs/namei.c
index 671c3c1a3425..c78757435317 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -303,7 +303,12 @@ static int acl_permission_check(struct inode *inode, int mask)
return error;
}
- if (in_group_p(inode->i_gid))
+ /*
+ * If the "group" and "other" permissions are the same,
+ * there's no point calling in_group_p() to decide which
+ * set to use.
+ */
+ if ((((mode >> 3) ^ mode) & 7) && in_group_p(inode->i_gid))
mode >>= 3;
}
--
2.23.0
next reply other threads:[~2019-11-13 21:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-13 21:45 Rasmus Villemoes [this message]
2019-12-09 14:54 ` [PATCH] fs/namei.c: micro-optimize acl_permission_check Rasmus Villemoes
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=20191113214521.20931-1-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--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).