From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C93C5C433DF for ; Mon, 17 Aug 2020 11:04:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 520272067C for ; Mon, 17 Aug 2020 11:04:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 520272067C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E55846B002A; Mon, 17 Aug 2020 07:04:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E06CE6B002B; Mon, 17 Aug 2020 07:04:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF6FF6B002C; Mon, 17 Aug 2020 07:04:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id B74A26B002A for ; Mon, 17 Aug 2020 07:04:04 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 79E91180AD837 for ; Mon, 17 Aug 2020 11:04:04 +0000 (UTC) X-FDA: 77159776008.19.roll84_560ae2227016 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 5018C1ACC35 for ; Mon, 17 Aug 2020 11:04:04 +0000 (UTC) X-HE-Tag: roll84_560ae2227016 X-Filterd-Recvd-Size: 2985 Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com [47.88.44.36]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Mon, 17 Aug 2020 11:04:03 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R841e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0U60T4QO_1597662228; Received: from IT-FVFX43SYHV2H.local(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U60T4QO_1597662228) by smtp.aliyun-inc.com(127.0.0.1); Mon, 17 Aug 2020 19:03:49 +0800 Subject: Re: [PATCH 1/2] mm/pageblock: mitigation cmpxchg false sharing in pageblock flags To: Wei Yang Cc: Andrew Morton , Hugh Dickins , Alexander Duyck , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1597549677-7480-1-git-send-email-alex.shi@linux.alibaba.com> <20200817095821.GA29756@L-31X9LVDL-1304.local> From: Alex Shi Message-ID: <301b82e3-4ee1-8b90-a6a6-256fd8885e59@linux.alibaba.com> Date: Mon, 17 Aug 2020 19:02:51 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200817095821.GA29756@L-31X9LVDL-1304.local> Content-Type: text/plain; charset=gbk X-Rspamd-Queue-Id: 5018C1ACC35 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: =D4=DA 2020/8/17 =CF=C2=CE=E75:58, Wei Yang =D0=B4=B5=C0: > On Sun, Aug 16, 2020 at 11:47:56AM +0800, Alex Shi wrote: >> pageblock_flags is used as long, since every pageblock_flags is just 4 >> bits, 'long' size will include 8(32bit machine) or 16 pageblocks' flag= s, >> that flag setting has to sync in cmpxchg with 7 or 15 other pageblock >> flags. It would cause long waiting for sync. >> >> If we could change the pageblock_flags variable as char, we could use >> char size cmpxchg, which just sync up with 2 pageblock flags. it could >> relief much false sharing in cmpxchg. >> >=20 > If my understanding is correct, CPU reads data in the size of cacheline= . > Define a variable a char or other, doesn't help on false sharing.=20 >=20 > Correct me, if not. Right and not, Cacheline false sharing is right. but after that, cmpxchg still need to c= ompare the pointed data, if the data is long, it need to compare long word and m= ake sure nothing changes in the long word. If we narrow the comparsion data to byt= e, cmpxchg will just sync up on a byte. So it looks like there are 2 level false sha= ring here. Thanks Alex for (;;) { - old_word =3D cmpxchg(&bitmap[word_bitidx], word, (word & = ~mask) | flags); - if (word =3D=3D old_word) + old_byte =3D cmpxchg(&bitmap[byte_bitidx], byte, (byte & = ~mask) | flags); + if (byte =3D=3D old_byte) break; - word =3D old_word; + byte =3D old_byte; }