Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp321338pxk; Thu, 3 Sep 2020 00:02:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4v2eec782kJICI9RWa4rygoNGzdJn8JpcEhlf6IFWtiBC9CECiMzOcYymhKiY82r6tuRH X-Received: by 2002:a05:6402:1016:: with SMTP id c22mr1639884edu.89.1599116569353; Thu, 03 Sep 2020 00:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599116569; cv=none; d=google.com; s=arc-20160816; b=ToDd91//jF/ZByMehcSICJRv0z5uEbS6hvtnbqTzSq6xRTPOlTFJFp31axRo/FtJUH i1Hn24u/hmwWyqZor/K0kLvLFVgnpjgYN33wBhHsEF03Rx9WjjTDH0pNFOtDKU5BlhlM T+aypoY4LWUMI9PaBnKcmrhPTlzpCnNgwZ5illsUn/ONSoGT3VD6BI8TTOkLUPGzkPuw sJF+gVd9YGjQjfkomYdW7yX6JlpXkJ3s1vUkkeg1mFCELga+Yw057h4Jq11moODENKul SoYMU2ozLQTt7CTF1qCfdvnMAgENzIwCv3jABlPlU9xNEJBQyyNsh03dor+bqcGCSemi h65g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=kFmtt5QkDI+QkphTZHFrfipTUi1QxHIE2HesXAbH/Qo=; b=DHbUMbvjETzuxUUYnourLu5JNgELZ4CsEboBBcGleaXmn2IcEkMyqDFepatSJUzG3Y PTy6lQVeTQfa2CZNv2l8wkeFu3qvIKsrBh6F977dsy6lGEytEWv9RveRfLuzAS4bAE2w NBUtaUmHyE2twAiu73ks8CPffgrmUFLioqfmn4RaICLmigI4xxDDDllxvr1QTtqTdt0N aRTLJ+5F34oaMXUin5i8jgCwDIX+vtrAAeD5pxkmomN2vGu+ihamsgeGpY3pCaA5oi8a YYVjKcocQQnVWgQ7/lGwJX/LI3U5ByLjUf9O+myCsYqu08DVNgGi1nBuC+tJPcEGQzjb xyQg== 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 nr22si1281065ejb.535.2020.09.03.00.02.26; Thu, 03 Sep 2020 00:02:49 -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 S1727938AbgICHBo (ORCPT + 99 others); Thu, 3 Sep 2020 03:01:44 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:56979 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbgICHBm (ORCPT ); Thu, 3 Sep 2020 03:01:42 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0U7n-ifu_1599116494; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U7n-ifu_1599116494) by smtp.aliyun-inc.com(127.0.0.1); Thu, 03 Sep 2020 15:01:35 +0800 From: Alex Shi To: Anshuman Khandual , David Hildenbrand , Matthew Wilcox , Vlastimil Babka , Alexander Duyck Cc: Andrew Morton , Mel Gorman , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v4 2/4] mm/pageblock: remove false sharing in pageblock_flags Date: Thu, 3 Sep 2020 15:01:21 +0800 Message-Id: <1599116482-7410-2-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1599116482-7410-1-git-send-email-alex.shi@linux.alibaba.com> References: <1599116482-7410-1-git-send-email-alex.shi@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current pageblock_flags is only 4 bits, so it has to share a char size in cmpxchg when get set, the false sharing cause perf drop. If we incrase the bits up to 8, false sharing would gone in cmpxchg. and the only cost is half char per pageblock, which is half char per 128MB on x86, 4 chars in 1 GB. Signed-off-by: Alex Shi Cc: Andrew Morton Cc: Mel Gorman Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org --- include/linux/page-isolation.h | 2 +- include/linux/pageblock-flags.h | 2 +- mm/page_alloc.c | 10 +++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h index 572458016331..baa2e1ecc134 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -35,7 +35,7 @@ static inline bool is_migrate_isolate(int migratetype) struct page *has_unmovable_pages(struct zone *zone, struct page *page, int migratetype, int flags); -void set_pageblock_migratetype(struct page *page, int migratetype); +void set_pageblock_migratetype(struct page *page, unsigned char migratetype); int move_freepages_block(struct zone *zone, struct page *page, int migratetype, int *num_movable); diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flags.h index d189441568eb..f785c9d6d68c 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -25,7 +25,7 @@ enum pageblock_bits { * Assume the bits will always align on a word. If this assumption * changes then get/set pageblock needs updating. */ - NR_PAGEBLOCK_BITS + NR_PAGEBLOCK_BITS = BITS_PER_BYTE }; #ifdef CONFIG_HUGETLB_PAGE diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 81e96d4d9c42..3688e6b83318 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -517,19 +517,15 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, unsigned long bitidx, byte_bitidx; unsigned char old_byte, byte; - BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); + BUILD_BUG_ON(NR_PAGEBLOCK_BITS != BITS_PER_BYTE); BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); bitmap = get_pageblock_bitmap(page, pfn); bitidx = pfn_to_bitidx(page, pfn); byte_bitidx = bitidx / BITS_PER_BYTE; - bitidx &= (BITS_PER_BYTE-1); VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); - mask <<= bitidx; - flags <<= bitidx; - byte = READ_ONCE(bitmap[byte_bitidx]); for (;;) { old_byte = cmpxchg(&bitmap[byte_bitidx], byte, (byte & ~mask) | flags); @@ -539,13 +535,13 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, } } -void set_pageblock_migratetype(struct page *page, int migratetype) +void set_pageblock_migratetype(struct page *page, unsigned char migratetype) { if (unlikely(page_group_by_mobility_disabled && migratetype < MIGRATE_PCPTYPES)) migratetype = MIGRATE_UNMOVABLE; - set_pfnblock_flags_mask(page, (unsigned long)migratetype, + set_pfnblock_flags_mask(page, migratetype, page_to_pfn(page), MIGRATETYPE_MASK); } -- 1.8.3.1