Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3678980pxf; Mon, 29 Mar 2021 08:32:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgQdjnG0OkcycixCWqcUSCjhkvZHuyoDZTOcZXuPMNwNACrZNC8Mp7FVZbjvoAlSNulhSF X-Received: by 2002:a05:6402:2d0:: with SMTP id b16mr29676599edx.194.1617031978052; Mon, 29 Mar 2021 08:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617031978; cv=none; d=google.com; s=arc-20160816; b=bBrepSxFGD0aQOPbaBZv7jKcqkqC2YlLcW0DjPOwmFd9UjaXdbGWuRN4sJnPUxRI6Q GQq0HMJJhVUJV4oghUAEBM7vbEGaM6S32sxBoyVMK0ysKaL8C+0yia88Iuj87JG6C8Qz 0h7tyX8PKvXOtjIpBc1IEbHlN5BWHm9Xx0z1llZOJEiGnViiBrJMcnQbN8jd3iEc/P2r fg33aUipSBxP4UPfHvU1kgkGMQZF+7f54br4RBiVgYQX8z/MuYdHguzn8AyGpIIGRwws QppOZwPwDr7LgvePd3Cuw6C3RRhhRe4U0TsdQvo2OBFcD/IK1eKPpWc6Am95w0BOdKon d5HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=EnLxo5vNaG7dc7Ux90Em9pBpn47itg9uLSyGbLNQuqU=; b=zgQG/y+GlwZAto+L+il4+bFckhU9SqA0N4LYOn+4O1PY4XALKbxCugyski40yf7xor Xd9UptGygJL3QwCOIKi5PKqItmmmU41zo+NfFe6eJAsuV5Ggp4WxO6h/7YKPEOvW9EjR vgk9n/qFZU15P/rAzJCvEee6k1Q9ZQFLfRi3eLY5viPvZypTZGMyTYVWgXarVagEbZgW slQwTP3k9T7mgZoGGGR4b0c7n5tqL8HeOe/jEZhHiSpJlCWzNTpxoJQU1iAiPgEfqoxE fBoU1Dd2CfI3/0GkOs0Z6Mkay2jJLddWlo/DgBSbI4DR3MTT6za96Hu7wX7XzVU/jHNy ANuQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si13378939ejb.608.2021.03.29.08.32.35; Mon, 29 Mar 2021 08:32:58 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbhC2Pbb (ORCPT + 99 others); Mon, 29 Mar 2021 11:31:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:56882 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbhC2PbL (ORCPT ); Mon, 29 Mar 2021 11:31:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 57CD5AFF6; Mon, 29 Mar 2021 15:31:10 +0000 (UTC) Subject: Re: [PATCH -next] mm, page_alloc: avoid page_to_pfn() in move_freepages() To: Liu Shixin , Andrew Morton , Stephen Rothwell , Michal Hocko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kefeng Wang References: <20210323131215.934472-1-liushixin2@huawei.com> From: Vlastimil Babka Message-ID: <33e6c72e-5479-e503-99ec-5025fafd46f6@suse.cz> Date: Mon, 29 Mar 2021 17:31:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210323131215.934472-1-liushixin2@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/23/21 2:12 PM, 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. > > Signed-off-by: Kefeng Wang > Signed-off-by: Liu Shixin Acked-by: Vlastimil Babka Agreed with Matthew's suggestion, also: > @@ -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); Since you touch this already, consider pageblock_start_pfn() > end_pfn = start_pfn + pageblock_nr_pages - 1; I'd also drop the "- 1" here and instead adjust the for loop's ending condition from "pfn <= end_pfn" to "pfn < end_pfn" as that's more common way of doing it. Thanks. > > /* 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); > } > >