Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2399458ybi; Mon, 1 Jul 2019 11:19:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwurNvE5j+DAh+mxLBliQMOnGM0GUnZXeuPtbaQvjUcXutlYAHscC6RNIF/LnUtsx0C25RT X-Received: by 2002:a65:6241:: with SMTP id q1mr25718888pgv.24.1562005194738; Mon, 01 Jul 2019 11:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562005194; cv=none; d=google.com; s=arc-20160816; b=sWtbVlqvOd0301PBCfZpsmmo11J6cn/WETRE7HWAxuqwX2fgGrjO3G5uSF57lYpeOP 17fyyw4pcb3htIDl5Q2nxJNYd5ppmpjywrwejd+7Y8IHXKuc1+biwaKuUtoMxCcrLKMp pEHrzbeeKs+ZWtubXEfG0oXqtyIddj3rvxY8V4eUpV3SZJYMR2WGxcqKe83SKp5HWiK1 SX9Phj+dbwkYTA2bDZUc4icMH1PUiKXtys7zfj6YJ3okgOfk3dIbLpr6epwt+imioy/e oKBzKzFOg06PvZYO2+UmEZkD1qVETnsmOSslkG7W09uf6bhmzJLlO0N34KQ76PHs7aQe SI1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GjbFO6Zi6jfRe/bkXkrP+9GcrEaqmKIfWUxraeXKXoE=; b=OgMnJ7f2YxlqR5GskSIl262sugNMgRp41G86l5+orjX2/wfuth3jrQ4Sqs/etc+1ni 07IRgH6cYvkg4YaagNHpWikTRZyveU3c6VplzTY6nyqAvp0BhzsdOmN32ZGoMcF2m77i s10uKyqLQ8xUlD9PzY9uXChxH7fLy96HT3kM2zXmVnP8dszn3JoDXVdkSOC4tuHdp6nn wnS+664INlAVm/tB82jA/hECG2HiqUTBwOf52x+tSUd97HNt48MLlFiWgRe3M59cJCYR e9C9JCfPGGh9GetiNOQz2xSfQwr0oGy3aAockfH07+jQXh0MHI6n7xEHLoeB5NZlvYkn NLhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=dNSImmto; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 39si10667974pla.73.2019.07.01.11.19.36; Mon, 01 Jul 2019 11:19:54 -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=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=dNSImmto; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729768AbfGARfg (ORCPT + 99 others); Mon, 1 Jul 2019 13:35:36 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43172 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727625AbfGARfg (ORCPT ); Mon, 1 Jul 2019 13:35:36 -0400 Received: by mail-pg1-f194.google.com with SMTP id f25so6363349pgv.10 for ; Mon, 01 Jul 2019 10:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GjbFO6Zi6jfRe/bkXkrP+9GcrEaqmKIfWUxraeXKXoE=; b=dNSImmtoyKvCh7FQUaeZ3H+IlOUassJYpIT4IOBzRA/umVqcBU+oJib3Y4Tl9gz8OO IeC82sEYlTh8MQW4gFDDVlu1TUmSEWj9SxFtgDS/zlesu6iMhWD1c+tytHcwKPoQjXUD bEysU3uxLQXV7tO2NZogs4GoPdJZ13MhQqGTQDa92yYqS1qt+Nu5QJRLcVeQPHr0rEED EkSkPyT8Y7qGSnA9Jzcp36zaYzcXo82TuoCsleDiTHzU/XpKq1nqUqvFRFLbsehZRDWu giulAdHxLjgMf+YqikwbTd+sFIgLr1y6si4OzEGSSR+CEYVRGPYJHv7sO+9bW6zPAnBz rdFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GjbFO6Zi6jfRe/bkXkrP+9GcrEaqmKIfWUxraeXKXoE=; b=fQuYVQtHQ6PSvuDTBuozNANiUU/fYBXDPGB0n19F7A2ofKUGLHutPxeNpdS/hjLgWa zhjO0kDYLWVJH76vV358j5W65vQqiTI+RrZpNPJYIIjqXmNCrN2/MNrlvrm1hh5fL7WX vL5gFXIPDeTQigLKpWvNpo0Hv7aT1lEL1FcjiJFmtS9auN7x7ix0zzsz1aw+nGGeW3OZ Fa+bYCD74GJe6F+LhVPTDRMF+ebPRTzxmCyvrc1xojRvMri9ryJxvbKG8cRz1Dm45ngi p8jbzxWh3Of4+d7l5ieKMYGSNM0m67EHrLt8tfAn07VjJoM7k8Al57/MYPEYUWW57952 FJ9Q== X-Gm-Message-State: APjAAAU34Pb9a/lpNs+jpzVU60HgFqszLDkXI7dq3rSDvikIguIljfjD L04/Qm1OJlcUafu88jENMoscuvtsxmA= X-Received: by 2002:a17:90a:8d09:: with SMTP id c9mr428334pjo.131.1562002535372; Mon, 01 Jul 2019 10:35:35 -0700 (PDT) Received: from vader ([2620:10d:c090:200::2:c56d]) by smtp.gmail.com with ESMTPSA id i126sm12622656pfb.32.2019.07.01.10.35.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 10:35:34 -0700 (PDT) Date: Mon, 1 Jul 2019 10:35:34 -0700 From: Omar Sandoval To: Pavel Begunkov Cc: Jens Axboe , osandov@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] sbitmap: Replace cmpxchg with xchg Message-ID: <20190701173534.GA10076@vader> References: <722e1d561f0a49dc464d3a2b1be4c077f7502726.1558625912.git.asml.silence@gmail.com> <0979d23f-bc31-b653-51d0-867dd52bf7ee@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0979d23f-bc31-b653-51d0-867dd52bf7ee@gmail.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 29, 2019 at 08:42:23AM -0700, Pavel Begunkov wrote: > Ping? > > On 23/05/2019 08:39, Pavel Begunkov (Silence) wrote: > > 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); This hunk is clearly correct. > > /* > > * 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); This hunk used to imply a memory barrier and no longer does. I don't think that's a problem, though. Reviewed-by: Omar Sandoval