Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2208594pxa; Mon, 17 Aug 2020 04:06:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTGEc6AHy1e0oumCctDIS2zNvkVg0ZznAa1Pn9dCCUU28rZAg5SKOERJjU7aziTgQYiN5H X-Received: by 2002:aa7:c358:: with SMTP id j24mr13740328edr.377.1597662412491; Mon, 17 Aug 2020 04:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597662412; cv=none; d=google.com; s=arc-20160816; b=ISHO4cJS7C5LrEoKUQ6zdWMjbzO8EVHb73Pm7utaE2TI+m3eG7juUj7Zr9m6tohnst KJ026ijeyim09zBOZ2QIAOtaNKqSu4ha7X8T/N7qKViNeZgWnCSmSknoxfV+PFHBvpns MJFJ9s7N2tG9q7vytXyHvRo384KOtNKU7tfYfAT0ZIgVsRIM6cbA0UUDV+t1sgO0DHys 5ScCbAqidpm3hBnNa1qikKI34ZSWBCDY+hGz8hdhMbFNhxQ6xK+U5QxyQQNpUYONJt24 47IUBIk0NRaovjpKOCWdYQoErzv4fgkTKYYrknHoYJ4bqwSTVMTzh8TUZ5PJwnAelZoe ynvA== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=ccb8UrJXQJK5INlo6VsEriZM460hYfxW8wEyUKNqp2E=; b=zUWuLcFW2iQGAVqKHNyJqdY1flGmZ9cNdaHq/qsYf6+AlUoxnmt5pA3GMlZd+fr1df 10rx7Elry8xuxyJCDCESNHMyYgX8TjRJ6cEWJwbLQCWIasAVrtsFV55sOYomEEqK+kPK iXNe1/Iibhc9xcg974rlmXW3dSzF5eq86Aq84G/vI+IZXiSCPpNY1pLv3vvBC4weg8R6 RIQC8UGJt+osAw5nYDk+doEUm0ggySDks7efLPB21sMytmcYZzHag7W92SP8VXZKpzsh MDu7QMy87LWrTD4CcZKk0FA2fZzEzs8BFNcevyScomZOTCBPgDyGRnaHFV45SnPYaZC9 KQ8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca18si10597645edb.414.2020.08.17.04.06.28; Mon, 17 Aug 2020 04:06:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbgHQLDz (ORCPT + 99 others); Mon, 17 Aug 2020 07:03:55 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:53464 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727062AbgHQLDx (ORCPT ); Mon, 17 Aug 2020 07:03:53 -0400 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2020/8/17 ????5:58, Wei Yang ะด??: > 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' flags, >> 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. >> > > 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. > > Correct me, if not. Right and not, Cacheline false sharing is right. but after that, cmpxchg still need to compare the pointed data, if the data is long, it need to compare long word and make sure nothing changes in the long word. If we narrow the comparsion data to byte, cmpxchg will just sync up on a byte. So it looks like there are 2 level false sharing here. Thanks Alex for (;;) { - old_word = cmpxchg(&bitmap[word_bitidx], word, (word & ~mask) | flags); - if (word == old_word) + old_byte = cmpxchg(&bitmap[byte_bitidx], byte, (byte & ~mask) | flags); + if (byte == old_byte) break; - word = old_word; + byte = old_byte; }