[{"id":3677767,"web_url":"http://patchwork.ozlabs.org/comment/3677767/","msgid":"<ad_EygHWDi19SS9y@kernel.org>","date":"2026-04-15T17:03:06","subject":"Re: [PATCH v2 6/6] mm/mm_init: Fix pageblock migratetype for\n ZONE_DEVICE compound pages","submitter":{"id":77733,"url":"http://patchwork.ozlabs.org/api/people/77733/","name":"Mike Rapoport","email":"rppt@kernel.org"},"content":"Hi Muchun,\n\nOn Wed, Apr 15, 2026 at 07:14:12PM +0800, Muchun Song wrote:\n> The memmap_init_zone_device() function only initializes the migratetype\n> of the first pageblock of a compound page. If the compound page size\n> exceeds pageblock_nr_pages (e.g., 1GB hugepages with 2MB pageblocks),\n> subsequent pageblocks in the compound page remain uninitialized.\n> \n> Move the migratetype initialization out of __init_zone_device_page()\n> and into a separate pageblock_migratetype_init_range() function. This\n> iterates over the entire PFN range of the memory, ensuring that all\n> pageblocks are correctly initialized.\n> \n> Fixes: c4386bd8ee3a (\"mm/memremap: add ZONE_DEVICE support for compound pages\")\n> Signed-off-by: Muchun Song <songmuchun@bytedance.com>\n> ---\n>  mm/mm_init.c | 42 +++++++++++++++++++++++++++---------------\n>  1 file changed, 27 insertions(+), 15 deletions(-)\n> \n> diff --git a/mm/mm_init.c b/mm/mm_init.c\n> index f9f8e1af921c..30528c4206c1 100644\n> --- a/mm/mm_init.c\n> +++ b/mm/mm_init.c\n> @@ -674,6 +674,19 @@ static inline void fixup_hashdist(void)\n>  static inline void fixup_hashdist(void) {}\n>  #endif /* CONFIG_NUMA */\n>  \n> +static __meminit void pageblock_migratetype_init_range(unsigned long pfn,\n> +\t\t\t\t\t\t       unsigned long nr_pages,\n> +\t\t\t\t\t\t       int migratetype)\n> +{\n> +\tunsigned long end = pfn + nr_pages;\n> +\n> +\tfor (pfn = pageblock_align(pfn); pfn < end; pfn += pageblock_nr_pages) {\n> +\t\tinit_pageblock_migratetype(pfn_to_page(pfn), migratetype, false);\n> +\t\tif (IS_ALIGNED(pfn, PAGES_PER_SECTION))\n> +\t\t\tcond_resched();\n> +\t}\n> +}\n> +\n>  /*\n>   * Initialize a reserved page unconditionally, finding its zone first.\n>   */\n> @@ -1011,21 +1024,6 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,\n>  \tpage_folio(page)->pgmap = pgmap;\n>  \tpage->zone_device_data = NULL;\n>  \n> -\t/*\n> -\t * Mark the block movable so that blocks are reserved for\n> -\t * movable at startup. This will force kernel allocations\n> -\t * to reserve their blocks rather than leaking throughout\n> -\t * the address space during boot when many long-lived\n> -\t * kernel allocations are made.\n> -\t *\n> -\t * Please note that MEMINIT_HOTPLUG path doesn't clear memmap\n> -\t * because this is done early in section_activate()\n> -\t */\n> -\tif (pageblock_aligned(pfn)) {\n> -\t\tinit_pageblock_migratetype(page, MIGRATE_MOVABLE, false);\n> -\t\tcond_resched();\n> -\t}\n> -\n>  \t/*\n>  \t * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released\n>  \t * directly to the driver page allocator which will set the page count\n> @@ -1122,6 +1120,8 @@ void __ref memmap_init_zone_device(struct zone *zone,\n>  \n>  \t\t__init_zone_device_page(page, pfn, zone_idx, nid, pgmap);\n>  \n> +\t\tcond_resched();\n> +\n\nI don't think we want cond_resched() for every page here too, even it's a\ncompound page :)\n\nOtherwise\n\nReviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>\n\n>  \t\tif (pfns_per_compound == 1)\n>  \t\t\tcontinue;\n>  \n> @@ -1129,6 +1129,18 @@ void __ref memmap_init_zone_device(struct zone *zone,\n>  \t\t\t\t     compound_nr_pages(altmap, pgmap));\n>  \t}\n>  \n> +\t/*\n> +\t * Mark the block movable so that blocks are reserved for\n> +\t * movable at startup. This will force kernel allocations\n> +\t * to reserve their blocks rather than leaking throughout\n> +\t * the address space during boot when many long-lived\n> +\t * kernel allocations are made.\n> +\t *\n> +\t * Please note that MEMINIT_HOTPLUG path doesn't clear memmap\n> +\t * because this is done early in section_activate()\n> +\t */\n> +\tpageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE);\n> +\n>  \tpr_debug(\"%s initialised %lu pages in %ums\\n\", __func__,\n>  \t\tnr_pages, jiffies_to_msecs(jiffies - start));\n>  }\n> -- \n> 2.20.1\n>","headers":{"Return-Path":"\n <linuxppc-dev+bounces-19781-incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=L06wAtHS;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=112.213.38.117; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-19781-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=172.105.4.254","lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org","lists.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=L06wAtHS;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org\n (client-ip=172.105.4.254; helo=tor.source.kernel.org;\n envelope-from=rppt@kernel.org; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1 raw public key)\n server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fwnXT1rf1z1yHM\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 03:03:20 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fwnXR2rkWz2yjN;\n\tThu, 16 Apr 2026 03:03:19 +1000 (AEST)","from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 4fwnXQ15T5z2yhY\n\tfor <linuxppc-dev@lists.ozlabs.org>; Thu, 16 Apr 2026 03:03:17 +1000 (AEST)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby tor.source.kernel.org (Postfix) with ESMTP id 21284600AD;\n\tWed, 15 Apr 2026 17:03:15 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id A83C4C19424;\n\tWed, 15 Apr 2026 17:03:09 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776272599;\n\tcv=none;\n b=AbuV5PUeSWydEfDI7xMr5JhH20S7v9PtHDeJu8jcuEd/y3PqGo3prgjVt3lso2PVbt50gpcux9uU4UytSLhOIG8nqpNLscbN2v6O5yPlk45c8ULahs/cc5cxkt+7pBIL7lfmWgalX10Lp9VgT1DHXmLIdm+rwQKNTvduIBeKPcEzlQjk1iNDYY0lJ3Pmu6xhfwR/RfdH8b7Lo+bSfPtt5c/jwmsJNeWcPax4VETlYVnJg8gYAgy2je6GILY1si1TCwJhtrGJYzAV865euxTxr7Pcn6b+Q8A6EwgFZqV9J+izuDUc9PIlihTcg7y7A7xOOyO2zirTBkhMhp1P9g6m9Q==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1776272599; c=relaxed/relaxed;\n\tbh=BeK4x1dxgJguKDNqttCCDO06v9f5N1pztpozpFeGrH0=;\n\th=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:\n\t Content-Type:Content-Disposition:In-Reply-To;\n b=CLV1hP9B+fLNQn2f5/8PZgzq87651mGUSjRGQgF0gF+X1oOMHz9/7c6hP2fFM9CBWzXHg00LqhFMdQTSpCw8WviuB1S/CxTR8gBZDS7XFYKgVW3Zz9UWg3U4Fs5P0bPYo12Nb1HjlvyscsT65G6a9gUbq2o9U8Aheu5Bw2n/SAf8ZsZpx2qs8ZeERwnvSKFDIfuFCkbORhuVCkNu2tQVdY9gD23HnGdGFnABOBxG9ALFlgjumoWQjkh8MyPYbDNkTpaat+3pd+MM1zXa8CpPHw6ZNNml0SsbQV+S1FNBvzZjHMs+p8u8hZoEq7KZ0/upyk7U2TL1Jbg6NMmsf+LSDQ==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org;\n dkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=L06wAtHS; dkim-atps=neutral;\n spf=pass (client-ip=172.105.4.254; helo=tor.source.kernel.org;\n envelope-from=rppt@kernel.org;\n receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1776272594;\n\tbh=mTAGT4DOoB+Ql7bFiOXRTX+ODnCO2UkCTVqe5r/JaGY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=L06wAtHSsRMa8OvFoMaXwNH+1eYa2W/v97alLbMISAOhCVynQoCeVmWJ5ZTbJM2MU\n\t QP7uytxhoWHErO3ob8f61vSccJltnPjAWtlZt4lsROLQKwiy6NhoQ5oVgulzUN2XE7\n\t Uo3FI5DmnXnfiqIlq8mgXKJj1rnTTcT/r34LozkpmiTLGt7Qjx1MyAk6v8ee1n+Rpk\n\t 74o3/NiC27Orm8AO8F1joPLIciZG77gcb4LXn7GyeQNAW8nrMjUVV+grPXZ+Huzp/Z\n\t RmjoqCkMBFE6XBtZkfqKwxw5eGbivNgTzlGo0+AdBKR6c4ga/EKSAl1llk+H4Pev8Q\n\t 9k3GwIuIRnuKA==","Date":"Wed, 15 Apr 2026 20:03:06 +0300","From":"Mike Rapoport <rppt@kernel.org>","To":"Muchun Song <songmuchun@bytedance.com>","Cc":"Andrew Morton <akpm@linux-foundation.org>,\n\tDavid Hildenbrand <david@kernel.org>,\n\tMuchun Song <muchun.song@linux.dev>,\n\tOscar Salvador <osalvador@suse.de>,\n\tMichael Ellerman <mpe@ellerman.id.au>,\n\tMadhavan Srinivasan <maddy@linux.ibm.com>,\n\tLorenzo Stoakes <ljs@kernel.org>,\n\t\"Liam R . Howlett\" <Liam.Howlett@oracle.com>,\n\tVlastimil Babka <vbabka@kernel.org>,\n\tSuren Baghdasaryan <surenb@google.com>,\n\tMichal Hocko <mhocko@suse.com>, Nicholas Piggin <npiggin@gmail.com>,\n\tChristophe Leroy <chleroy@kernel.org>, aneesh.kumar@linux.ibm.com,\n\tjoao.m.martins@oracle.com, linux-mm@kvack.org,\n\tlinuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org","Subject":"Re: [PATCH v2 6/6] mm/mm_init: Fix pageblock migratetype for\n ZONE_DEVICE compound pages","Message-ID":"<ad_EygHWDi19SS9y@kernel.org>","References":"<20260415111412.1003526-1-songmuchun@bytedance.com>\n <20260415111412.1003526-7-songmuchun@bytedance.com>","X-Mailing-List":"linuxppc-dev@lists.ozlabs.org","List-Id":"<linuxppc-dev.lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev+help@lists.ozlabs.org>","List-Owner":"<mailto:linuxppc-dev+owner@lists.ozlabs.org>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Archive":"<https://lore.kernel.org/linuxppc-dev/>,\n  <https://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Subscribe":"<mailto:linuxppc-dev+subscribe@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-digest@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-nomail@lists.ozlabs.org>","List-Unsubscribe":"<mailto:linuxppc-dev+unsubscribe@lists.ozlabs.org>","Precedence":"list","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20260415111412.1003526-7-songmuchun@bytedance.com>","X-Spam-Status":"No, score=-0.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,\n\tDKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS\n\tautolearn=disabled version=4.0.1 OzLabs 8","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org"}}]