Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4227453rwd; Tue, 30 May 2023 02:13:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CCCQhfyATIm40TSRlsPX4DLHVcgAqK/4USmePM5GaaHFzTdXLgCHMRElE1pAEmN7qFnMK X-Received: by 2002:a17:90a:17ce:b0:256:d262:e686 with SMTP id q72-20020a17090a17ce00b00256d262e686mr342910pja.19.1685438029967; Tue, 30 May 2023 02:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685438029; cv=none; d=google.com; s=arc-20160816; b=Ees4ARuW1XC1HvC/aX5LNXRv8vJWL4oDuX7FN7GHT3Pp+pdziVWqqYlT55mB9pohAL Cxu38CiEzuk0hJvuS4JVR/GINk8JkHrEGl0fNeKyJK0Qj2Hm/rw7sDYk4lo2TvmXxOSt ffrhoT46l1lbS8TMw3Ptf8gs3sFfurCXHbL7F5psdkDrzVIdJQxsCYFqph2EQf/rsaPt Kst8OKracm2uHxfNAyiGgYmJJPyd/OWdWCueaUzX6AjCtVl51QGHrkNumG3930bcMEBs zl+2gsiFyBE/1LeD9WKbPMUVuVvkoWC5e8yvGoa53pBId5LoRNbmCzOKoXolBuEpWdbh M/ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/B8rJgb/TTTwBH5ViPm9d8ysn0N8DMcpjqydqGZQO/s=; b=iRtDwL3BLMN6B2hsjExvUo2/a2MtjWKwGcm4XneRyFcYrFK7PhTeqlbgrIMTeu6p4T asgSTMYQcWg5pZ7TUBsetXoe2+bcSuYCk2u4KCCMddw0EZ+myZah6TU/9kJBiZiw1UoG uBTiZiTenHtesZpaOZv9rLX1n7+OHbU1IVXA07UiSR1DfiT53LCs/nBcwSe3vm+t/wqM ugySL0YVhzT/zdilVsAGHWmt597M/iYPJ9qfRMFq4O4nxEVm4xGUFXLNK/5AlgmBrLog NxoV9jAdh/oEz9nTKcO5voXzWHnxHPwGDtVGd+bSFc282XK9H9GIl1Jq4Tq22MDt21P/ aqSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bp5Er4TA; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id on1-20020a17090b1d0100b0025378fb1538si1743169pjb.41.2023.05.30.02.13.35; Tue, 30 May 2023 02:13:49 -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=@kernel.org header.s=k20201202 header.b=bp5Er4TA; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbjE3Iux (ORCPT + 99 others); Tue, 30 May 2023 04:50:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbjE3Iuu (ORCPT ); Tue, 30 May 2023 04:50:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CE4BE; Tue, 30 May 2023 01:50:47 -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 59D1361870; Tue, 30 May 2023 08:50:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51547C433D2; Tue, 30 May 2023 08:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685436646; bh=YNggnKnwtaASUyaCFQCb+6vH6GXHzQlXJx39u2e9+yU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bp5Er4TA2QcOqQM4Pks2ChB9sv7gZpRdkNWWOhraRqR6rltwt1yipf0jByrnhjiAn vKUw/MsZ5+Ih71F1jdJUeGmoEf6rKzaj8yVSCJ1s7uqE5k22uvCnlOzPN2NhSzmxyc k7N7SQZm9g42BHB5fefjCe/dz8T4VIL3ukRrqJaKuFb1sPDLEn3PbjS87SSxBUwy14 0STtnyWAKoIwWoZSeidcMaDYtnxW4bFR7KilvympvJ2GPiVIc5+d7ogQ+MyO2wSrFq qXssmt4DKIYOqx3RBifCrQtlWRdIpNLmqQAk7yKS3tuZ5RgH6GNlmkMH7PeVrm+Ka8 5l25PlXDbrm9A== Date: Tue, 30 May 2023 10:50:42 +0200 From: Christian Brauner To: chenzhiyin Cc: 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: <20230530-wortbruch-extra-88399a74392e@brauner> References: <20230530020626.186192-1-zhiyin.chen@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230530020626.186192-1-zhiyin.chen@intel.com> X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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?