From patchwork Tue Aug 9 16:56:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 12939777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 979D4C19F2D for ; Tue, 9 Aug 2022 16:56:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245170AbiHIQ4b (ORCPT ); Tue, 9 Aug 2022 12:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245162AbiHIQ43 (ORCPT ); Tue, 9 Aug 2022 12:56:29 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EAD1637D; Tue, 9 Aug 2022 09:56:28 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id j15so15003955wrr.2; Tue, 09 Aug 2022 09:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=trF1Dnl/B4bmI0Jk6roxYxlXVoEJE4owCmdIB31PL+E=; b=O2mS2dqkqbMKlXPy/EAZEuhFeIOCzGJo8weuij0/bAzS9ZFRzhDDZcnR7jwZuTQAq+ mdpFDpLmj+2ttPS/4TBVQJQANNgkZnkaJt5aOjPZgYHdIpHu/wSylhB6FeCHezO2iL9o 3y0nJBpYOvhIRu8gGVhXISfXVj5tJMa8bTTMokNm/lkj+GHaH5/+YCuZiifOl+J4Wroe +pWN/dD1G7H1tYDn0MzWXqNhPr+JmO2pGf7eoXjZnJI7C7cqp35tdK6CbI10BQ/+NMud iQbvnszrhe8T0p6piiWg9PVOYmafDS6btza5ejCAp/oy+MCyGRN7u9gMOzcy2dHtHEYU qo5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=trF1Dnl/B4bmI0Jk6roxYxlXVoEJE4owCmdIB31PL+E=; b=qdWOFOgrK2RnXnWDk1u+9EtQzKoadbOmgklfwldAh7FIYLrvZUHiFZbIOfh08YIURJ LaMyn3G69LiuFoKBo09JwvKdyBRkVDMYETe7sPLseoXj/RXV+e5UnzXRhPtZM12J4yW3 YosyanmvRQkeZSvDOATwwUk3b3px1kNl0ZfxRLnh8QFSMwpVU5Zgz9tfJBnKnmM7HE8C /d1WO4A+7zIorUX8sPbCedbcZVXCAmm7e5ecWzUJe0O2Cb8f0R/+D6A85R09bbHrtF7B m0Ij6EVJYKrZGsfjPI84VK8EIT2XenHDrSXUuHU9ARHOXDq0A9ptnVHIOpnr2bEo+/6j HwNg== X-Gm-Message-State: ACgBeo2vmF0Z+HHt30cZa/GPauHK3EPvqElZ33HSDOTatC5o9bf17ix+ V0Q9KYtQNxiLaB0MfWChID4O6b458YBPyA== X-Google-Smtp-Source: AA6agR5Nz1sE/9VlQRDfDjrl3cMmnbOu/eagJ74tZByUddQH/G/DtvACPP2g2RkLT2uf5hDzoe1kTg== X-Received: by 2002:adf:de0f:0:b0:21e:ead4:23f5 with SMTP id b15-20020adfde0f000000b0021eead423f5mr14622172wrm.641.1660064186432; Tue, 09 Aug 2022 09:56:26 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id o41-20020a05600c512900b003a2e1883a27sm26346290wms.18.2022.08.09.09.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 09:56:26 -0700 (PDT) From: Uros Bizjak To: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , "Darrick J. Wong" Subject: [PATCH] fs/xfs: Use atomic64_try_cmpxchg in xlog_grant_{add,sub}_space Date: Tue, 9 Aug 2022 18:56:15 +0200 Message-Id: <20220809165615.9694-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Use `!atomic64_try_cmpxchg(ptr, &old, new)` instead of `atomic64_cmpxchg(ptr, old, new) != old` in xlog_grant_{add,sub}_space. 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. - atomic64_try_cmpxchg implicitly assigns the *ptr value to &old when cmpxchg fails, enabling further code simplifications. This patch has no functional change. Cc: "Darrick J. Wong" Signed-off-by: Uros Bizjak --- fs/xfs/xfs_log.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index 4b1c0a9c6368..92e39873d09e 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -148,7 +148,7 @@ xlog_grant_sub_space( int bytes) { int64_t head_val = atomic64_read(head); - int64_t new, old; + int64_t new; do { int cycle, space; @@ -161,10 +161,9 @@ xlog_grant_sub_space( cycle--; } - old = head_val; new = xlog_assign_grant_head_val(cycle, space); - head_val = atomic64_cmpxchg(head, old, new); - } while (head_val != old); + + } while (!atomic64_try_cmpxchg(head, &head_val, new)); } static void @@ -174,7 +173,7 @@ xlog_grant_add_space( int bytes) { int64_t head_val = atomic64_read(head); - int64_t new, old; + int64_t new; do { int tmp; @@ -190,10 +189,9 @@ xlog_grant_add_space( cycle++; } - old = head_val; new = xlog_assign_grant_head_val(cycle, space); - head_val = atomic64_cmpxchg(head, old, new); - } while (head_val != old); + + } while (!atomic64_try_cmpxchg(head, &head_val, new)); } STATIC void