Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2391158ybc; Wed, 13 Nov 2019 13:47:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxgG9CUQ4UbJrsqGgmjGpw6iuS1etRkzOJwoBktM1X7PVMIXBdANSByG2BrczOl68awPDz6 X-Received: by 2002:aa7:cd52:: with SMTP id v18mr6185010edw.280.1573681642631; Wed, 13 Nov 2019 13:47:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573681642; cv=none; d=google.com; s=arc-20160816; b=V4Jfu8KiXaVeY8LCjuf+3NNJVvzrOyl8n49tBQJxxe1Y2UUX8EF/A9c8m/0tQP2xni CQpgdU0M8o6iLFXfwMAw8SvLp16B01IzPh1ZocFs/6EL2uuI3mKYm8e33AKWXwoH7AcF J3jgqqagv0EuB2V2bsFtKh5Q7PANVtZtdXsIA5GJakA1qRiBUkbz3QLeCNiLgyhkK5N6 QgWi3IA8q8FU8u1aH4ZKyfVcF7yfUg2HX6uzkucNfHpdDIaRPoBBk/s64XjtWAaM57/D l9/a5q8jieO/zXloq44w4QWdekl1L5VmsYPj0EwQN7WVU9uuM9MPeUZV1Ktn7kYvl9QY Zf3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=VCIGNym1KnSbrflz0aPgysV9g2CKRub3cea0GIpdFfg=; b=gQlkTVG1WQM3XsqgsO1O9P9fxGZDLzAk7ZP1x5KcFUrZsaruPr/dkqrFyDrfO+r3t+ Qw/ZG3mdsm0hFBneU2lbnoKMPC1+JnkjZEfW4sibm4gyj1Wv7Qu8SvRF8l5/9M9u2Bpo WemvBEqZhPc2RR3pm6go3aMph/vvS8CNwrx8FFlvA3DiD3R4i06OZ7BJgguReC0NoqeK VCZNWnJRjgVxvAjUoW9SjOfVWWKdE/UcTgEYYxxtlaQuxlEEk+T2iW2Vv8Yf1bBwGbE7 /rAXOt5F7KsLW8HD/SHpJGHlCUxJyn9hhbtiA8nlWPzNEiSbzIwtNdCxTTd8yqOFUM3z fsEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=fMdFyNK+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si2137435edy.41.2019.11.13.13.46.57; Wed, 13 Nov 2019 13:47:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=fMdFyNK+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbfKMVp2 (ORCPT + 99 others); Wed, 13 Nov 2019 16:45:28 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37305 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbfKMVp1 (ORCPT ); Wed, 13 Nov 2019 16:45:27 -0500 Received: by mail-wm1-f68.google.com with SMTP id b17so3687521wmj.2 for ; Wed, 13 Nov 2019 13:45:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VCIGNym1KnSbrflz0aPgysV9g2CKRub3cea0GIpdFfg=; b=fMdFyNK+SymwdAECuwGh5bgHiLHM52dlM8jOA7UMmkyThGbzpgqWdiZvnbYfi7Q5X/ j8rrzeyjUH4OHFGBfQVetXMSg4HnUM6L7SqEx7WB5Iq8rF/KmJ+WVTiCgnfWP0Sx2EOj omXRh2a572Q2dOE+jH/Z+H/Igd+HuEMtjmDQc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VCIGNym1KnSbrflz0aPgysV9g2CKRub3cea0GIpdFfg=; b=SSfcgHqzTtDqR9ipj0N5BNbCBpVRGTWTvqUakVK/15XrzBYUSOwHd5bvvOkXLCtaWI CkkwTDywHAYJDLyNW+of9nuvSQBYkqNeC78sm8ZrElFjUHr4eSsvKTwphF5T6dEWakN6 xiwOGPM0Wrz/6/OIyBJwivyrum+P1RRQbT8QJEh9YYTJMlAR+zZDEymbVzHDHkFWgLKi bW7RdutwbsRAuqwNwZuPB2h9hlVFtpsQAupbYKsAlc0KFT+5xy/1x0J5GPBHL0NH1d9+ xg/IMpIR1PlkwTT7bWaSQ+KMfM3+on98QEkVIqXRwkt3Kac9byMz7zec4hjWcOsHnD1p zERw== X-Gm-Message-State: APjAAAXloxS5+kfeXpocs6/N5tZ8H0/HS0iz4Vs4yXm8f4eKM7VITKKA 4DrT9nL0RiPMjYnb/G9VT6m8aQ== X-Received: by 2002:a1c:41c2:: with SMTP id o185mr4419000wma.34.1573681524367; Wed, 13 Nov 2019 13:45:24 -0800 (PST) Received: from prevas-ravi.prevas.se (ip-5-186-115-54.cgn.fibianet.dk. [5.186.115.54]) by smtp.gmail.com with ESMTPSA id y78sm3997722wmd.32.2019.11.13.13.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 13:45:23 -0800 (PST) From: Rasmus Villemoes To: Alexander Viro Cc: Rasmus Villemoes , 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 Message-Id: <20191113214521.20931-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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