From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-135.mta1.migadu.com [95.215.58.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EB32259498 for ; Mon, 24 Aug 2026 11:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787570331; cv=none; b=Y/WG1lzILNINhjmys4KEmGNUBeLFgmPWAaEw0Sv4aT6B8sBQFZFKJ7vOCiwn3dCm7zbN/CMOicMig410YjoKUW1FHauHZdS9mBXevZ/7xSWTPLsJPkEJKP++s9nIT8Lte+IZNCSRsRMCpwm/aeM5zT20gyk2lGmQwgIlGqdKzCE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787570331; c=relaxed/simple; bh=32itMfmpMIT+qkqntr949fZUt3gdG2/oFwkIwIa+FkI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=r55hoTY18y2ET4LyJjjfcvQlZSiVLCe3z1UYBzkyu3WkXZYkMuNe5wyzEKQy4ZJrQJPutbaXpJ0URye6AWVwkQEYKsqxprXPBUnkapP7qNcgPp96US1Gl00i0Q2CSR5VFV1INsdmcjt4MiGgLHYiIMTn/dUHMHZff85MGLfJ/oc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=GoJC1by9; arc=none smtp.client-ip=95.215.58.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="GoJC1by9" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=32itMfmpMIT+qkqntr949fZUt3gdG2/oFwkIwIa+FkI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787570326; v=1; x=1788175126; b=GoJC1by9GxLQ910MDvdF1Cr8YH/Gh1/AKhTNFnn6Ldo3blWD0YZQDs22W5gc08Mh/030dLYh sxTNa2gDBv5sud6PAoeim5ilnVj22wpGK7olGAd4N1EyjPg5LbeQkvZXcs/AA/MPQGs3kgMD2U0 0TIKDqqypQQgqImrQCpC7LhA= X-Envelope-To: linux-kernel@vger.kernel.org Received: from [10.67.158.60] (114.251.196.104) by smtp.migadu.com with ESMTPS id 0250bd41515bb170; Mon, 24 Aug 2026 11:18:46 +0000 X-Mizu-Trace-ID: 0250bd41515bb170 X-Migadu-Flow: FLOW_OUT Message-ID: <42b6e1b4-96ed-4364-a502-369b4a96705b@linux.dev> Date: Mon, 24 Aug 2026 19:18:37 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 03/17] mm/mm_init: skip initializing shared vmemmap tail pages To: Mike Rapoport Cc: Andrew Morton , Oscar Salvador , David Hildenbrand , Vlastimil Babka , Lorenzo Stoakes , Michal Hocko , David Laight , "Liam R . Howlett" , Suren Baghdasaryan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song References: <20260819095140.17252-1-songmuchun@bytedance.com> <20260819095140.17252-4-songmuchun@bytedance.com> <178756196748.3606540.14377746709923091802.b4-review@b4> Content-Language: en-US From: Muchun Song In-Reply-To: <178756196748.3606540.14377746709923091802.b4-review@b4> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026/8/24 16:59, Mike Rapoport wrote: >> memmap_init_range() initializes every struct page in the target range. >> For compound pages with vmemmap optimization, the tail struct pages are >> backed by a shared vmemmap page. >> >> Initializing those tail struct pages would overwrite the shared >> vmemmap page contents, requiring users such as HugeTLB to restore the >> metadata afterwards. >> >> Track the compound order for HVO-backed sections and use that metadata >> to detect struct pages that fall into the shared tail vmemmap range. >> Skip those shared tail pages in memmap_init_range(), then initialize >> pageblock migratetypes for the processed range with a helper after the >> per-page initialization loop. >> >> Keep direct mem_section access inside sparse helpers by exposing >> pfn_to_section_order() to users that only need the order associated with >> a PFN. This lets memmap_init_range() skip shared tail vmemmap pages >> without exposing __pfn_to_section() to !SPARSEMEM builds. >> >> This is a preparatory change for consolidating handling across users of >> vmemmap optimization, and it also avoids redundant initialization of >> shared tail vmemmap pages during early boot. >> >> Signed-off-by: Muchun Song >> >> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h >> index 5fb9b37819d5..df31cac12311 100644 >> --- a/include/linux/mmzone.h >> +++ b/include/linux/mmzone.h >> @@ -2022,6 +2022,14 @@ struct mem_section { >> unsigned long section_mem_map; >> >> struct mem_section_usage *usage; >> +#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP >> + /* >> + * Normally, sections hold regular (order-0) pages. However, for >> + * sections with HVO enabled, this tracks the compound page order >> + * to enable deduplication of redundant vmemmap pages. >> + */ >> + unsigned int order; >> +#endif >> #ifdef CONFIG_PAGE_EXTENSION >> /* >> * If SPARSEMEM, pgdat doesn't have page_ext pointer. We use >> diff --git a/mm/mm_init.c b/mm/mm_init.c >> index 1533aebafb68..05c09e755e0b 100644 >> --- a/mm/mm_init.c >> +++ b/mm/mm_init.c >> @@ -29,6 +29,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -677,21 +678,19 @@ static inline void fixup_hashdist(void) >> static inline void fixup_hashdist(void) {} >> #endif /* CONFIG_NUMA */ >> >> -#if defined(CONFIG_ZONE_DEVICE) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT) >> static __meminit void pageblock_migratetype_init_range(unsigned long pfn, >> - unsigned long nr_pages, int migratetype, bool atomic) >> + unsigned long nr_pages, int migratetype, bool isolate, bool atomic) > Growing boolean flags makes the callsites harder to read. > One way to deal with it is to add comments to the callers saying what > each true and false mean. Make sense. > >> { >> const unsigned long end = pfn + nr_pages; >> >> for (pfn = pageblock_align(pfn); pfn < end; pfn += pageblock_nr_pages) { >> enum migratetype mt = kho_scratch_migratetype(pfn, migratetype); >> >> - init_pageblock_migratetype(pfn_to_page(pfn), mt, false); >> - if (!atomic && IS_ALIGNED(pfn, PAGES_PER_SECTION)) >> + init_pageblock_migratetype(pfn_to_page(pfn), mt, isolate); >> + if (!atomic && IS_ALIGNED(pfn, PFN_DOWN(SZ_1G))) >> cond_resched(); >> } >> } >> -#endif >> >> #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT >> static inline void pgdat_set_deferred_range(pg_data_t *pgdat) >> @@ -886,6 +885,13 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone >> } >> } >> >> + if (vmemmap_optimizable_pfn(pfn)) { > A short comment above would be nice :) No problem. Thanks for your review. Muchun, Thanks.