Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4254527pxf; Tue, 23 Mar 2021 06:39:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRjawqa8r8ZgJVHojUy2Ga4g21lqPOOFHPIiVuCm7wno/M14NrD4h2jxxejsmb6fAALslL X-Received: by 2002:a17:906:1c98:: with SMTP id g24mr5009650ejh.51.1616506762653; Tue, 23 Mar 2021 06:39:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616506762; cv=none; d=google.com; s=arc-20160816; b=qhiqDE6R62PbMljUfYohpQLmrRfOX/qdTjZBsEfKjTrfinimW5FCSjF2FC5T94muZ2 m/2r5P70ZsCcjWBwifrxQdrjMmOB1UDoZD2rknxxFTZFbY2nU6L7UCNP8x3uumcldDn/ HEOyEOz7MhWR/NjijPdwPTPiOCQz+zXFISr8QPT8t2lBmNF0Wc1qjPwNjhyCL/a7Udt+ ywmIykVkGaHMWs/v9TG2neByzyRz+APVhYPzMj8A0SUnMrkdjqs7EHAXJEf3rpOUcnT/ h3urt0zDmlq9Xmc6gv409VycQTF3JgS2fcWsvL9h1JlypywzEuXApE+W9d+g8fS8fQx3 5bew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LTQEMCkZdiBXrLcpX0fP9V/zBXP3nEkqVdlVQQ2MTjE=; b=SqBcIOKd9HzC96N8n7pkLGDWn3mPYhLRodK3FGA14x+WiHbjcnxnfWc+oHITgmc6fX Xr0/F0xJz2CLiqtvUdQRLScI9L+QB+FQLHgCfWCAyAhAOojIacCI2nBj1mqhn7ig8Fmi DjCsNqU26Fai0pQcQyaRUkNlwboT8XRdr1jWKOwguOHhJ8HsS/IHSv7gHZtjBuOiy865 9/a9GyOfkv+03FMsbLZI8lJQM0xqGixieDoVILzvYhMKUy6vcBM9HwfGN+UrtLZZH90t alrF2Tx0oKbE02PEdV7chd9UYbIqB1MAX8f4SYz639xJpFm/J+cloRVAToc89CtXrAA3 Lcjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=FZGahySo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b26si13153635edx.214.2021.03.23.06.39.00; Tue, 23 Mar 2021 06:39:22 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=FZGahySo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231379AbhCWMzh (ORCPT + 99 others); Tue, 23 Mar 2021 08:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231387AbhCWMzJ (ORCPT ); Tue, 23 Mar 2021 08:55:09 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 675B6C061574 for ; Tue, 23 Mar 2021 05:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LTQEMCkZdiBXrLcpX0fP9V/zBXP3nEkqVdlVQQ2MTjE=; b=FZGahySoelD/j9c7Bm8wddQJGw 966+pphwKL3Tb3ETkw+oHfZDIyvpPNhRmwp90/cdsi0oDR/kRWB01pDYErZrv3FfPlGvJz1vMsiRH KopKbMyhZz9dGtIyGKu1aYtLKlC43KXE071VFy9imHYz6N/ZFw6bj7DPPEoYRRoMGDr3H+fGLRc1P bnAGh652qFU2WTRx5OYrkT+CW61CcLgYTQIswre6cmXut4XMDhLi4nd9nnl8vQU7BE2tigkjiACQg tGvvXQWOaU8g5Wpr1GkxGgtPIuNHmUSON6w12ink243xND2t6arvNm5s9GzvYrHq65FJWQPcGd+eI oOVwuIRQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lOgXo-00A4AJ-Lf; Tue, 23 Mar 2021 12:54:10 +0000 Date: Tue, 23 Mar 2021 12:54:00 +0000 From: Matthew Wilcox To: Liu Shixin Cc: Andrew Morton , Stephen Rothwell , Michal Hocko , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kefeng Wang Subject: Re: [PATCH -next] mm, page_alloc: avoid page_to_pfn() in move_freepages() Message-ID: <20210323125400.GE1719932@casper.infradead.org> References: <20210323131215.934472-1-liushixin2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210323131215.934472-1-liushixin2@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?