Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1932348pxf; Fri, 26 Mar 2021 20:38:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPj/+oqywZl93++zg2/XudnLAasg8RRJvY9vQDoCjho6Ar0tMZZ5946F+fAFj/BWyzXJ1W X-Received: by 2002:a17:906:8807:: with SMTP id zh7mr18432459ejb.196.1616816288166; Fri, 26 Mar 2021 20:38:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616816288; cv=none; d=google.com; s=arc-20160816; b=HKtnXJy2eIxLhtC3e/d8hkInfkZUFrQXT91LvUQMxy1ZN6K7CDwLPNVmK0IDpvp6NB SamNtza2sZlDJnZ+0T36yFqGRO4VGIYjixk2/SdlljhtHgyqmLYehll5viFvPITAZEJ3 EQlsne8/c+j+fmp5XPM9RlmqEiJ0KTgUolaKOIIlyzJUoW+tOgPz+1pUEzuoAViIcTKE 65hiRvnMFMyqJ1Kwva2CE5IfNJnh2wy7I0sXK34fXIVULkaeHbdtWDx+Gre+eF5P621t +5l7eLo4bGBrspqMgG7HNl3yGdSK3iN336Qw3XJZ3wIUnoPLZI1Gpt8tVIux4SrPom+5 tAuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=fSKfZZOA4BumtmYZT6ARKekIpzI69FF44AJCzJo/HAQ=; b=Qh8kVVTReI8IlHFM1JRkx88WW9RMyg7lPF2Amp0UAMI/zmgQN+hIwcViI9by33k8Bs 2F0fUKxUOgIF1IUfr8s681XcUKhL+NvD/1JCyLOluTBs0T0G22AmKOhpzmrtTthyF9jG FXttvCss+h54aL5ncT630CeRcfybjubpNUQGRr4GvHxKSBzu0nJC7npojv3n6wlmeUiW BrfyYyxt/PqBH+w0yWb99g88eOViNkXNWoGpmFQ+XMNdPLUX5ciHCgNHuKhWMgOz5To6 FtSD4iWyUwFRrO2fHx9DZeWYJ4fCC/ui689k63KrrMrSs8FtLbLpadMxAL98pPzQU439 2eww== 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 dm20si9167722edb.28.2021.03.26.20.37.45; Fri, 26 Mar 2021 20:38:08 -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 S230150AbhC0Dee (ORCPT + 99 others); Fri, 26 Mar 2021 23:34:34 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:14495 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbhC0DeQ (ORCPT ); Fri, 26 Mar 2021 23:34:16 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4F6kt401MkzySBp; Sat, 27 Mar 2021 11:32:12 +0800 (CST) Received: from [10.174.177.208] (10.174.177.208) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Sat, 27 Mar 2021 11:34:05 +0800 Subject: Re: [PATCH -next] mm, page_alloc: avoid page_to_pfn() in move_freepages() To: Matthew Wilcox References: <20210323131215.934472-1-liushixin2@huawei.com> <20210323125400.GE1719932@casper.infradead.org> CC: Andrew Morton , Stephen Rothwell , Michal Hocko , Vlastimil Babka , , , Kefeng Wang From: Liu Shixin Message-ID: Date: Sat, 27 Mar 2021 11:34:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20210323125400.GE1719932@casper.infradead.org> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.208] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry to reply to you after a so long time and thanks for your advice. It does seem that your proposed change will make the code cleaner and more efficient. I repeated move_freepages_block() 2000000 times on the VM and counted jiffies. The average value before and after the change was both about 12,000. I think it's probably because I'm using the Sparse Memory Model, so pfn_to_page() is not time-consuming. On 2021/3/23 20:54, Matthew Wilcox wrote: > On Tue, Mar 23, 2021 at 09:12:15PM +0800, Liu Shixin wrote: >> 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. > This looks good to me: > > Reviewed-by: Matthew Wilcox (Oracle) > >> 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); > I wonder if this wouldn't be even better if we did: > > struct page *start_page = pfn_to_page(start_pfn); > > for (pfn = start_pfn; pfn <= end_pfn; pfn++) { > struct page *page = start_page + pfn - start_pfn; > > if (!pfn_valid_within(pfn)) > continue; > >> - >> - page++; >> + pfn++; >> continue; > ... then we can drop the increment of pfn here > >> } >> >> @@ -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; > ... and change this to pfn += (1 << order) - 1; > > Do you have any numbers to quantify the benefit of this change? > . >