From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52B57261B9E for ; Thu, 9 Jul 2026 13:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783603514; cv=none; b=qj7E9zcxm048Cw2xxql/Wh9na0fu8qZ4DVllmYcBlffkfD/BpeKTc9y5gHF210PyZdIoRFwwGg2p5DqBZB1nEB7WSv2EzGJpGQAJNPoYs26H0xocJZjVhLBtjGiSClXzbTXgoJsPAkk9iEfRC/wjU9TAOE+7umWIui3RV+yqwvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783603514; c=relaxed/simple; bh=ofamMzeEY607upDpjZrvcv5ePn02h3IKq0BKgtPg+sE=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=hm4IVNvuTx4034fInuuJVbygmd4Zew/ajDg4fyznkotmgT76XUJpOfjbmT7v3HKhzt/FG1Aco4TtUU2AkLWD+rkkeyFg/fPSzaM9h8Ht0jV6AZm9XEsra5Ik+i9ln5KyT5m+CiSLsYk04754QaOOhcopRdvG2iInOMjOWwXUVXE= 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=QSXGGM3n; arc=none smtp.client-ip=91.218.175.172 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="QSXGGM3n" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783603510; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sO9G8F5VULeMEdh5I5+DwqvlznbD42nz7nqrLE6HRog=; b=QSXGGM3nkI6u+O+hECi0uUyevg1hNCWwlHV/ZG8B8g1RP8JtVFpnPfnZgITfiekwEaBx3k eDLeqc/jxdcIiy4W1sQizWiCk7QTeub1WuZAQRrrBWHlLCdsxzIPlWx7Vtjg9woy2gO7Q6 KrRRL8ORecsEtRjMEEnT8HeDOWUyHf8= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: [PATCH 04/17] mm/mm_init: skip initializing shared vmemmap tail pages X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: Date: Thu, 9 Jul 2026 21:23:47 +0800 Cc: Muchun Song , Andrew Morton , Oscar Salvador , David Hildenbrand , linux-mm@kvack.org, Vlastimil Babka , Lorenzo Stoakes , Michal Hocko , linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260702093821.2740183-1-songmuchun@bytedance.com> <20260702093821.2740183-5-songmuchun@bytedance.com> <2306829C-A66D-41F2-B5F7-1C164A7FF757@linux.dev> To: Mike Rapoport X-Migadu-Flow: FLOW_OUT > On Jul 9, 2026, at 21:05, Mike Rapoport wrote: >=20 > On Thu, Jul 09, 2026 at 08:31:31PM +0800, Muchun Song wrote: >>> On Jul 9, 2026, at 18:45, Mike Rapoport wrote: >>> On Thu, Jul 02, 2026 at 05:38:08PM +0800, Muchun Song 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. >>>>=20 >>>> Initializing those tail struct pages would overwrite the shared >>>> vmemmap page contents, so users such as HugeTLB have to open-code >>>> follow-up handling to restore the metadata afterwards. >>>>=20 >>>> Use the section's compound page order to detect struct pages that = fall >>>> into the shared tail vmemmap range and skip their initialization in >>>> memmap_init_range(). Still initialize the pageblock migratetypes = for >>>> the skipped range so the surrounding setup remains intact. >>>>=20 >>>> 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. >>>>=20 >>>> Signed-off-by: Muchun Song >>>> --- >>>> include/linux/mmzone.h | 4 ++++ >>>> mm/internal.h | 16 ++++++++++++++++ >>>> mm/mm_init.c | 25 +++++++++++++++++++------ >>>> 3 files changed, 39 insertions(+), 6 deletions(-) >>>>=20 >>>> @@ -673,19 +673,21 @@ static inline void fixup_hashdist(void) >>>> static inline void fixup_hashdist(void) {} >>>> #endif /* CONFIG_NUMA */ >>>>=20 >>>> -#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) >>>=20 >>> What is isolate parameter for? >>=20 >> I've re-examined the code, and you're right that the isolate = parameter is technically >> redundant for our current use case, as memmap_init_zone_range() = passes false. >>=20 >> The rationale behind keeping it is future-proofing. The ultimate goal = of a generic >> HVO is to support arbitrary huge pages, not just HugeTLB. I decoupled = this as a >> parameter to prevent potential regressions down the road; if a = developer leverages >> this for other huge page types in the future, they won't = inadvertently break >> things by forgetting to update a hardcoded false in = init_pageblock_migratetype(), >> especially since memmap_init_range() natively accepts an isolate = parameter. >>=20 >> Of course, we could also just delete this parameter for now and add = it back later if >> needed. I think both approaches work. >>=20 >> Which way are you leaning? >=20 > I'd drop it for now and would revisit when there would be a new HVO = user.=20 > Even one boolean means it's hard to tell from a call site what is the > intention of the flag, two make it completely confusing :) No problem. I'll drop it next version. Muchun, Thanks. >=20 >>>> { >>>> const unsigned long end =3D pfn + nr_pages; >>>>=20 >>>> for (pfn =3D pageblock_align(pfn); pfn < end; pfn +=3D = pageblock_nr_pages) { >>>> - init_pageblock_migratetype(pfn_to_page(pfn), migratetype, false); >>>> + init_pageblock_migratetype(pfn_to_page(pfn), migratetype, = isolate); >>>> +#ifdef CONFIG_SPARSEMEM >>>> if (!atomic && IS_ALIGNED(pfn, PAGES_PER_SECTION)) >>>> +#else >>>> + if (!atomic && IS_ALIGNED(pfn, MAX_FOLIO_NR_PAGES)) >>>> +#endif >>>=20 >>> Let's trigger cond_resched() on some defined number of iterations or = some >>> memory size chunk, e.g PAGES_PER_128M or even PAGES_PER_1G. >>=20 >> Yes, that's for the best. I was really struggling to choose a = suitable macro >> for this earlier, but I realized it's a difficult thing to get right. = I'm leaning >> toward selecting PAGES_PER_1G instead. >=20 > Yeah, PAGES_PER_1G makes sense to me too. >=20 >> Muchun, >> Thanks. >>=20 >>>=20 >>>> cond_resched(); >=20 > --=20 > Sincerely yours, > Mike.