Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp78027rwb; Wed, 18 Jan 2023 14:25:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXtFSazvCx5BVbcJGMFgDUfD/AQtnbtE94xvzdfBJmz0TMsmeLyDi6JxpgDBnbNFxNCt3W54 X-Received: by 2002:a17:907:1710:b0:85d:dd20:60a4 with SMTP id le16-20020a170907171000b0085ddd2060a4mr8937897ejc.40.1674080705635; Wed, 18 Jan 2023 14:25:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674080705; cv=none; d=google.com; s=arc-20160816; b=NDEOTFqQWFkAFq13vlekVbnK5V6E4AyJXOVyxhJCb5d1K22eEV2rkZyfPzBBMsifl4 e5exudQY3IyspCZsdFj9F89XDJJJsoyqWgGMBLqVLD/0fa8+rT+ynJuUBsx81FYI4CSQ yFXMeTAgTAxTEKfAYNGZ+8pf72NkxhjrmTm6h2HPZaqLk2IDWQISJ2Q0KDMhLcGP9dRH /A5MDLPN6HgWsfPpFph6uv6PsYKtjuHauaNfxTffgB7ISoGamBKFAHwc0yGDpRtwCxCh 4DsXHbH5Lz14Mc75prdQ+0CxtrNJLsIigYl8rjrifcz3rv5pIxiF7wjpxI5t6Ar2uNFL D2dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=kOINPc9885W2fS4zcQZveSxc/U9CN93C5Tz8ZuyKDRA=; b=L0NYrBAmYiuIJI1SdusBiDyZDwPlblvPJ2sqlHECdt1Bpk6wgu96DmgIcob9kYu/+g H3cM8fahXrTlXjRGFGOeA7ZJKsCpBvyeoXUnKGVU8WHAdrR1piBKWLuIqgyvQyyUMeC+ qUGe5gn5xfyvCoIc7JbowZPc0akEp3/4uA2dd+Vk7/lbzVdRCVsf2lAB64H7+0Vvgx7p JII/fj/4xJuTsu2U1UOSckSHDtABkGBhIr8PiHpCzvtkOShFN/w8lWF2FL6zTrbEFYgA kPkQbHhGXA+BDEqGOQ3yszfO9TF+rlX39eZCHFcqHMuBpG/lNU41/SZyYZ9Ne8pP5WDU v23A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=DDOiIi8+; 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 ds6-20020a170907724600b0078cdba56108si39998482ejc.296.2023.01.18.14.24.54; Wed, 18 Jan 2023 14:25:05 -0800 (PST) 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=@linux-foundation.org header.s=korg header.b=DDOiIi8+; 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 S230288AbjARVSd (ORCPT + 45 others); Wed, 18 Jan 2023 16:18:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbjARVSa (ORCPT ); Wed, 18 Jan 2023 16:18:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 050052C65A for ; Wed, 18 Jan 2023 13:18:29 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id ABE3FB81F0E for ; Wed, 18 Jan 2023 21:18:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42EBBC433D2; Wed, 18 Jan 2023 21:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1674076706; bh=vHeTPswFT6UGjKqMulF60/zXR5ZS1Aukp1xmbcZxG9M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DDOiIi8+wJ2qaoD3NYtfyOjfMxSNIRA4oPekbbjCFnzlhyhYUdFoTOmd7IzVSOLPb FUJDeKwLOB0ypAqlh/Z2OeThvAwjOtf4+A5q4cEIAJDATa/9945i//BMBK8hSftmt8 anl1u+j8D1QJ5oifC5z0VevIp+gskhTlyPb9ZZ8M= Date: Wed, 18 Jan 2023 13:18:25 -0800 From: Andrew Morton To: Uros Bizjak Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] lib/genalloc: use try_cmpxchg in {set,clear}_bits_ll Message-Id: <20230118131825.c6daea81ea1e2dc6aa014f38@linux-foundation.org> In-Reply-To: <20230118150703.4024-1-ubizjak@gmail.com> References: <20230118150703.4024-1-ubizjak@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 On Wed, 18 Jan 2023 16:07:03 +0100 Uros Bizjak wrote: > Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in > {set,clear}_bits_ll. x86 CMPXCHG instruction returns success in ZF > flag, so this change saves a compare after cmpxchg (and related move > instruction in front of cmpxchg). > > Also, try_cmpxchg implicitly assigns old *ptr value to "old" > when cmpxchg fails. > > Note that the value from *ptr should be read using READ_ONCE to prevent > the compiler from merging, refetching or reordering the read. > > The patch also declares these two functions inline, to ensure inlining. But why is that better? This adds a few hundred bytes more text, which has a cost.