Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3136672rwb; Mon, 15 Aug 2022 19:04:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR7zoMcaIZl2uoA6c36D9419wOuqwI279vkHUSeDDh+wW5Rmt02votE7SCthY3inyX+pXN6R X-Received: by 2002:a17:90b:1894:b0:1f5:1041:a4ed with SMTP id mn20-20020a17090b189400b001f51041a4edmr21542051pjb.125.1660615440460; Mon, 15 Aug 2022 19:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660615440; cv=none; d=google.com; s=arc-20160816; b=PiTmaRR0A1r1kdEKvQi74MrLVfU9X9LbM2N6iCFof5tnYVR9+n86YCNCfEANFSzJ90 kCCDdCEnK3nIkwEry9UOUmtZrdCxOuftnVPT3IzXevL4oNvNcCXydNX+fs1IQ7HV8ThA EKKEOHwdYkqRPtFYRM6J9C6IL/rvdwwcIp31N/k/NGSPhS42ZDdwycJsvCUeiHK3El28 5ocriHiKo6wv9QTCUkccT4DrNAx+qlI/62xwq/4s9yO/aL+9fuf0tOq+AzWSr2zoArK/ XdXRH6QCdL/e3y3zC9aaoBh5tOh0+K2dw10jPJAJ6i6Eq9XXpSWKzvLnNZdVRQDCU8fD yeAQ== 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:feedback-id :dkim-signature:dkim-signature; bh=q1GHOVR2HG8hGzbylQv89Zpmm6U7IK8HwWlEMQHeE0Q=; b=XBaYMe/X4pS8fimh/K7/0kENZT8DarN+NuPho1OGT56I0JwOS2tuL3OUNBc+1wjker 7BCU8jrh/yknNFkyC6jXRS2RC45iQWbmtGf8sRDSQqtsviBQNPmRV41q6xrgi7BJWOyh KZkC+0sGIBTkRK8LwyGMkmY3IHtCMSwkQ4WALE+QZkEUWlsRxwNG60a5jUmclmDmZ37X /jxaLLuNBvyGIl4/sLLcY92/4cjYC7gHeKPKO6YUcakIDhWO8KNv+3hSx6GumHaNP2Uq yCvUH4L6TTRL+Kt3CdSaKe20pbIc0tDXmrjcaJh1wdtTtH/iyHgCryklc2KFjqw1SOrm yYFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bur.io header.s=fm1 header.b=p3DcQwx3; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="Vxg/pwxQ"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a056a0010c700b0052adad0f01esi12747100pfu.376.2022.08.15.19.03.49; Mon, 15 Aug 2022 19:04:00 -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=@bur.io header.s=fm1 header.b=p3DcQwx3; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="Vxg/pwxQ"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234642AbiHPBoE (ORCPT + 99 others); Mon, 15 Aug 2022 21:44:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233940AbiHPBnb (ORCPT ); Mon, 15 Aug 2022 21:43:31 -0400 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39F745FF63; Mon, 15 Aug 2022 14:35:04 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 2933C320090F; Mon, 15 Aug 2022 17:35:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 15 Aug 2022 17:35:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc:cc :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=fm1; t=1660599302; x=1660685702; bh=q1GHOVR2HG 8hGzbylQv89Zpmm6U7IK8HwWlEMQHeE0Q=; b=p3DcQwx3UhVFNJ4Ne5ggFH8HYU ATT7E9nfCS8FTf9zCUoIhljDt29iiTJWrtOK/Ab/CQvN7XGl7piu6A2EeQ9S8l7s colERk4NTdmTr9hj9AELhEw8ZBYpt58zkcKkafj5nH/SFcndpasyMgICCdu/4/JS KUNXKHMAUmP3wKXX0FHxUz7wPNMKCw591YgYwOXQT5TS3oJpn2Lze0pkBn401VLK x7ul9uVCoYdKajgrlyHmaijX1IDUCEHhA7dotI0NV3BT2uxlVxmx08mle76kmGON JMgl2tzeKi0LR9MLXE0v/VwrPa9WBFlTXPGsHtRiLsvNAE93BPeCmZjG94ew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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= fm1; t=1660599302; x=1660685702; bh=q1GHOVR2HG8hGzbylQv89Zpmm6U7 IK8HwWlEMQHeE0Q=; b=Vxg/pwxQbhtAkJ0Q2vd4ulSLVjnVhVTflw2nXiy58SeF acjKBnkJ5NTuQoSVt7cOzyknL7BdAIyo2R3Tz9dmJSUUDBNVPur2Zz5UTDrqMoxs xfG5x5ZbjdE3a3CrLlo8o+u3kUbmQPIC/U4RIvpvgVI/UahZMEDJgoYu1oWwDtd+ wpKH6OMydaDaSOd2CrvvU125bE8YgfCZGJWkxoM5oDdKotZiF0GC9dXDQF4gx3fK 3HeHTmmBF/cTvpbg6WxxPObLA3Su+iq+sN8J6udrbMp+ZfHHbScW/uGgOLuzBRe6 yXlCaKHZ0Wj0GCw6I2f6RyKMV33i7tZmsFgLFosMJg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdehfedgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehorhhi shcuuehurhhkohhvuceosghorhhishessghurhdrihhoqeenucggtffrrghtthgvrhhnpe ekvdekffejleelhfevhedvjeduhfejtdfhvdevieeiiedugfeugfdtjefgfeeljeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhsse gsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Aug 2022 17:35:02 -0400 (EDT) Date: Mon, 15 Aug 2022 14:36:25 -0700 From: Boris Burkov To: Uros Bizjak Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Mason , Josef Bacik , David Sterba Subject: Re: [PATCH] fs/btrfs: Use atomic_try_cmpxchg in free_extent_buffer Message-ID: References: <20220809163633.8255-1-ubizjak@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220809163633.8255-1-ubizjak@gmail.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 Tue, Aug 09, 2022 at 06:36:33PM +0200, Uros Bizjak wrote: > Use `atomic_try_cmpxchg(ptr, &old, new)` instead of > `atomic_cmpxchg(ptr, old, new) == old` in free_extent_buffer. This > has two benefits: > > - The x86 cmpxchg instruction returns success in the ZF flag, so this > change saves a compare after cmpxchg, as well as a related move > instruction in the front of cmpxchg. > > - atomic_try_cmpxchg implicitly assigns the *ptr value to &old when > cmpxchg fails, enabling further code simplifications. > > This patch has no functional change. > > Cc: Chris Mason > Cc: Josef Bacik > Cc: David Sterba > Signed-off-by: Uros Bizjak Reviewed-by: Boris Burkov > --- > fs/btrfs/extent_io.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index bfae67c593c5..15ff196cbd6d 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -6328,18 +6328,16 @@ static int release_extent_buffer(struct extent_buffer *eb) > void free_extent_buffer(struct extent_buffer *eb) > { > int refs; > - int old; > if (!eb) > return; > > + refs = atomic_read(&eb->refs); > while (1) { > - refs = atomic_read(&eb->refs); > if ((!test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) && refs <= 3) > || (test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) && > refs == 1)) > break; > - old = atomic_cmpxchg(&eb->refs, refs, refs - 1); > - if (old == refs) > + if (atomic_try_cmpxchg(&eb->refs, &refs, refs - 1)) > return; > } > > -- > 2.37.1 >