Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp677388rdb; Tue, 19 Sep 2023 07:12:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGf7d44GWJWCHsKlEytEfKj3V7bMbOEilN3nzwElppSF20wKsNJgsEYHmhDqj1wrEhoZK8C X-Received: by 2002:a17:902:efce:b0:1a9:b8c3:c2c2 with SMTP id ja14-20020a170902efce00b001a9b8c3c2c2mr11147282plb.37.1695132755317; Tue, 19 Sep 2023 07:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695132755; cv=none; d=google.com; s=arc-20160816; b=t4jy6wnLEERsEB6k2w5VuXS3LCAtUK6KgvueGaQEseGC9fNdAF2Fl22xw8btyy8Wqu atAQumQbwsNrfJIVY35NsKjrvi22G8d3z6VAA3Ybi9uNRmhCDOrDVF9Br+hCAHIrpCqc RMh+Wrdghc45Y+2lRGST+Jz0rMkBZPCfm0L82jHJ389budg0Hy2PgGfihbN0GHSEy8Iz Ie26wnKJj4Sj7ZIg5M0RFGhumwkyCdKRPrnki2aEiCD2eiTPEuhCUZMMM0Ni9M5XVuGC a6AcETdo8L2xY+fr/Zb06YSc4BuRXAlH3SXIpC70irM4xyq/UcNNYqLbht0NZbKjez57 JEkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:feedback-id:dkim-signature:dkim-signature; bh=35U7SZxly5E4C5II0R3QwFIGHLkcF+JoifaLm/DjmW8=; fh=ZgF0wNHA4d22MtcnaQdOGuWx5csPHy/WlsWyL8NmZa8=; b=vlAtryrlB4QxrGJMBoR2vm5eH9K/fJJfKei8548on9RGxy0zjbH3U/YDYDzAPK0MvN ga3HbPkAMdo8tIvTorfSHawaW3nkrc2I5iRAbSqXrJXjML2gHN1uJjNudOebgdvYsWa2 8mXM8KnE+vrO67dQaxiDK/JKgCJ4Zcz1DFI8O/MyC28cakvqYZ+0VU0ojVtiHpe64nwq yUUAJ+gVO/Yb8Znt/s+7OQ6+bnZaRjaiyBCiXhDEk2hpwlbajudnIKl/R87q8xTCmYXv OdPDqS6GXLscI+rS22UYo+i3YFFdyJ2+ydlSgKT/CPIlnaICW1IpgtO/TQPm0mLNRieE Cv/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fastmail.fm header.s=fm2 header.b=SZuY9XIY; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="hleu/2n2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fastmail.fm Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t12-20020a1709027fcc00b001b89bd6fd59si9616348plb.215.2023.09.19.07.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 07:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@fastmail.fm header.s=fm2 header.b=SZuY9XIY; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="hleu/2n2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fastmail.fm Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2C858802FA60; Tue, 19 Sep 2023 06:12:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231968AbjISNM0 (ORCPT + 99 others); Tue, 19 Sep 2023 09:12:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbjISNMZ (ORCPT ); Tue, 19 Sep 2023 09:12:25 -0400 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0574EF0; Tue, 19 Sep 2023 06:12:19 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 9C9C45C01BE; Tue, 19 Sep 2023 09:12:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 19 Sep 2023 09:12:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1695129136; x=1695215536; bh=35U7SZxly5E4C5II0R3QwFIGHLkcF+Joifa Lm/DjmW8=; b=SZuY9XIYk8UoYI0cncKefuLo+3a8kidBwLfYvWl/HMWy4sDKpey 5lybXHs4E+8uqsMuhnLl53Ms7goP5REEXf7GB3jlkqf8mWqkiDdhMnRELphtCf/E y8VCX4qmyfdn7jynjeh9/E9wZ6/wdiodDiguGzIWupbXsyQg38yPic+DD+VqFzcS bVOEQ8sY54KmuMJKnpl+QKGpYDXvA+vraZf42r9DlljLSav05OO/s9VOzDLsNyxQ wM4TWSwUx5d8CpIIUIlVnP577X9wcPhzGBhu+CYLKS+4BgUeGZDRC5J2WIOsvdOJ B4AWJd0MNH/CRZjR1FMptpEoi8j0x2yefxA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1695129136; x= 1695215536; bh=35U7SZxly5E4C5II0R3QwFIGHLkcF+JoifaLm/DjmW8=; b=h leu/2n2IqBV76jXcXUaryUgHgVvO2eQIsDZmcMckNMClWVc+rhh4Frle33aRBbkW 9dOrGPNkT0almLn2hpK3SJljCulNBKP1biwByfGoWT6sRpmiupocQfVLmF5YprFm yybIQaUimxhWJXfxy0nbIw3+6tgDzz8vhYZ20bb9ZPRD2+QoyrqXS9cNDHZF8Xi6 4GB0uIe3EppIoBnqWbM/dSNJO3dr4bCKvkIB0RURW+MU71HQXm1dJwl3NVVJsJty UnM3+Bo4FWfrIpENHxqFGLZ6CINqSWMhqltm/2YGCDwn889yn78eCbVSKZJbdCmu mZUojfE0by3yTgcQf20jA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekuddgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomhepuegvrhhn ugcuufgthhhusggvrhhtuceosggvrhhnugdrshgthhhusggvrhhtsehfrghsthhmrghilh drfhhmqeenucggtffrrghtthgvrhhnpefgleefffejffeugeeivedvleevffeihfeuleev leeutdefieeftddttdeghfelgeenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsggvrhhnugdr shgthhhusggvrhhtsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: id8a24192:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 19 Sep 2023 09:12:15 -0400 (EDT) Message-ID: <73e673d6-ecb8-dec9-bdc0-6dde9c4e76cb@fastmail.fm> Date: Tue, 19 Sep 2023 15:12:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] fuse: remove unneeded lock which protecting update of congestion_threshold Content-Language: en-US, de-DE To: Kemeng Shi , miklos@szeredi.hu, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230914154553.71939-1-shikemeng@huaweicloud.com> <9a5d4c82-1ab3-e96d-98bb-369acc8404d1@fastmail.fm> <177d891e-9258-68bb-72aa-4d4126403b7e@huaweicloud.com> From: Bernd Schubert In-Reply-To: <177d891e-9258-68bb-72aa-4d4126403b7e@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 06:12:26 -0700 (PDT) On 9/19/23 08:11, Kemeng Shi wrote: > > > on 9/16/2023 7:06 PM, Bernd Schubert wrote: >> >> >> On 9/14/23 17:45, Kemeng Shi wrote: >>> Commit 670d21c6e17f6 ("fuse: remove reliance on bdi congestion") change how >>> congestion_threshold is used and lock in >>> fuse_conn_congestion_threshold_write is not needed anymore. >>> 1. Access to supe_block is removed along with removing of bdi congestion. >>> Then down_read(&fc->killsb) which protecting access to super_block is no >>> needed. >>> 2. Compare num_background and congestion_threshold without holding >>> bg_lock. Then there is no need to hold bg_lock to update >>> congestion_threshold. >>> >>> Signed-off-by: Kemeng Shi >>> --- >>>   fs/fuse/control.c | 4 ---- >>>   1 file changed, 4 deletions(-) >>> >>> diff --git a/fs/fuse/control.c b/fs/fuse/control.c >>> index 247ef4f76761..c5d7bf80efed 100644 >>> --- a/fs/fuse/control.c >>> +++ b/fs/fuse/control.c >>> @@ -174,11 +174,7 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file, >>>       if (!fc) >>>           goto out; >>>   -    down_read(&fc->killsb); >>> -    spin_lock(&fc->bg_lock); >>>       fc->congestion_threshold = val; >>> -    spin_unlock(&fc->bg_lock); >>> -    up_read(&fc->killsb); >>>       fuse_conn_put(fc); >>>   out: >>>       return ret; >> >> Yeah, I don't see readers holding any of these locks. >> I just wonder if it wouldn't be better to use WRITE_ONCE to ensure a single atomic operation to store the value. > Sure, WRITE_ONCE looks better. I wonder if we should use READ_ONCE from reader. > Would like to get any advice. Thanks! I'm not entirely sure either, but I _think_ the compiler is free to store a 32 bit value with multiple operations (like 2 x 16 bit). In that case a competing reading thread might read garbage... Although I don't see this documented here https://www.kernel.org/doc/Documentation/memory-barriers.txt Though documented there is that the compile is free to optimize out the storage at all, see "(*) Similarly, the compiler is within its rights to omit a store entirely" Regarding READ_ONCE, I don't have a strong opinion, if the compiler makes some optimizations and the value would be wrong for a few cycles, would that matter for that variable? Unless the compiler would be really creative and the variable would get never updated... For sure READ_ONCE would be safer, but I don't know if it is needed SSee section "The compiler is within its rights to omit a load entirely if it know" in the document above. Thanks, Bernd