From mboxrd@z Thu Jan 1 00:00:00 1970 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 3140EC7618E for ; Mon, 24 Apr 2023 14:47:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C55E6B0071; Mon, 24 Apr 2023 10:47:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74D786B0074; Mon, 24 Apr 2023 10:47:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EE3E6B0075; Mon, 24 Apr 2023 10:47:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 49CDA6B0071 for ; Mon, 24 Apr 2023 10:47:55 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 011D0AC565 for ; Mon, 24 Apr 2023 14:47:54 +0000 (UTC) X-FDA: 80716564110.23.8BCBFF7 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf11.hostedemail.com (Postfix) with ESMTP id E140B40022 for ; Mon, 24 Apr 2023 14:47:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=tDVTM+Y0; spf=pass (imf11.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682347672; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EguKY0cZkMrWGDpyRY3VFx21djInsbc1dIZ4hVv8EFY=; b=yDQfaKIlvPiyIhss5XNs62RQaOV+C2wMVe2Xb8tPXZ9XDav0jIxM38ufQhi+F+td19a6YS 4+h3JMkMM9jsKvhPhIVwa4WxyhIg9uSt/wCQeqykmq7bly1vmJbi3Dkj5nN2N2aa0inr1K WnhzoCMA7htDFA5LpFNSUrnKNaVfgPw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682347672; a=rsa-sha256; cv=none; b=mE1gce4k/lcikwUM96xOVUBpYDUmyXXjfS/sq3L3+rzdtt4BnpzuJBGFbkfALtz46m/bE0 mKKB7jhpJR6xvnf1yCKbQUjWP8/MYa8QXwWE/J7EzuBHx239BleMly+DIAo74lk2/ugoXN mUkMuWAn7AeHmPUYhV1ZJjNkydb8kRc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=tDVTM+Y0; spf=pass (imf11.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 84FF521A79; Mon, 24 Apr 2023 14:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682347670; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EguKY0cZkMrWGDpyRY3VFx21djInsbc1dIZ4hVv8EFY=; b=tDVTM+Y0Ku93kVfp41sWODCyjfiJELTwbHKXXk71xwzQbDIjzQ93oVmk2UDwEELuUhXYuL mjo3dmHGoeyyqetHmuEQATcarlO7LSJyr19J3q/uYzDMrI080elHambvdLgQms2l5eqkmI aJE5FqMq4TMc/4g16jncNzibKW0DKrs= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5EE8F1390E; Mon, 24 Apr 2023 14:47:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CilcFJaWRmQCTAAAMHmgww (envelope-from ); Mon, 24 Apr 2023 14:47:50 +0000 Date: Mon, 24 Apr 2023 16:47:49 +0200 From: Michal Hocko To: Baolin Wang Cc: akpm@linux-foundation.org, rppt@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, vbabka@suse.cz, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] mm/page_alloc: add some comments to explain the possible hole in __pageblock_pfn_to_page() Message-ID: References: <50b5e05dbb007e3a969ac946bc9ee0b2b77b185f.1682342634.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50b5e05dbb007e3a969ac946bc9ee0b2b77b185f.1682342634.git.baolin.wang@linux.alibaba.com> X-Rspam-User: X-Rspamd-Queue-Id: E140B40022 X-Rspamd-Server: rspam09 X-Stat-Signature: mhrbt7emxd6e68zbrajoi87x45zpi4re X-HE-Tag: 1682347671-741071 X-HE-Meta: U2FsdGVkX1/Q2K1U+kV+hIrT3ZQDJoL8E9/8kXm1vNkv9TdiPouniONjPG+d4khNrpKyFscV6V/mApnrFgfaMiDz1euKIZSxODBhdEp0PBAw6ep0cZxwl8b+PjHLOkdxyW8zaKUaVkPW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hTpekhXdxhJhugh0/wbK/uTnpSTKhT9iMMU6B62ryMPesYRwX7eDig1sAP9SNnFe2cOunbbfK9rqNOapkeE2YZu1cfxK27IHQedwciS7td6Y+XUaiVpIqDDcBQ2Lu+dzHByWiRUFUc5gwXrE1f4xKNE/vLKHqM7uzxSqo5O0vwTHBuhyIbXQmIaIIDlo/+hPgsOaCQc= 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: On Mon 24-04-23 21:45:40, Baolin Wang wrote: > Now the __pageblock_pfn_to_page() is used by set_zone_contiguous(), which > checks whether the given zone contains holes, and uses pfn_to_online_page() > to validate if the start pfn is online and valid, as well as using pfn_valid() > to validate the end pfn. > > However, the __pageblock_pfn_to_page() function may return non-NULL even > if the end pfn of a pageblock is in a memory hole in some situations. For > example, if the pageblock order is MAX_ORDER, which will fall into 2 > sub-sections, and the end pfn of the pageblock may be hole even though > the start pfn is online and valid. > > See below memory layout as an example and suppose the pageblock order > is MAX_ORDER. > > [ 0.000000] Zone ranges: > [ 0.000000] DMA [mem 0x0000000040000000-0x00000000ffffffff] > [ 0.000000] DMA32 empty > [ 0.000000] Normal [mem 0x0000000100000000-0x0000001fa7ffffff] > [ 0.000000] Movable zone start for each node > [ 0.000000] Early memory node ranges > [ 0.000000] node 0: [mem 0x0000000040000000-0x0000001fa3c7ffff] > [ 0.000000] node 0: [mem 0x0000001fa3c80000-0x0000001fa3ffffff] > [ 0.000000] node 0: [mem 0x0000001fa4000000-0x0000001fa402ffff] > [ 0.000000] node 0: [mem 0x0000001fa4030000-0x0000001fa40effff] > [ 0.000000] node 0: [mem 0x0000001fa40f0000-0x0000001fa73cffff] > [ 0.000000] node 0: [mem 0x0000001fa73d0000-0x0000001fa745ffff] > [ 0.000000] node 0: [mem 0x0000001fa7460000-0x0000001fa746ffff] > [ 0.000000] node 0: [mem 0x0000001fa7470000-0x0000001fa758ffff] > [ 0.000000] node 0: [mem 0x0000001fa7590000-0x0000001fa7dfffff] > > Focus on the last memory range, and there is a hole for the range [mem > 0x0000001fa7590000-0x0000001fa7dfffff]. That means the last pageblock > will contain the range from 0x1fa7c00000 to 0x1fa7ffffff, since the > pageblock must be 4M aligned. And in this pageblock, these pfns will > fall into 2 sub-section (the sub-section size is 2M aligned). > > So, the 1st sub-section (indicates pfn range: 0x1fa7c00000 - > 0x1fa7dfffff ) in this pageblock is valid by calling subsection_map_init() > in free_area_init(), but the 2nd sub-section (indicates pfn range: > 0x1fa7e00000 - 0x1fa7ffffff ) in this pageblock is not valid. > > This did not break anything until now, but the zone continuous is fragile > in this possible scenario. So as previous discussion[1], it is better to > add some comments to explain this possible issue in case there are some > future pfn walkers that rely on this. > > [1] https://lore.kernel.org/all/87r0sdsmr6.fsf@yhuang6-desk2.ccr.corp.intel.com/ > > Signed-off-by: Baolin Wang Acked-by: Michal Hocko > --- > Changes from v2: > - Update the commit log and comments per Michal, thanks. > Changes from v1: > - Update the comments per Ying and Mike, thanks. > > Note, I did not add Huang Ying's reviewed tag, since there are some > updates per Michal's suggestion. Ying, please review the v3. Thanks. > --- > mm/page_alloc.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 6457b64fe562..bd124390c79b 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -1502,6 +1502,15 @@ void __free_pages_core(struct page *page, unsigned int order) > * interleaving within a single pageblock. It is therefore sufficient to check > * the first and last page of a pageblock and avoid checking each individual > * page in a pageblock. > + * > + * Note: the function may return non-NULL struct page even for a page block > + * which contains a memory hole (i.e. there is no physical memory for a subset > + * of the pfn range). For example, if the pageblock order is MAX_ORDER, which > + * will fall into 2 sub-sections, and the end pfn of the pageblock may be hole > + * even though the start pfn is online and valid. This should be safe most of > + * the time because struct pages are still zero pre-filled and pfn walkers > + * shouldn't touch any physical memory range for which they do not recognize > + * any specific metadata in struct pages. > */ > struct page *__pageblock_pfn_to_page(unsigned long start_pfn, > unsigned long end_pfn, struct zone *zone) > -- > 2.27.0 -- Michal Hocko SUSE Labs