Skip to contentSkip to conversation

fs/namei.c: micro-optimize acl_permission_check

PATCH Superseded Rasmus Villemoes 1 participant 2 messages Nov 13, 2019 – Dec 9, 2019 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/namei.c: micro-optimize acl_permission_check

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.

---
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(-)
fs/namei.c +6 -1
index 671c3c1a3425..c78757435317 100644
@@ -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;
 	}
 
Signature · 1 line
2.23.0
#1 lore raw

ping

Quoted 3 lines · Rasmus Villemoes

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.