Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4021008pxk; Tue, 8 Sep 2020 08:41:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCmk+Zjya/oHjgom7+wNbkSkgSGA7vwy7mPtEZIpHpz84rOKbzAC7HLpiX2fzgrKZY+SUr X-Received: by 2002:a17:906:e24f:: with SMTP id gq15mr27024780ejb.395.1599579708547; Tue, 08 Sep 2020 08:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599579708; cv=none; d=google.com; s=arc-20160816; b=M0OfkIELV5r9gwgV3iK1bmneuqjvDeDn5u5oXhtk9/6riYe/pj5svCCWq8QDwDDkKW RD5ii83IqAIEknwUr3wsJhb1pkf8l699hBQxwYEwWcKxvHwVG95bEqI3an4H3e49qsQE 05LZPl3kz/w5pnXZHbZnOQ/RsdYBv3nTxGE2gOt2ei7Q5wQAC8XaqJ5kFtgJV6q739hY U6C/88kARThfZg999Ac/DGBgBiNlVojvbbJp2G6qscSLdOcDV0L5gIgRr3fVauTs7xD8 XZHjR3+ZSjmDtD4ERh6ggcbOb7AwWjqAhia4uqP6bWIhUDtM8xJCTnAO2RuaAu5o+Apb S8PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mKNdo7smjE/Y6C2Rd2FnO+RlOVkHoy5Uefbwpc0iH+g=; b=cUY4A4R60n5zRsW+4sQStnmfyA0h4V0m5NysLDYr7G7VajhEm+H2s5lcWS7XTZYig5 Am5mel6VBSQmjyj0wYoNxUGiWFqojZXUYy31pXLVI7LvXXm9AGlXx3lyJ7itauT5S47x R0qhUJ6Tz32XI6m4RLjagML7XdnWBgxjJr5TKef9tWgKhUK4evYgeRun7Guy5mOt/h4Y lI6vz1PWerR2BUi34YFSIKdMFZvgrwNSOvejb8XQaD8i+mbfaD5kOs8gPbDJvPFAawXN qVZty9Lu21d2klqGWqeCMlzjgnDw9uu3SvIF2e3DEVruVpKC0SRNYTkWLi13wdNHC7/t /jyA== ARC-Authentication-Results: i=1; mx.google.com; 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 c3si12669925edl.567.2020.09.08.08.41.25; Tue, 08 Sep 2020 08:41:48 -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; 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 S1730501AbgIHPff (ORCPT + 99 others); Tue, 8 Sep 2020 11:35:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:33484 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730393AbgIHPYC (ORCPT ); Tue, 8 Sep 2020 11:24:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9FC06AD1E; Tue, 8 Sep 2020 11:37:46 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 1018B1E1325; Tue, 8 Sep 2020 13:37:45 +0200 (CEST) Date: Tue, 8 Sep 2020 13:37:45 +0200 From: Jan Kara To: Shaokun Zhang Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , Peter Zijlstra , Alexander Viro , Boqun Feng , Yuqi Jin Subject: Re: [PATCH RESEND] fs: Move @f_count to different cacheline with @f_mode Message-ID: <20200908113745.GA4070@quack2.suse.cz> References: <1592987548-8653-1-git-send-email-zhangshaokun@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1592987548-8653-1-git-send-email-zhangshaokun@hisilicon.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 24-06-20 16:32:28, Shaokun Zhang wrote: > get_file_rcu_many, which is called by __fget_files, has used > atomic_try_cmpxchg now and it can reduce the access number of the global > variable to improve the performance of atomic instruction compared with > atomic_cmpxchg. > > __fget_files does check the @f_mode with mask variable and will do some > atomic operations on @f_count, but both are on the same cacheline. > Many CPU cores do file access and it will cause much conflicts on @f_count. > If we could make the two members into different cachelines, it shall relax > the siutations. Thanks for the patch! The wins for your microbenchmark heavily sharing struct file are nice but I'm not sure your change is a universal win. When struct file is not shared (which is far more common), hot code paths like __fget() or __fget_light() will now need to fetch two cache lines from struct file instead of one. So I don't think that for most users the tradeoff is really worth it... Honza > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 3f881a892ea7..0faeab5622fb 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -955,7 +955,6 @@ struct file { > */ > spinlock_t f_lock; > enum rw_hint f_write_hint; > - atomic_long_t f_count; > unsigned int f_flags; > fmode_t f_mode; > struct mutex f_pos_lock; > @@ -979,6 +978,7 @@ struct file { > struct address_space *f_mapping; > errseq_t f_wb_err; > errseq_t f_sb_err; /* for syncfs */ > + atomic_long_t f_count; > } __randomize_layout > __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */ > > -- > 2.7.4 > -- Jan Kara SUSE Labs, CR