Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2175280ybg; Fri, 5 Jun 2020 07:26:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfTjyORcv2NhIF37363SplUMCujV1QBdkcgFtwJtOwrikEJR9O1HS1Cg75uTNU2KPCDJrN X-Received: by 2002:a50:9d46:: with SMTP id j6mr9769623edk.362.1591367211292; Fri, 05 Jun 2020 07:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591367211; cv=none; d=google.com; s=arc-20160816; b=E3QevgrEQwi0ZqeYsvqOF8WnfRMHi2fUuhpcL4LiA3fZ1ny0boWyZIpkTkG8sAgBgw HogJg70b6HZToYcmnnod2TtLgWAB+v7KBdIUP5aa+TKT+UDDIcUUHmVFCWs6c3wQJm7E IVl61gHhOFmnwYyuUhSL5Bfa/0Z14nArpLLfVfIKqT3Pt/jcHoO/cbI77fyVhrpCl0BU oDvbMvXHsEbdKMCssS0ppcCjIdZcivlikDBhTj4S1yLThvaLSVcubujFsZ0xxjgWl5T8 88Jd3OuUPm66DUtq6msH+q91C5F3Rr3XLXc9UVqfws9yXHHYyfWqBC63jMZQnDA2jsZR wuUw== 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=XgY4I2DT6NHuEBJVBWH5xaWHKtAb7Acjuq8xM3DNBZs=; b=K5OwZi5uamCiVohfcb6XPm2PWO0nrtbWdq0cjP94Z6OL6dTd/ipBWWNEa7e1PzKgOO 2+sEn/FKnAHAlUWP2qYl5iVNqkhFVm4vFJuOC1FoOmD//nTbuwWzoIzIRruuFvVc9Oxn 7Cf5Tr+Zjkwsdb7sj6oPjUMnD252rpXp9lY3Ev1Z2rePaA9QCXSaVgmpyEBAUcxQLeuX rbC/6IAEAFD3d29JMfkOx4YgBgBd12J6HixYjPBvRz4FfMGloaRbmhPnU6zxvgDpyvF+ x8G5ARy+jNK+B/znD6Jr6UoB88qeFKmlIE6FujNVTSSs6ehWXvJgN0YDbdXyV8P84pSk 2KPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=QTElvvtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e12si4056483edc.122.2020.06.05.07.26.28; Fri, 05 Jun 2020 07:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=QTElvvtJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728307AbgFEOXn (ORCPT + 99 others); Fri, 5 Jun 2020 10:23:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728387AbgFEOXd (ORCPT ); Fri, 5 Jun 2020 10:23:33 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F318C08C5C4 for ; Fri, 5 Jun 2020 07:23:32 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id n24so10330985ejd.0 for ; Fri, 05 Jun 2020 07:23:32 -0700 (PDT) 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=XgY4I2DT6NHuEBJVBWH5xaWHKtAb7Acjuq8xM3DNBZs=; b=QTElvvtJbPz7O4l0N2vXVv9mj1TLExtC0raNDMa24L8UfKR1yYUuYHL9CxjaruDrjh aefJM28+QoU0J+hH7LcJY9hLj2TeIZpO1d1afTdHbgITtKVt276YnRSIFQtqPC3dyyfI ovRyDY8g9W4NZLaLUUq/4fqdIhDWT8EwOvTWA= 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=XgY4I2DT6NHuEBJVBWH5xaWHKtAb7Acjuq8xM3DNBZs=; b=m7TSc3xTwUNsJQs3vy2oMRaeLmotV1ZeIdkWDdk5JKu73xGm+8+E85+drjbIAS/PB1 57wKa6UPhK9ut66RiDtAoUZEqe8/bV9H1PA+cd8wLaRvtbkJwiXGy1LCjCNBkGkQwOih +HUEFPE1HjOqjE9bGy9p1590OnHXYcFdO7bdTZHz7g4diWsket9W/drugkFDTDoHz29h 6CJTjFCdSthzX/CLKjTROojXSjhifvDOrx66jOpVQmLMmAr8pvjgmL4IHTFbe3BxLJdf PG3vle+B5m8Vg70txjJCMBIsMqM6nFLtKcvpX+cIXsmcj2Azr0KxwX7C052ErZ3cB8Be pGCw== X-Gm-Message-State: AOAM531ci+LhelwJgyrb+VH/d3OcKALbRLnpKfyERX8yki0WZFET6kF7 0iT+nb6R1sIeEN7s395RhpGHKQ== X-Received: by 2002:a17:906:cb97:: with SMTP id mf23mr4356134ejb.468.1591367011198; Fri, 05 Jun 2020 07:23:31 -0700 (PDT) Received: from prevas-ravi.prevas.se (ip-5-186-116-45.cgn.fibianet.dk. [5.186.116.45]) by smtp.gmail.com with ESMTPSA id qp16sm4421833ejb.64.2020.06.05.07.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 07:23:30 -0700 (PDT) From: Rasmus Villemoes To: Alexander Viro Cc: Linus Torvalds , Rasmus Villemoes , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH resend] fs/namei.c: micro-optimize acl_permission_check Date: Fri, 5 Jun 2020 16:23:00 +0200 Message-Id: <20200605142300.14591-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 Just something like open(/usr/include/sys/stat.h) causes five calls of generic_permission -> acl_permission_check -> in_group_p; if the compiler first tried /usr/local/include/..., that would be a few more. Altogether, on a bog-standard Ubuntu 20.04 install, a workload consisting of compiling lots of userspace programs (i.e., calling lots of short-lived programs that all need to get their shared libs mapped in, and the compilers poking around looking for system headers - lots of /usr/lib, /usr/bin, /usr/include/ accesses) puts in_group_p around 0.1% according to perf top. With an artificial load such as while true ; do find /usr/ -print0 | xargs -0 stat > /dev/null ; done that jumps to over 0.4%. System-installed files are almost always 0755 (directories and binaries) 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 --- fs/namei.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/namei.c b/fs/namei.c index d81f73ff1a8b..c6f0c6643db5 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