From patchwork Wed Apr 12 10:45:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13208787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3BD7C77B6E for ; Wed, 12 Apr 2023 11:02:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E6F6B0074; Wed, 12 Apr 2023 07:02:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1F256B0075; Wed, 12 Apr 2023 07:02:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5B14900002; Wed, 12 Apr 2023 07:02:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B99886B0074 for ; Wed, 12 Apr 2023 07:02:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 15C601A5561 for ; Wed, 12 Apr 2023 10:45:48 +0000 (UTC) X-FDA: 80672408376.09.3A78591 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf05.hostedemail.com (Postfix) with ESMTP id D4819100027 for ; Wed, 12 Apr 2023 10:45:44 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf05.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681296346; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=AMR5YGRm8ecpN8KXEf5iglgHINtqICbGJBaMFigm/fU=; b=VkYLaRaRgdYxQLDPShHAuoSYho4hFKikfVWIij6GFR2X1lNKtCYYX6hjFlSFzC21IlOF4+ kMYm3a5xyejXo6qn4UN5uS2TtzmUfoxfwPmpVyDb3wFjpbasjPuFSBWJB1bc556Elm24hk 8DNEOhFNXJkI9UB3h3CSfSnkvh5SYkA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf05.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681296346; a=rsa-sha256; cv=none; b=tY6hGyJuKGzwCBqqNk4Rb7yYui2sNRhbJ2mHqSO0nTKfQjRNVFitywxvrx5Xz85A6eT33x PQkGpx85o6fTRSkcJbNukTVYD4MYzMBFr6G2gPWGHc9qcJujeNg8q0LRihMKIZ7Pq+JeNQ WxZiSonHNyJx4rpF5SW1pQNo+rlThn4= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Vfw8Fy8_1681296340; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vfw8Fy8_1681296340) by smtp.aliyun-inc.com; Wed, 12 Apr 2023 18:45:41 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: mgorman@techsingularity.net, vbabka@suse.cz, mhocko@suse.com, david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/page_alloc: consider pfn holes after pfn_valid() in __pageblock_pfn_to_page() Date: Wed, 12 Apr 2023 18:45:31 +0800 Message-Id: <62e231a8f2e50c04dcadc7a0cfaa6dea5ce1ec05.1681296022.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: D4819100027 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: so4abexpfdwckmqhfzs5qnd8wydf7zpc X-HE-Tag: 1681296344-586347 X-HE-Meta: U2FsdGVkX192beLKtIfVqp4aGgdcEF6pARGO98L4quPDLcWUTmbEX4H3aMmkAUWk3qVraxXby8Kdw4/LqhUGf2EPLdqL4V2HlvIA8QsMthgQzArB3rFpNtC4n5VDnHL/eSURZl8lEgkyKrf+7mvMqB0P644z1n4nJVoob/rue8zlqwHYp/uqVFsfFE5M3Hf3OwKulWW5KPSqRByNdhrDv4PaVN/YwuxJD474dh9wtB3lL47Z7u0IWnyNFv/L5JJGcUz6u2X7FPdMUwScEnA2YhT1Bl5MKiq02s68XiKVsy3G95pDjX3zbjc24ouwZc/N3CP7RizGp+FtLMVTdGFBncdRjgZPXBfp8j58JogFhyDArvbySV5PsNscRwaW9CbI12HOxrab5VoSV+8I9IemPyCQvR4nOTSLgRuh8WMUqSnUXnYVG8S+di7zoz4W9DgU6QKcaBG5gYJt+hRs61NrC1OpLcRNTapi3XGOUV9aNx8wPtJyYDV/5eG1pfQ+6CdhAdhVo5AIFZ4ym7Ax9l1B1kA5tPKn4uWFWNaBB+46jjKqOwQawBok44Cl2WULqprL4+6aXU4e+5ANIHAF6X7eM3HGbMVXYNnfjnsw8ERq0nLjNOsWAX2CEcXXlfLP1Jm8qw2mKxssZR6B3p5bdzkvZiOmtbrJUh7tYfnqBh2jndio9gR7IMrSc9KdlQFwf3gfni374WzzIq6ii0SAXrbnNPwoW4SVGpGX3YnhIJx5dugi8nK1R8so+y1CS3Mfc//YFUyx0E26aqgnvlR+rqN1La1S+XPJc9E1eKkhdPc95rzEro2UOEv6s4e/UoQAbj0BVXgf4mJFP39mwjjWQfWwHcMNJFNDdN/7PWWCdgMdU4Iaij8WlA3dURryohlDoyI9Rs9QQKcIDbBRI0AWyiiTD4vJESgZvAu4N/qlnFLSLMp7oSqD0ND7AHz7r/10+idH2ReFlgvY3HQ6D3/cxSW O8K+EoDg hRd2OD964E6JFzyRYP7hgsitM6kMFUOfiQ6J+/kqw9T6xjIkzA/4xTap1DO8QW0mc5PEGVc7z0SwbGqMTvG2mSEqbDlyeBJa/rN18HE1AoQ2ZQuoIoHUXkWHrcNrz/F/o/JusqgqMO0I8POHXZOgTP/sC1kSzdmIW/+5V X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Now the __pageblock_pfn_to_page() is used by set_zone_contiguous(), which checks whether the given zone contains holes, and uses pfn_valid() to check if the end pfn is valid. However pfn_valid() can not make sure the end pfn is not a hole if the size of a pageblock is larger than the size of a sub-mem_section, since the struct page getting by pfn_to_page() may represent a hole or an unusable page frame, which may cause incorrect zone contiguous is set. Though another user of pageblock_pfn_to_page() in compaction seems work well now, it is better to avoid scanning or touching these offline pfns. So like commit 2d070eab2e82 ("mm: consider zone which is not fully populated to have holes"), we should also use pfn_to_online_page() for the end pfn to make sure it is a valid pfn with usable page frame. Meanwhile the pfn_valid() for end pfn can be dropped now. Moreover we've already used pfn_to_online_page() for start pfn to make sure it is online and valid, so the pfn_valid() for the start pfn is unnecessary, drop it. Signed-off-by: Baolin Wang --- mm/page_alloc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d0eb280ec7e4..8076f519c572 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1512,9 +1512,6 @@ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, /* end_pfn is one past the range we are checking */ end_pfn--; - if (!pfn_valid(start_pfn) || !pfn_valid(end_pfn)) - return NULL; - start_page = pfn_to_online_page(start_pfn); if (!start_page) return NULL; @@ -1522,7 +1519,9 @@ struct page *__pageblock_pfn_to_page(unsigned long start_pfn, if (page_zone(start_page) != zone) return NULL; - end_page = pfn_to_page(end_pfn); + end_page = pfn_to_online_page(end_pfn); + if (!end_page) + return NULL; /* This gives a shorter code than deriving page_zone(end_page) */ if (page_zone_id(start_page) != page_zone_id(end_page))