Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3898759rwd; Mon, 29 May 2023 19:34:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tIGS1qIeh9HopEkOOuCFdA6HciMN9yxjngHH4YesPY5n5GLWyk3cGlxqzj8CpF/HXTU8D X-Received: by 2002:a05:6a00:9a5:b0:627:e49a:871a with SMTP id u37-20020a056a0009a500b00627e49a871amr980344pfg.23.1685414095320; Mon, 29 May 2023 19:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685414095; cv=none; d=google.com; s=arc-20160816; b=yopPUzeDgoAekts71cdjdXbm3dnumY/bZPx4P+LQMexyT0EBZLgOb1VsU5Ef4x/wE5 qfReTOPmn7Y10W7NtuHCInnAs0TlOPJRIgaxEZkWEcpAL+hoDK1dYrzEju6kBzIyt9mN qcdNjWZ0negSttb1aLHtYMT0GN2M289VKsQN4D3y5dhewauu3v9fxrrGQN93qfrhQL0j T5VwffvE4FkgHk348+3uHaVIF+E9ql4L3iAi1rlKYESdjMxDJykTHngT2JpC6peMQx/6 TtcAGxNGCnr+VNOaAmPTB5bGqk9QEd8L0/uEySFT0+OURs0u70DSpwPaddfOg5HvB/w9 ED8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=6KX5b0V344rc2NhlzqEtxTqSc141ihWOx/JPvkH2JGk=; b=DbnPxkjjKD8E9qJeqsz3IyzB8omP93K+Dy6ayvI/2LcP10YE3FWeayV3CMowmeM0HS 5epv6I6HxDwYbCyDMHKEFWM9EDpvNwcH9Fx8uzy3Uj3p7NeOZNLsKJmyAlpwMJ+JlplY yxJUwxPA9spXtZK+0GWJycz2PhPsh8Ywmz5/QT8/CnIA1SUWvZDsb3zV6wjZwpFzvvru phF11w1j6wiMOTWudoTuTW6tmA92AErFaRVbKsZNJVehfuMmhYVxQ6SH0rfht8IQehsn GbCCRppWoRVBZQUeJam1aUsqlQy7SQEfg/nuPLcxJDb3chdfyeKuzBOsXhWlyugLsCwS GSSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RvI0vc8n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t14-20020aa7946e000000b006455d53001fsi893327pfq.40.2023.05.29.19.34.43; Mon, 29 May 2023 19:34:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RvI0vc8n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbjE3CIX (ORCPT + 99 others); Mon, 29 May 2023 22:08:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbjE3CIQ (ORCPT ); Mon, 29 May 2023 22:08:16 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0574E5; Mon, 29 May 2023 19:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685412486; x=1716948486; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=reNeQez1F7r8ZGoYnYWNc9HF8+Nb54iuzqiK4gjVInk=; b=RvI0vc8nvPDXh9OLIdtAIF7/GgaoafLv076/HcdN4WE/vzhr6dz1oA3m PhDlBq35suDKVciCo75k6z7s+c/+UaKtluCJIEORY1e96+tkWN9AW5e4A C2VD8SwJ3Zn+pmM/gWBMhvYfVS0BE29hO4WwgIia5chBqRlENtWeVUj+E fg1bocAL2cVIDs/GTin1saCL9sPw3E+rb6ycPBSZM01sAmH9IKViLE+at FmhJqxKHTFfR+JuWFwgNhRUkjhC6a5kG5A0zasbHRMm5ELMHaiwAcvJ96 IDIzNF1PzytQvEd86UrQ+yCZXhr3Aa/qxr7haxWXFVUWIxSVb32ePMhnM Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="354812291" X-IronPort-AV: E=Sophos;i="6.00,201,1681196400"; d="scan'208";a="354812291" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2023 19:06:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="952923391" X-IronPort-AV: E=Sophos;i="6.00,201,1681196400"; d="scan'208";a="952923391" Received: from crt-e302.sh.intel.com (HELO localhost.localdomain) ([10.239.45.181]) by fmsmga006.fm.intel.com with ESMTP; 29 May 2023 19:06:53 -0700 From: chenzhiyin To: viro@zeniv.linux.org.uk, brauner@kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, nanhai.zou@intel.com, zhiyin.chen@intel.com Subject: [PATCH] fs.h: Optimize file struct to prevent false sharing Date: Mon, 29 May 2023 22:06:26 -0400 Message-Id: <20230530020626.186192-1-zhiyin.chen@intel.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the syscall test of UnixBench, performance regression occurred due to false sharing. The lock and atomic members, including file::f_lock, file::f_count and file::f_pos_lock are highly contended and frequently updated in the high-concurrency test scenarios. perf c2c indentified one affected read access, file::f_op. To prevent false sharing, the layout of file struct is changed as following (A) f_lock, f_count and f_pos_lock are put together to share the same cache line. (B) The read mostly members, including f_path, f_inode, f_op are put into a separate cache line. (C) f_mode is put together with f_count, since they are used frequently at the same time. The optimization has been validated in the syscall test of UnixBench. performance gain is 30~50%, when the number of parallel jobs is 16. Signed-off-by: chenzhiyin --- include/linux/fs.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 21a981680856..01c55e3a1b96 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -962,23 +962,23 @@ struct file { struct rcu_head f_rcuhead; unsigned int f_iocb_flags; }; - struct path f_path; - struct inode *f_inode; /* cached value */ - const struct file_operations *f_op; /* * Protects f_ep, f_flags. * Must not be taken from IRQ context. */ spinlock_t f_lock; - atomic_long_t f_count; - unsigned int f_flags; fmode_t f_mode; + atomic_long_t f_count; struct mutex f_pos_lock; + unsigned int f_flags; loff_t f_pos; struct fown_struct f_owner; const struct cred *f_cred; struct file_ra_state f_ra; + struct path f_path; + struct inode *f_inode; /* cached value */ + const struct file_operations *f_op; u64 f_version; #ifdef CONFIG_SECURITY -- 2.39.1