From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 11EB12110E for ; Thu, 16 Apr 2026 02:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776305212; cv=none; b=a0TaZ2Vh7Tpz/NmTw84My3szJQyMxab3CoNVu2DoJer8cOPhMWk+0bAek+lV59jl9vLPm5tmyLGKaU/B6AOJC92pt8tNK4O76vwQQbRUOypr9Cv7UeynwHmLpv9Xlx1JDV3pSGD2U4+uDjB03WQUbpE+dt689PkSx4hBAOu9A0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776305212; c=relaxed/simple; bh=4MpxFeUo23JV904uYzFKRObUJT6fpoQmhALG/M7ARGE=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=spuntlEEsm1VW9QhnOjLLixG7bejUYTAbEUAOtfVco9gXGoueeZEDGAcgV+AoGFJQCgTL52jr0e2efP3efKWdSMtqFGagtv5JPnKqevHusEWmzf9j0glg/KJgH2q/nXrXquXXx70NiaJulBJrKxaqotQ6PIX/Czqw1YyFYnm2s0= 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=J0zA0c7P; arc=none smtp.client-ip=91.218.175.174 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="J0zA0c7P" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776305207; 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=TaDtlDhvpSN1DHQ/+o47EJco+lcgV052hZ9XtkHXQBM=; b=J0zA0c7PNrU1/2K6DsccDATXvjS/5EjTLM92uaQLPBY5Bs2V4BcyO2VeGwXmN8w1IQpL8E uiKGZopweljMF01lnCABOKA5JDUkCf3P60EkZYOn4tKQ6HjXEmbJ+l9Aq0NcG3edWqIxxp eVPIu6DatuMk04EV+TM9SasWJSra1zs= 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.500.181\)) Subject: Re: [PATCH v2 6/6] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE compound 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, 16 Apr 2026 10:06:03 +0800 Cc: Muchun Song , Andrew Morton , David Hildenbrand , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <86523791-2C69-4A43-BD32-3713840A6640@linux.dev> References: <20260415111412.1003526-1-songmuchun@bytedance.com> <20260415111412.1003526-7-songmuchun@bytedance.com> To: Mike Rapoport X-Migadu-Flow: FLOW_OUT > On Apr 16, 2026, at 01:03, Mike Rapoport wrote: >=20 > Hi Muchun, >=20 > On Wed, Apr 15, 2026 at 07:14:12PM +0800, Muchun Song wrote: >> The memmap_init_zone_device() function only initializes the = migratetype >> of the first pageblock of a compound page. If the compound page size >> exceeds pageblock_nr_pages (e.g., 1GB hugepages with 2MB pageblocks), >> subsequent pageblocks in the compound page remain uninitialized. >>=20 >> Move the migratetype initialization out of __init_zone_device_page() >> and into a separate pageblock_migratetype_init_range() function. This >> iterates over the entire PFN range of the memory, ensuring that all >> pageblocks are correctly initialized. >>=20 >> Fixes: c4386bd8ee3a ("mm/memremap: add ZONE_DEVICE support for = compound pages") >> Signed-off-by: Muchun Song >> --- >> mm/mm_init.c | 42 +++++++++++++++++++++++++++--------------- >> 1 file changed, 27 insertions(+), 15 deletions(-) >>=20 >> diff --git a/mm/mm_init.c b/mm/mm_init.c >> index f9f8e1af921c..30528c4206c1 100644 >> --- a/mm/mm_init.c >> +++ b/mm/mm_init.c >> @@ -674,6 +674,19 @@ static inline void fixup_hashdist(void) >> static inline void fixup_hashdist(void) {} >> #endif /* CONFIG_NUMA */ >>=20 >> +static __meminit void pageblock_migratetype_init_range(unsigned long = pfn, >> + unsigned long nr_pages, >> + int migratetype) >> +{ >> + unsigned long end =3D pfn + nr_pages; >> + >> + for (pfn =3D pageblock_align(pfn); pfn < end; pfn +=3D = pageblock_nr_pages) { >> + init_pageblock_migratetype(pfn_to_page(pfn), = migratetype, false); >> + if (IS_ALIGNED(pfn, PAGES_PER_SECTION)) >> + cond_resched(); >> + } >> +} >> + >> /* >> * Initialize a reserved page unconditionally, finding its zone = first. >> */ >> @@ -1011,21 +1024,6 @@ static void __ref = __init_zone_device_page(struct page *page, unsigned long pfn, >> page_folio(page)->pgmap =3D pgmap; >> page->zone_device_data =3D NULL; >>=20 >> - /* >> - * Mark the block movable so that blocks are reserved for >> - * movable at startup. This will force kernel allocations >> - * to reserve their blocks rather than leaking throughout >> - * the address space during boot when many long-lived >> - * kernel allocations are made. >> - * >> - * Please note that MEMINIT_HOTPLUG path doesn't clear memmap >> - * because this is done early in section_activate() >> - */ >> - if (pageblock_aligned(pfn)) { >> - init_pageblock_migratetype(page, MIGRATE_MOVABLE, = false); >> - cond_resched(); >> - } >> - >> /* >> * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released >> * directly to the driver page allocator which will set the page = count >> @@ -1122,6 +1120,8 @@ void __ref memmap_init_zone_device(struct zone = *zone, >>=20 >> __init_zone_device_page(page, pfn, zone_idx, nid, pgmap); >>=20 >> + cond_resched(); >> + >=20 > I don't think we want cond_resched() for every page here too, even = it's a > compound page :) I'll update it to every PAGES_PER_SECTION, does this make sense for you? Thanks, Muchun >=20 > Otherwise >=20 > Reviewed-by: Mike Rapoport (Microsoft) >=20 >> if (pfns_per_compound =3D=3D 1) >> continue; >>=20 >> @@ -1129,6 +1129,18 @@ void __ref memmap_init_zone_device(struct zone = *zone, >> compound_nr_pages(altmap, pgmap)); >> } >>=20 >> + /* >> + * Mark the block movable so that blocks are reserved for >> + * movable at startup. This will force kernel allocations >> + * to reserve their blocks rather than leaking throughout >> + * the address space during boot when many long-lived >> + * kernel allocations are made. >> + * >> + * Please note that MEMINIT_HOTPLUG path doesn't clear memmap >> + * because this is done early in section_activate() >> + */ >> + pageblock_migratetype_init_range(start_pfn, nr_pages, = MIGRATE_MOVABLE); >> + >> pr_debug("%s initialised %lu pages in %ums\n", __func__, >> nr_pages, jiffies_to_msecs(jiffies - start)); >> } >> --=20 >> 2.20.1 >>=20 >=20 > --=20 > Sincerely yours, > Mike.