Message ID | 20221020155104.9485-1-ubizjak@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp191272wrr; Thu, 20 Oct 2022 09:04:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM593N1gbdvtwOS//N/dQwBUH0QkZK6DrB0aBm7JzEEo0k6q/JxO30fVSYBE/h5g0xOa8aXO X-Received: by 2002:a17:907:94d1:b0:790:65a:3a18 with SMTP id dn17-20020a17090794d100b00790065a3a18mr11350792ejc.428.1666281849270; Thu, 20 Oct 2022 09:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666281849; cv=none; d=google.com; s=arc-20160816; b=TE1HW9VY99g1ZXVqNBUnkB4ozHtcwWQ+Qnt91OnjHFk71ZUXJgq7xCC43Ri4YO+R40 Ez2OwQPT/5FGxZyux0fE/EzNNEQBRej6LkOu8J3uTDKgaV7wxCBWBnopxx4S6gS++HlJ h1nvr/4DzoM3ZeSrJWNQhzqi3yzqQL7MHfI9Op2LEs5SCtiFSgVLP+XceF1vat/RUyFq EHnWhosw7uUqY85d9XMh61to7kYygO66SFCdj0qiD02VujkQunz6u6UJ8iDaF6lLR83A IR0pStxX7V69qAb9IBX0FMvbacpTlbnETnmJ5yIvtJpMv9plJoSKtM8GwQZYXdcdqbuP f8dg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=54fd/0yen88eFOEGtvTo0HIRTRehsPlXZmjj7D9lRYM=; b=vRzK8UXT+GHzbhsR4FwfSb3NslYTF/Go7co5juB+8cR88A9YKs4451Z1we6gXTuVo6 WdhLbS7OW1+LkEUbhKy2D7h4PSpM3gbP0yaC3wy9uampK/Ntj1i3b+6xSaobt091By23 VbAmZGcMZ8Jugw2Y9vuymUS97bRJ4+8ui0+zVLYcqe2R06y3mRF9Z9fr8R9gd8SFOHi5 df5Ttar3yhPg3N5n/5myhVT/kkULzuGysjZZfX9Fdg8sAVdnVbMPOeXWQ81ZrsI4dhgX EwZYWw1GwtWCfeHWWhpIhs7YQI+9POrb84Dxrm8ouiTf3sOmiKXqfH+OejDZ87ZHr4EN b6Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AYzEUOOv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs31-20020a1709073e9f00b0077e156d8e07si13864180ejc.828.2022.10.20.09.03.35; Thu, 20 Oct 2022 09:04:09 -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=@gmail.com header.s=20210112 header.b=AYzEUOOv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230342AbiJTPv1 (ORCPT <rfc822;ruipengqi7@gmail.com> + 99 others); Thu, 20 Oct 2022 11:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbiJTPvX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Oct 2022 11:51:23 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 396821B90FE; Thu, 20 Oct 2022 08:51:16 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 186-20020a1c02c3000000b003c6c154d528so2685621wmc.4; Thu, 20 Oct 2022 08:51:16 -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:subject:date:message-id:reply-to; bh=54fd/0yen88eFOEGtvTo0HIRTRehsPlXZmjj7D9lRYM=; b=AYzEUOOvgKrh8OY79DYRWSgwx6N8g/vR6J3zOIQt1gL8WOjDLWAvK0msuxAhyjy8H5 gggcBJuxspkS1/wgrQLT9gieS4kFqu/mJAgZ91Qbp9fsYRwVSSdVjymrhQOpRcfHFyrs vNRr0nHhoAQ+F8gPsOe5wA8m7xO+PAeHiFT3p0gr84lf5L/rtvXxecm4lkmf8I+c2Toh 2iNtwXaKtllOhvTEnCy8jnkFj3p8ozL9gV+oeNG/AXBMdhpeiy36hxivHZN0IEx6e6Fw 5Fpi5LiZdrRHQMMbr9nRKNAjvE+yYYa1ZFS3CvKJEAZ++wOhbYVd2+1kidN34KTWWFyZ FD0w== 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:subject:date:message-id :reply-to; bh=54fd/0yen88eFOEGtvTo0HIRTRehsPlXZmjj7D9lRYM=; b=bFpCd6txKIsCYOdo9RQx292AGuDTLgwWP7IldpdxKjB8BgE/V2a82KeXcQ5mvU7eoA SrNjf258FHSYw5g/oKffjx/3bohbnsTSWFL4etuJyntjhmMCfTkmXWek7QWpAnlm9qeq ihtFzT8u858xCqI2+VMgyBMVVlnAeeMxNsGqFO5+YfxbQ7kukMOi2eW1CMms8yYqWy2C 98o8Qx8YJzLVlsTnbTt/QXuLkqoYeO5/Gp9QeXh9GYW/g3LPGCLvONmWE7UU0vh5vQDY DjvQnHvCTHwunKKlsTwcPIs6sDKzUdrZUe6E0YAmOl5XJ6Np7z4Ljn4Zn4VQCL1iuYp4 2EUw== X-Gm-Message-State: ACrzQf3jQhfsei/+jAHvASx6INqiaz7SRou86Y6u9AeN2P+pkGGKDZXT 5WGHSMWBrhv/3O4ezgn/O2q90TGUDt+xUA== X-Received: by 2002:a1c:f60d:0:b0:3be:708b:c96c with SMTP id w13-20020a1cf60d000000b003be708bc96cmr31458957wmc.168.1666281074889; Thu, 20 Oct 2022 08:51:14 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id b21-20020a05600c4e1500b003a83ca67f73sm31645wmq.3.2022.10.20.08.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 08:51:14 -0700 (PDT) From: Uros Bizjak <ubizjak@gmail.com> To: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak <ubizjak@gmail.com>, Song Liu <song@kernel.org> Subject: [PATCH v2] raid5-cache: use try_cmpxchg in r5l_wake_reclaim Date: Thu, 20 Oct 2022 17:51:04 +0200 Message-Id: <20221020155104.9485-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747223156144968897?= X-GMAIL-MSGID: =?utf-8?q?1747223156144968897?= |
Series |
[v2] raid5-cache: use try_cmpxchg in r5l_wake_reclaim
|
|
Commit Message
Uros Bizjak
Oct. 20, 2022, 3:51 p.m. UTC
Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
r5l_wake_reclaim. 86 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. There is no need to re-read the value in the loop.
Note that the value from *ptr should be read using READ_ONCE to prevent
the compiler from merging, refetching or reordering the read.
No functional change intended.
Cc: Song Liu <song@kernel.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
v2: Fix garbled subject line
---
drivers/md/raid5-cache.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On Thu, Oct 20, 2022 at 8:51 AM Uros Bizjak <ubizjak@gmail.com> wrote: > > Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in > r5l_wake_reclaim. 86 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. There is no need to re-read the value in the loop. > > Note that the value from *ptr should be read using READ_ONCE to prevent > the compiler from merging, refetching or reordering the read. > > No functional change intended. > > Cc: Song Liu <song@kernel.org> > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Applied to md-next. Thanks! Song > --- > v2: Fix garbled subject line > --- > drivers/md/raid5-cache.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c > index 832d8566e165..a63023aae21e 100644 > --- a/drivers/md/raid5-cache.c > +++ b/drivers/md/raid5-cache.c > @@ -1565,11 +1565,12 @@ void r5l_wake_reclaim(struct r5l_log *log, sector_t space) > > if (!log) > return; > + > + target = READ_ONCE(log->reclaim_target); > do { > - target = log->reclaim_target; > if (new < target) > return; > - } while (cmpxchg(&log->reclaim_target, target, new) != target); > + } while (!try_cmpxchg(&log->reclaim_target, &target, new)); > md_wakeup_thread(log->reclaim_thread); > } > > -- > 2.37.3 >
diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c index 832d8566e165..a63023aae21e 100644 --- a/drivers/md/raid5-cache.c +++ b/drivers/md/raid5-cache.c @@ -1565,11 +1565,12 @@ void r5l_wake_reclaim(struct r5l_log *log, sector_t space) if (!log) return; + + target = READ_ONCE(log->reclaim_target); do { - target = log->reclaim_target; if (new < target) return; - } while (cmpxchg(&log->reclaim_target, target, new) != target); + } while (!try_cmpxchg(&log->reclaim_target, &target, new)); md_wakeup_thread(log->reclaim_thread); }