Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4211480pxf; Tue, 23 Mar 2021 05:44:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOAVNFggA2jQsxmn2MTkjiE4gurRVzGvs6A1aQvd28Y2RIMiDHfTg3dS/jJfbon8+1Mfc7 X-Received: by 2002:a17:906:ef2:: with SMTP id x18mr4839520eji.323.1616503463567; Tue, 23 Mar 2021 05:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616503463; cv=none; d=google.com; s=arc-20160816; b=fV3CaVVYkDGaoZcaD7Qi/VvZLi41gTJ68PQh4z+4lUANUEZ22GL2Yr+SGkuetB3hqt z8GEwK0QdCGtmu7ueuvKi1IHYv/QKzAYj4cn9VpqcXKx37i95L/HqCpH6u+rS0xjud5u KhTtFYJnNwOBczMrBIjJ078M94JWiJjE2IM7dtobtPoCYUR92aBYk0r4ZqyseIjf1YIe Xu1bSWZmq3MX/KZ/rgDU4gloT8JWZ4OobWIoPdTb0CHqTkjtsOXYIXq+vDmU3DLRcg3v JprDb8KRpgaWLcjyiZyA+tH02cmtFkB4IAWkLsyxDLfT9eaMK0hx9AnODBVIqDPQmqD0 T1Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=WX4VFgKFtFw9xauaSc8sZWCzm5zeVKhUUDh6p15mp9s=; b=pi5ILndueVIRx9xr+MpIesJrkBmOC+XJ+A2ZYEnMYHYaIvAx8J3aeHzoSBTepjMgl+ QMmvTddxpJ/gmqRmmIa5zUpHluYpK+14vzE85lVNoPph/fTgyk0YLW3PPJtIyVNX5to6 1RcX2BGo9qUzg2ELHhOArbnQdiHu7CJMvVE5nFEz/AVGhx4pryoqbUULrqmg6aKXaP9K Ud0HLtU2PxAcGGfsK2dxrbVoc/dpUAXMcHqMcWTKBbE+22wWRvX1YlGQm6QTQQWZnawu tCFVbwaKsjr4Nt5/Dza6EPVDywbSFlwYpssvhpmbAAsf40oF7QBLLiuBdf4GdGAcYmr8 uH7A== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r18si13133200eds.390.2021.03.23.05.44.00; Tue, 23 Mar 2021 05:44:23 -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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231304AbhCWMmM (ORCPT + 99 others); Tue, 23 Mar 2021 08:42:12 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:14849 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbhCWMlz (ORCPT ); Tue, 23 Mar 2021 08:41:55 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4F4WCt0HgDz92nR; Tue, 23 Mar 2021 20:39:54 +0800 (CST) Received: from huawei.com (10.175.113.32) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.498.0; Tue, 23 Mar 2021 20:41:46 +0800 From: Liu Shixin To: Andrew Morton , Stephen Rothwell , Michal Hocko , Vlastimil Babka CC: , , Kefeng Wang , Liu Shixin Subject: [PATCH -next] mm, page_alloc: avoid page_to_pfn() in move_freepages() Date: Tue, 23 Mar 2021 21:12:15 +0800 Message-ID: <20210323131215.934472-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kefeng Wang The start_pfn and end_pfn are already available in move_freepages_block(), there is no need to go back and forth between page and pfn in move_freepages and move_freepages_block, and pfn_valid_within() should validate pfn first before touching the page. Signed-off-by: Kefeng Wang Signed-off-by: Liu Shixin --- mm/page_alloc.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c53fe4fa10bf..ccfaa8158862 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2425,19 +2425,21 @@ static inline struct page *__rmqueue_cma_fallback(struct zone *zone, * boundary. If alignment is required, use move_freepages_block() */ static int move_freepages(struct zone *zone, - struct page *start_page, struct page *end_page, + unsigned long start_pfn, unsigned long end_pfn, int migratetype, int *num_movable) { struct page *page; + unsigned long pfn; unsigned int order; int pages_moved = 0; - for (page = start_page; page <= end_page;) { - if (!pfn_valid_within(page_to_pfn(page))) { - page++; + for (pfn = start_pfn; pfn <= end_pfn;) { + if (!pfn_valid_within(pfn)) { + pfn++; continue; } + page = pfn_to_page(pfn); if (!PageBuddy(page)) { /* * We assume that pages that could be isolated for @@ -2447,8 +2449,7 @@ static int move_freepages(struct zone *zone, if (num_movable && (PageLRU(page) || __PageMovable(page))) (*num_movable)++; - - page++; + pfn++; continue; } @@ -2458,7 +2459,7 @@ static int move_freepages(struct zone *zone, order = buddy_order(page); move_to_free_list(page, zone, order, migratetype); - page += 1 << order; + pfn += 1 << order; pages_moved += 1 << order; } @@ -2468,25 +2469,22 @@ static int move_freepages(struct zone *zone, int move_freepages_block(struct zone *zone, struct page *page, int migratetype, int *num_movable) { - unsigned long start_pfn, end_pfn; - struct page *start_page, *end_page; + unsigned long start_pfn, end_pfn, pfn; if (num_movable) *num_movable = 0; - start_pfn = page_to_pfn(page); - start_pfn = start_pfn & ~(pageblock_nr_pages-1); - start_page = pfn_to_page(start_pfn); - end_page = start_page + pageblock_nr_pages - 1; + pfn = page_to_pfn(page); + start_pfn = pfn & ~(pageblock_nr_pages - 1); end_pfn = start_pfn + pageblock_nr_pages - 1; /* Do not cross zone boundaries */ if (!zone_spans_pfn(zone, start_pfn)) - start_page = page; + start_pfn = pfn; if (!zone_spans_pfn(zone, end_pfn)) return 0; - return move_freepages(zone, start_page, end_page, migratetype, + return move_freepages(zone, start_pfn, end_pfn, migratetype, num_movable); } -- 2.25.1