Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1923724ybm; Thu, 23 May 2019 08:41:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXaUOYQAClHwV3OtloH5uPrYv3u8ROUhr5Nc5wFGnS2x3buipHAc2JxO6psq8XtPqrao9Z X-Received: by 2002:a17:902:6a83:: with SMTP id n3mr99621911plk.109.1558626066343; Thu, 23 May 2019 08:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558626066; cv=none; d=google.com; s=arc-20160816; b=s8O4x8Qf6THHtrUhk+bXxlPgbfcvsVkl0zmj1VfOXcopNRkh/Mce7KnfhsF4wJsMJW IcnwL2ISbopbICJZIVyz8gx09eoN1bYshwR1MVGcobaXI/c5pCPenEUG5quZ9yOFmiku rR3mT8RSsOAvr1O/xqwqzfXdqe5gztOvqUX2oeqWkAZYnh0GToyo/3RZ5UzdLlS4Ka7L HMM8kHnmlsM138ViwLl/YWETidj1CfZIG6HYZjJu6m+bQKnP8HfRbeQXa7VZmRk37JGq HcyyHTpSLedIgZWbhCoiRakT8ogAxPSZrYbe74+/NuRupZtxs29bdRjnBkEW0QphP5VL Ew6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sg9QJMVoIXaKWf9d4CiiruugNRRgEMRA5guNFQCIeLc=; b=unzcly9swozsN6GloldMWR86omhxzF3RFsawiIAdIcq61qXBCz9DgBYo8X7fauWrbC itFp/lFLNCpAlp/1nBPzfHDz5fSbWRJDDm4MfrPPIMUF+EPbC5qXG+Lc1lv8i2arBYJ+ mcjxPeNcpqFBXwk+ppJ6WEMghFe5MHkW7DcWdQClccoFMhxAcOL4O7nElxdoX7Z6ERxv XSL26A5j9okOAqNXNF13K5ucquTdXatuuQlonD7jN5XmLTwu2RaW3Cc+cfQyBOlkpsmU W/XQSvPe5GgIv+/7QiNsUDSCqLbs/e1rr6oKAmMZozBL7ZiDDPqVuV0U1bQF108tHsJD mypA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QziK08t3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13si27724452pgg.389.2019.05.23.08.40.49; Thu, 23 May 2019 08:41:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QziK08t3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731042AbfEWPja (ORCPT + 99 others); Thu, 23 May 2019 11:39:30 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35519 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730760AbfEWPja (ORCPT ); Thu, 23 May 2019 11:39:30 -0400 Received: by mail-lj1-f194.google.com with SMTP id h11so5940411ljb.2; Thu, 23 May 2019 08:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sg9QJMVoIXaKWf9d4CiiruugNRRgEMRA5guNFQCIeLc=; b=QziK08t3EUrliO+xfZUbyOcUD9cQyhbf8kO0GsHcyjftkFBnNC/BfRrHzr9W1s/6QP jtoQcNA2YjVKpTef+5mwavvlXvI5fPlaO5Gk2Y2o95csW7Boe8DEWdkmqOmK8vAYm0KQ +gpkyNlaniZ7bqlJt7kZ+Of6EAWbtse3eVvY0kM42vvvQdq+MaH6BxDiGpFWXuJpfSzL 6UoFdzz8B9Uog5MamvqMYLJLuBp9yKMZ3YGzs1dQJBcsP0YRy7tR1X55SkzQ8hIKn+U6 E+APeHivXDJtOR3Ht9fTdxrSuZWjF8V7Fxm2lX51+fgN8j9BIXD2h2GUSBQGMzugbuNO Lycw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sg9QJMVoIXaKWf9d4CiiruugNRRgEMRA5guNFQCIeLc=; b=GYkVYf//Y4ao83A1IrzyAsstYeuVHr4z359mod6oJWYna+gcewb+zg+zUSqKsa4nM2 mIxhp4leV7M+AmuVYVA9XufCS/tV9i/gcr5UIeE1dxiGiRFwnLmGCphaDAG1tPJQE9C7 TwC+YC/YVkV5gTLVCyxQpAMKnah3uA/37ScAK5xV10Y0Dc0mAS3Gi0p0Rb+V0Zsq+5mD TLsEGwe/5oLbRAy1X3LvuFOqfV8W502IakBlqgIULPh5HGjRwyzXydmhta343H+Rk9ZV h/Bdflq0No7gZH+ON36HuEeS5EJXM8CCA1uYxwB2xduEzrJ66F4ASArZpr5Bc43XFXP7 H1yw== X-Gm-Message-State: APjAAAWrWOFum//1+ZW3+H545spXbyu8bMwq7Tc5SwmPgyazB+kz116b sdbXj0tSCvpdekVlbaerOrU= X-Received: by 2002:a2e:8644:: with SMTP id i4mr7460180ljj.0.1558625968417; Thu, 23 May 2019 08:39:28 -0700 (PDT) Received: from localhost.localdomain (mm-89-92-44-37.mgts.dynamic.pppoe.byfly.by. [37.44.92.89]) by smtp.gmail.com with ESMTPSA id z9sm294677lfa.25.2019.05.23.08.39.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 08:39:27 -0700 (PDT) From: "Pavel Begunkov (Silence)" To: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Pavel Begunkov Subject: [PATCH 1/1] sbitmap: Replace cmpxchg with xchg Date: Thu, 23 May 2019 18:39:16 +0300 Message-Id: <722e1d561f0a49dc464d3a2b1be4c077f7502726.1558625912.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov cmpxchg() with an immediate value could be replaced with less expensive xchg(). The same true if new value don't _depend_ on the old one. In the second block, atomic_cmpxchg() return value isn't checked, so after atomic_cmpxchg() -> atomic_xchg() conversion it could be replaced with atomic_set(). Comparison with atomic_read() in the second chunk was left as an optimisation (if that was the initial intention). Signed-off-by: Pavel Begunkov --- lib/sbitmap.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 155fe38756ec..7d7e0e278523 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -37,9 +37,7 @@ static inline bool sbitmap_deferred_clear(struct sbitmap *sb, int index) /* * First get a stable cleared mask, setting the old mask to 0. */ - do { - mask = sb->map[index].cleared; - } while (cmpxchg(&sb->map[index].cleared, mask, 0) != mask); + mask = xchg(&sb->map[index].cleared, 0); /* * Now clear the masked bits in our free word @@ -527,10 +525,8 @@ static struct sbq_wait_state *sbq_wake_ptr(struct sbitmap_queue *sbq) struct sbq_wait_state *ws = &sbq->ws[wake_index]; if (waitqueue_active(&ws->wait)) { - int o = atomic_read(&sbq->wake_index); - - if (wake_index != o) - atomic_cmpxchg(&sbq->wake_index, o, wake_index); + if (wake_index != atomic_read(&sbq->wake_index)) + atomic_set(&sbq->wake_index, wake_index); return ws; } -- 2.21.0