From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 B213E3CEB99 for ; Mon, 13 Apr 2026 13:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776088653; cv=none; b=CVzFXwOcDrTOfrOnSJHyLX+6xzyXiF6G99pRoUithz0/y1IZRVeG/Ult4IechL1KlAW+3owhwmF7ze1P+8XNjLUFs0AAZwY79pkWaP32qMrqkrZCQ93+PqmBo8CDSPJ4LqhgF7MeUwiU3I5u7KBeHQ3mutnvtXK0dlHF9/oNc1U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776088653; c=relaxed/simple; bh=41oTlUs39OFMQe6f4gC1i9y8y3+rAoe+ohHT2yfuznA=; h=Content-Type:From:Mime-Version:Subject:Date:Message-Id:References: Cc:In-Reply-To:To; b=AkdPXeSK2PyEAsnKguLERsW8XXtjYDGdG338qP2mxcxky92QfogrJGqF2iUD/2PCjYfR78EAQmZ2Fk7jZN8YjSXEmXSoH6R7re4Ln93XF1lvvPVsQejf4i0wxXZi+14XvigsPQY5m63SMl6YWNkRPXKRZyOjXT1sSs5q3nnrwXk= 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=DmYoUD9o; arc=none smtp.client-ip=91.218.175.179 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="DmYoUD9o" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776088647; 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=WB6X/KB4lcgoxaXTVldx7yfC+K++jG31ztfaBdye/0o=; b=DmYoUD9oKqdfKivm9z9TwfbKLHD13LH/gu6nFBQGBPzDBoPrHIIJnqbsGdaBjyp/HzmHN5 mVQMvqextCEEWtEWK81D/y4Sja1/VSwcgDqDjhNY8hYIm10O6g8QQmcjc0z05CcPpQLLRS 8dTHIkivv52rRR/NBQD14jzk00a+lW0= Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (1.0) Subject: Re: [PATCH 06/49] mm/mm_init: fix uninitialized pageblock migratetype for ZONE_DEVICE compound pages Date: Mon, 13 Apr 2026 21:57:00 +0800 Message-Id: References: 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 In-Reply-To: To: Mike Rapoport X-Migadu-Flow: FLOW_OUT > On Apr 13, 2026, at 21:28, Mike Rapoport wrote: >=20 > =EF=BB=BFOn Mon, Apr 13, 2026 at 06:07:44PM +0800, Muchun Song wrote: >>=20 >>=20 >>>> On Apr 13, 2026, at 17:32, Mike Rapoport wrote: >>>=20 >>> On Sun, Apr 05, 2026 at 08:51:57PM +0800, Muchun Song wrote: >>>> Previously, memmap_init_zone_device() only initialized 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 would remain uninitialized. >>>>=20 >>>> This patch moves the migratetype initialization out of >>>> __init_zone_device_page() and into a separate function >>>> pageblock_migratetype_init_range(). This function iterates over the >>>> entire PFN range of the memory, ensuring that all pageblocks are correc= tly >>>> initialized. >>>>=20 >>>> Fixes: c4386bd8ee3a ("mm/memremap: add ZONE_DEVICE support for compound= pages") >>>> Signed-off-by: Muchun Song >>>> --- >>>> mm/mm_init.c | 41 ++++++++++++++++++++++++++--------------- >>>> 1 file changed, 26 insertions(+), 15 deletions(-) >>>>=20 >>>> diff --git a/mm/mm_init.c b/mm/mm_init.c >>>> index 9a44e8458fed..4936ca78966c 100644 >>>> --- a/mm/mm_init.c >>>> +++ b/mm/mm_init.c >>>> @@ -674,6 +674,18 @@ 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 p= fn, >>>> + 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_p= ages) { >>>> + init_pageblock_migratetype(pfn_to_page(pfn), migratetype, false); >>>> + cond_resched(); >>>=20 >>> Do we need to call cond_resched() every iteration here? >>=20 >> Of course not. >>=20 >>>=20 >>>> + } >>>> +} >>>> + >>>> /* >>>> * Initialize a reserved page unconditionally, finding its zone first. >>>> */ >>>> @@ -1011,21 +1023,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 +1119,8 @@ void __ref memmap_init_zone_device(struct zone *z= one, >>>>=20 >>>> __init_zone_device_page(page, pfn, zone_idx, nid, pgmap); >>>>=20 >>>> + cond_resched(); >>>=20 >>> Originally we called cond_resched() once per pageblock, now it's called >>> once per page plus for every pageblock in the tight loop that sets the >>> migrate type. Isn't it too much? >>=20 >> There are indeed many more cond_resched() than before, but I don=E2=80=99= t have a >> concise way to write it, so I took the easy way out. >>=20 >> How about: >>=20 >> diff --git a/mm/mm_init.c b/mm/mm_init.c >> index 2d680636b67a..d13a2577c4c3 100644 >> --- a/mm/mm_init.c >> +++ b/mm/mm_init.c >> @@ -683,7 +683,8 @@ static __meminit void pageblock_migratetype_init_rang= e(unsigned long pfn, >>=20 >> for (pfn =3D pageblock_align(pfn); pfn < end; pfn +=3D pageblock_n= r_pages) { >> init_pageblock_migratetype(pfn_to_page(pfn), migratetype, i= solate); >> - cond_resched(); >> + if ((pfn & (pageblock_nr_pages * 512 - 1)) =3D=3D 0) >> + cond_resched(); >=20 > TBH, I don't know if 512 is the right number :) I picked this number out of thin air. I=E2=80=99m not sure as well. >=20 > pageblock boundary was a convenient point to have cond_resched() along wit= h > setting the migrate type. >=20 > Here we might be able to squeeze more iterations between subsequent > cond_resched() calls. Choosing an appropriate number is indeed difficult. We need to consider both unnecessary cond_resched() calls and scheduling latency, and the specific value also depends on the current CPU performance. At the very leas= t, I find it hard to choose a correct value. Since we all agree it should be la= rger than 512, why not just pick 1024? I can't think of a good evaluation criteri= on or selection method either. Thanks. >=20 > -- > Sincerely yours, > Mike.