From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 008B4C77B73 for ; Wed, 31 May 2023 11:15:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235453AbjEaLPw (ORCPT ); Wed, 31 May 2023 07:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232240AbjEaLPu (ORCPT ); Wed, 31 May 2023 07:15:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5161107; Wed, 31 May 2023 04:15:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 50662639C2; Wed, 31 May 2023 11:15:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B355C433EF; Wed, 31 May 2023 11:15:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685531748; bh=5Z/ncIIcZ7JrClaUclZ6ZS2IJVWcebebdWD3/h3CjS4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I9qOuMTW4BKRHf8TO2UJhIzgvmVQk3fWdTT4gt7FrY1jEf+fGA0aCWbzGOrx5F9Vq GQc0PZ7A2sFlJMy+q9FH1xrWVPPqbiYUZrGSOJblwsjmCU+KtDotXNKH2udP8/mSq8 GchTRv5iUNFL551UfzLRXYP8ShbA/ZbiySlhqYFwzZShO6+CRdEeVM+YumIMt5aRMg bsnHYDcnXgQaV46kNEV3OXKGn51Pqzk9L8DaSJTqCjAX6Z7rNsFWZRJncqs+HNsyR7 eRVMzWqCoTpx/KaAdHOCvShbFGEYGMnR52wnIZFiGUWBSofLzNRfn+ebJxNci3ZE/n E/TuKQ9mpeD6w== Date: Wed, 31 May 2023 13:15:43 +0200 From: Christian Brauner To: Amir Goldstein Cc: chenzhiyin , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, nanhai.zou@intel.com Subject: Re: [PATCH] fs.h: Optimize file struct to prevent false sharing Message-ID: <20230531-symmetrie-absender-8e9af6834753@brauner> References: <20230530020626.186192-1-zhiyin.chen@intel.com> <20230530-wortbruch-extra-88399a74392e@brauner> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 30, 2023 at 01:02:06PM +0300, Amir Goldstein wrote: > On Tue, May 30, 2023 at 12:31 PM Christian Brauner wrote: > > > > On Mon, May 29, 2023 at 10:06:26PM -0400, chenzhiyin wrote: > > > 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 > > > --- > > > > Sounds interesting, but can we see the actual numbers, please? > > So struct file is marked with __randomize_layout which seems to make > > this whole reordering pointless or at least only useful if the > > structure randomization Kconfig is turned off. Is there any precedence > > to optimizing structures that are marked as randomizable? > > Good question! > > Also does the impressive improvement is gained only with (A)+(B)+(C)? > > (A) and (B) make sense, but something about the claim (C) does not sit right. > Can you explain this claim? > > Putting the read mostly f_mode with frequently updated f_count seems > counter to the goal of your patch. > Aren't f_mode and f_flags just as frequently accessed as f_op? > Shouldn't f_mode belong with the read-mostly members? > > What am I missing? I think that f_mode will be more heavily used because it's checked everytime you call fget variants. For example, f_mode is used to check whether the file you're about to get a reference to is an O_PATH file and, depending on the fget variant that the caller used, denies or allows the caller to get a reference on that file depending on whether FMODE_PATH is or isn't set. So you have if (unlikely(file->f_mode & mask)) if (unlikely(!get_file_rcu(file))) // this is just try to bump f_count everytime you call an fget variant which should be substantial. Other places are fdget_pos() where f_mode is also checked right after an fdget()...