Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp203101ybi; Sat, 29 Jun 2019 08:44:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdKrVjaJo1MjFk3DVAXwqxm/UMcJDTn1oe+f7Rc04T4oL5UdhH3sBrvH3vz7Kr3g3nhuqX X-Received: by 2002:a63:d944:: with SMTP id e4mr14947677pgj.261.1561823049533; Sat, 29 Jun 2019 08:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561823049; cv=none; d=google.com; s=arc-20160816; b=yK7+qbUw5P84ZbUN69lV8sjbEOTepujCMp3OjopyP59rMtlXGJitYHWBcG5/2Ca7M1 0pAuBh+jiFLYwIa3nfYH5Bg5P7YyEZhzshh97zmin9unkCMA1jTRiESmwH11lhLHBkRg NmawjRw2Urx4Xvs7WYnaxOowuR7Fm76py63U+8CUb+Zx5rwK7S/uCqyuE3konV7pK+hO yJwBm7GdJbeK/liSFqTRTITiuc7KFhclrYZjpI9PtydlJTLTSXipwvZlfM+4qbReH0No lKEHRHhWTsyqxKYjnbRLR7GaADzmEm4Xu3SYj4Ixu/28A9DJCbjrmlM31KlIDS+jCnzs cGSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:to:subject :dkim-signature; bh=gpJbPI6bl+nXp0bBkiKZ8dARbqPZbVsTzRBwm4N0o3I=; b=VNt3B0/JKHzsVePtSo2oyHbym67dw8Jotg83w3WYXkO4DmSdYUiPN7OTj2+usOUYWj YsaMMChedKk5G1b3ixZ6FAlk3ufajaRtEWCJ05v6mMTvgu9hPScUMBBxkEe29eBtht5P 7Z/hMBsEm5ykDew5iteCThWSj/lS5sqooCbeHex3YD/BOXNvoBkTP+/gU4T5mrPntkqK KO3jf3WgXCskWfU/g2GhnkiwN9SM847PRo8W2yVv3AEaytPE94w+3pvk97eZZHx1Cqw8 lyJa6fjGgbSqLBFuYQzsR3zQENmxzsGECSSPDDOpw6rNpoiydDnPE9FR66BsDs5cl4aD FCmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fuoCgk3s; 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 22si5707574pfi.161.2019.06.29.08.43.53; Sat, 29 Jun 2019 08:44:09 -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=fuoCgk3s; 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 S1726906AbfF2Pm0 (ORCPT + 99 others); Sat, 29 Jun 2019 11:42:26 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35824 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbfF2Pm0 (ORCPT ); Sat, 29 Jun 2019 11:42:26 -0400 Received: by mail-pl1-f193.google.com with SMTP id w24so4908716plp.2; Sat, 29 Jun 2019 08:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to; bh=gpJbPI6bl+nXp0bBkiKZ8dARbqPZbVsTzRBwm4N0o3I=; b=fuoCgk3s9sNhhHbt/9pjpXKmKnR1KnQcACPAMVxh1BfU1yLyY0CXmHAm/CDYHVLE/M oWiJG4zqkAy6iLvovbRLhbFEjUX1nIRCBkOs6DTwhZdqTuCJxQI5uMH3t82G/BhY+Erj QqBBzPH9z3sV1XYKIodaXBvv9ZFZ/E5bxa1LFygjhat/VtPv6zQW+BrFHZWiCc2sw/2P zp1ppPKefxCaERfspxp158IArVajZo3qQGPg0MpJdUCYR6ZiF/uTcIVyWMRZWccZ3VWk AZEUwEx+zdu1qU/bCK8cKCCkDrpy34BWYYl/vLAj8dVbWj2WUkfnGShF0Ux9iqfNiFBX rjZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to; bh=gpJbPI6bl+nXp0bBkiKZ8dARbqPZbVsTzRBwm4N0o3I=; b=Nz3MJsZjQ5HOggJn6LlKiyQbT8Rrv/FE7X3+w8m8XbkielpGb7QN8/RTSp24EAJ9Pb PN+LbBnu6FIcwp1CmkIkiXAA0FEG6MnaajPwcNEa/9GBbATKeJbiI6jkk4laFOIwOqZx 4jkSGPrTIZb5kXf3gKCZPPT2ls4wJUrjQx26KOR+Oi+2UUuPzsz7D5htp779P+NWyKDT fQxW9W/wufNQJeQq5qBC92k0I04gH+UtrBpK9nGoU+4VIXuHnRsla1MD+hjq+JG8wByH zKuoIzqQklX/ZtPJnXMiJLELMB+DwkBJMrwBxCJNbi7f3u+hzCIh80lbUkoXhGQiMIGq A8ag== X-Gm-Message-State: APjAAAV0uOMu6GCgYPd1XeML+P8m2RADutut1pInhd+w+5ScCBz25wHf Xb1mfi0Oj6QYwVVCtIHoCag7h06C X-Received: by 2002:a17:902:7586:: with SMTP id j6mr18623540pll.128.1561822944838; Sat, 29 Jun 2019 08:42:24 -0700 (PDT) Received: from [172.20.3.188] ([12.206.169.194]) by smtp.gmail.com with ESMTPSA id m20sm5081301pjn.16.2019.06.29.08.42.24 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Sat, 29 Jun 2019 08:42:24 -0700 (PDT) Subject: Re: [PATCH 1/1] sbitmap: Replace cmpxchg with xchg To: Jens Axboe , osandov@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <722e1d561f0a49dc464d3a2b1be4c077f7502726.1558625912.git.asml.silence@gmail.com> From: Pavel Begunkov Openpgp: preference=signencrypt Autocrypt: addr=asml.silence@gmail.com; prefer-encrypt=mutual; keydata= mQINBFmKBOQBEAC76ZFxLAKpDw0bKQ8CEiYJRGn8MHTUhURL02/7n1t0HkKQx2K1fCXClbps bdwSHrhOWdW61pmfMbDYbTj6ZvGRvhoLWfGkzujB2wjNcbNTXIoOzJEGISHaPf6E2IQx1ik9 6uqVkK1OMb7qRvKH0i7HYP4WJzYbEWVyLiAxUj611mC9tgd73oqZ2pLYzGTqF2j6a/obaqha +hXuWTvpDQXqcOZJXIW43atprH03G1tQs7VwR21Q1eq6Yvy2ESLdc38EqCszBfQRMmKy+cfp W3U9Mb1w0L680pXrONcnlDBCN7/sghGeMHjGKfNANjPc+0hzz3rApPxpoE7HC1uRiwC4et83 CKnncH1l7zgeBT9Oa3qEiBlaa1ZCBqrA4dY+z5fWJYjMpwI1SNp37RtF8fKXbKQg+JuUjAa9 Y6oXeyEvDHMyJYMcinl6xCqCBAXPHnHmawkMMgjr3BBRzODmMr+CPVvnYe7BFYfoajzqzq+h EyXSl3aBf0IDPTqSUrhbmjj5OEOYgRW5p+mdYtY1cXeK8copmd+fd/eTkghok5li58AojCba jRjp7zVOLOjDlpxxiKhuFmpV4yWNh5JJaTbwCRSd04sCcDNlJj+TehTr+o1QiORzc2t+N5iJ NbILft19Izdn8U39T5oWiynqa1qCLgbuFtnYx1HlUq/HvAm+kwARAQABtDFQYXZlbCBCZWd1 bmtvdiAoc2lsZW5jZSkgPGFzbWwuc2lsZW5jZUBnbWFpbC5jb20+iQJ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GdbuvDzaq6/3OJLKohr5eLXNU3JkT+3HezydWm3W OPhauth7W0db74Qd49HXK0xe/aPrK+Cp+kU1HRactyNtF8jZQbhMCC8vMGukZtWaAwpjWiiH bA== Message-ID: <0979d23f-bc31-b653-51d0-867dd52bf7ee@gmail.com> Date: Sat, 29 Jun 2019 08:42:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <722e1d561f0a49dc464d3a2b1be4c077f7502726.1558625912.git.asml.silence@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="uzz2TY5uZnI06xCKH3n3Lp4BlDS8ROpf4" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --uzz2TY5uZnI06xCKH3n3Lp4BlDS8ROpf4 Content-Type: multipart/mixed; boundary="FuhgTVb8yfbQS7dziWodTAhy0by58eNYo"; protected-headers="v1" From: Pavel Begunkov To: Jens Axboe , osandov@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <0979d23f-bc31-b653-51d0-867dd52bf7ee@gmail.com> Subject: Re: [PATCH 1/1] sbitmap: Replace cmpxchg with xchg References: <722e1d561f0a49dc464d3a2b1be4c077f7502726.1558625912.git.asml.silence@gmail.com> In-Reply-To: <722e1d561f0a49dc464d3a2b1be4c077f7502726.1558625912.git.asml.silence@gmail.com> --FuhgTVb8yfbQS7dziWodTAhy0by58eNYo Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Ping? On 23/05/2019 08:39, Pavel Begunkov (Silence) wrote: > From: Pavel Begunkov >=20 > 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. >=20 > In the second block, atomic_cmpxchg() return value isn't checked, so > after atomic_cmpxchg() -> atomic_xchg() conversion it could be replace= d > with atomic_set(). Comparison with atomic_read() in the second chunk wa= s > left as an optimisation (if that was the initial intention). >=20 > Signed-off-by: Pavel Begunkov > --- > lib/sbitmap.c | 10 +++------- > 1 file changed, 3 insertions(+), 7 deletions(-) >=20 > 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 sbit= map *sb, int index) > /* > * First get a stable cleared mask, setting the old mask to 0. > */ > - do { > - mask =3D sb->map[index].cleared; > - } while (cmpxchg(&sb->map[index].cleared, mask, 0) !=3D mask); > + mask =3D xchg(&sb->map[index].cleared, 0); > =20 > /* > * 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 =3D &sbq->ws[wake_index]; > =20 > if (waitqueue_active(&ws->wait)) { > - int o =3D atomic_read(&sbq->wake_index); > - > - if (wake_index !=3D o) > - atomic_cmpxchg(&sbq->wake_index, o, wake_index); > + if (wake_index !=3D atomic_read(&sbq->wake_index)) > + atomic_set(&sbq->wake_index, wake_index); > return ws; > } > =20 >=20 --=20 Yours sincerely, Pavel Begunkov --FuhgTVb8yfbQS7dziWodTAhy0by58eNYo-- --uzz2TY5uZnI06xCKH3n3Lp4BlDS8ROpf4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE+6JuPTjTbx479o3OWt5b1Glr+6UFAl0Xht8ACgkQWt5b1Glr +6UtHw/+NA/Cl2kUbo540HN/b2x/QpS31C5Jq/4YyHKBPMidCw83E8RS+OB2/Sql 59OOugg8Bvw1ZAym2gM7/Ab6XmZpeWwg+kRSlRzKL9GPjJRg+U+kpz9oDF5WO4w8 qAI8gk+v74rjH8PVuNuwDQPnFiuyVWJA9QmbOf6uTZpuojAXVPWXjqTT2w3bCh1j XkOFR5LqdXgQEToCF4YJdpgXV4M3Peotk0lr2nA0ojf9NywB9kh/zJTnk1qPq8RY fSuX4bJwa45y1aduX+AI0jL0l140VUqFx8jcCqyma7nq2eOfTFstkx/4rm6b3Zbg 54OIisWekQy2hiUKDRic/GbnbToDuaFnzebyHacUKX1i/LWDxFtbt2SGF4S4g0kg Upq0VExbzi9Hfng7FF4NgzbVHkQGOVvZlBtDiW00k3PRzgwq8fPcPywluh1daOle qyEzKJlGIngBZARMfI9oFL7zpQ4FC+EnHh/m+CQtYzZqW6pcBH8Dyk+myYvxkFpE CNY1Fjk112Lq5lIcE4ZqNnGDxCsrFq3Bx4Ntq7R72+BjGchaM6yUVpfdQ37YK9m9 +g7u6zKZGN7/vWAaEtcFaSQEcIHPMAUzve5xONylGAJ03zcRq4skYEd7u5rkuWSd pJUMvgkJUWIoEUZ8HoMhBNmnwyFywcmOlU59F+hMa+AaPOMBNXc= =UP90 -----END PGP SIGNATURE----- --uzz2TY5uZnI06xCKH3n3Lp4BlDS8ROpf4--