{"id":2226088,"url":"http://patchwork.ozlabs.org/api/patches/2226088/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260422081420.4009847-5-songmuchun@bytedance.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/projects/2/?format=json","name":"Linux PPC development","link_name":"linuxppc-dev","list_id":"linuxppc-dev.lists.ozlabs.org","list_email":"linuxppc-dev@lists.ozlabs.org","web_url":"https://github.com/linuxppc/wiki/wiki","scm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git","webscm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/","list_archive_url":"https://lore.kernel.org/linuxppc-dev/","list_archive_url_format":"https://lore.kernel.org/linuxppc-dev/{}/","commit_url_format":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}"},"msgid":"<20260422081420.4009847-5-songmuchun@bytedance.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20260422081420.4009847-5-songmuchun@bytedance.com/","date":"2026-04-22T08:14:19","name":"[v4,4/5] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE compound pages","commit_ref":null,"pull_url":null,"state":"handled-elsewhere","archived":false,"hash":"4bf17a5bf15da5d776bbbafeeefd288893bd0026","submitter":{"id":78930,"url":"http://patchwork.ozlabs.org/api/people/78930/?format=json","name":"Muchun Song","email":"songmuchun@bytedance.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260422081420.4009847-5-songmuchun@bytedance.com/mbox/","series":[{"id":500940,"url":"http://patchwork.ozlabs.org/api/series/500940/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=500940","date":"2026-04-22T08:14:15","name":"mm: Fix vmemmap optimization accounting and initialization","version":4,"mbox":"http://patchwork.ozlabs.org/series/500940/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226088/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226088/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linuxppc-dev+bounces-19940-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=bytedance.com header.i=@bytedance.com\n header.a=rsa-sha256 header.s=google header.b=AubyEuX1;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=2404:9400:21b9:f100::1; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-19940-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=\"2607:f8b0:4864:20::435\"","lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=bytedance.com","lists.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=bytedance.com header.i=@bytedance.com\n header.a=rsa-sha256 header.s=google header.b=AubyEuX1;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com\n (client-ip=2607:f8b0:4864:20::435; helo=mail-pf1-x435.google.com;\n envelope-from=songmuchun@bytedance.com; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org\n [IPv6:2404:9400:21b9:f100::1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0sTz0PGVz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 18:15:19 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4g0sTn6Kpvz304h;\n\tWed, 22 Apr 2026 18:15:09 +1000 (AEST)","from mail-pf1-x435.google.com (mail-pf1-x435.google.com\n [IPv6:2607:f8b0:4864:20::435])\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 4g0sTn1F8kz2yqs\n\tfor <linuxppc-dev@lists.ozlabs.org>; Wed, 22 Apr 2026 18:15:09 +1000 (AEST)","by mail-pf1-x435.google.com with SMTP id\n d2e1a72fcca58-82fbdd60b64so1906878b3a.3\n        for <linuxppc-dev@lists.ozlabs.org>;\n Wed, 22 Apr 2026 01:15:08 -0700 (PDT)","from n232-176-004.byted.org ([240e:83:200::34f])\n        by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-82f8ec0307esm16522874b3a.53.2026.04.22.01.15.00\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Wed, 22 Apr 2026 01:15:06 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776845709;\n\tcv=none;\n b=EPzc9OzNB6Lwx5nSDlEILHGHfqIMfEJxKUVINpK0Qr1k9yRQGqD9tpsXWZHDuN7RZXafp7yGWui6/CLcr4M+CwHxBY2xCWcJIxtG9wESpEwPIuddfbyjeHa2MRDsxv5vd500CHfEVPzPxa6rY3ByRtsIEsRqNGq3vzcVrqv244VluyudRcgYHrsRPiMOVUtdAxISG73kZpRQ67O77tus84eDzorPm1ocoLNCWdd62xkas8s/f0zi9/XfDW17BLqlfvHkDpJ51LVlhedvYZ/1zFFfsd37RO9No2cZVB4XNPRVvVqsnsnGjbBm/mGh2QLPizsmyPLffajuYlc3W9rm1g==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1776845709; c=relaxed/relaxed;\n\tbh=bFvE9gY2jdfvM/7z3bv6AJAQ88eqA1v0Ow6s9f2y7sk=;\n\th=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n\t MIME-Version;\n b=EI/BhpBD/y41MRaRaoZ06rn1mrBxDLwKaCJFfwYFCC+yE72YdPSRfTeyI480nPr9/CD72VlsfTxkOs7M+pkjC81QpSLxVAbXQ9xvBMWmXU7uKPQL5wGw5I9nxI2PGzkR4E0/InyHpsAB4b//8WW2W5iSc7HT+DSY3i6slu7W5OL/FeAmiEYbguPCBxf/KDYhVa9ju4y4BNY2HmBG7yVvlgScd6yIC9/8Rd0bnxFG/ipyD62ITQgDbesFzpv56Nepn3Yh5IaGm8n6gdQI6S2CbMtk1n4yGaiExRquJclE8DoBHommaDdq1D3XMW4TjoInWRTHvua2PpRhQ2FHSwpJ6w==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=bytedance.com;\n dkim=pass (2048-bit key;\n unprotected) header.d=bytedance.com header.i=@bytedance.com\n header.a=rsa-sha256 header.s=google header.b=AubyEuX1; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::435; helo=mail-pf1-x435.google.com;\n envelope-from=songmuchun@bytedance.com;\n receiver=lists.ozlabs.org) smtp.mailfrom=bytedance.com","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=bytedance.com; s=google; t=1776845707; x=1777450507;\n darn=lists.ozlabs.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=bFvE9gY2jdfvM/7z3bv6AJAQ88eqA1v0Ow6s9f2y7sk=;\n        b=AubyEuX1JRIiPpw3xds5R/+n5nEPTjrTszZue7YLZ74pjWmaPgkMLc4WBQ8fBebq5T\n         ENIoUG/JwY4yT6MrxJURbZ0WOFHOkVZ/b9OkSxjWpeKeJfreBTLihyEFJbvXRPK3j41V\n         mvMjVkSUZ/yfVHuXBTUHWO63a/TuWlhWayTMVaXPGHcOEhfIcg3YdD0QxgyCuQ1YXCEl\n         BDXuFpTfyIaFnNuLUjw7sJyEBTuwIjGd+JURSLXl76Zb5qfEgfXdutKq3DrzUIOyAYir\n         pDusoKhh8INiU/QvT58ZLfbXEOz+IdxTDqk3xRlBAGYgz+FA0yjlHTWHgTm1VTe4KcRU\n         8cDA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776845707; x=1777450507;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=bFvE9gY2jdfvM/7z3bv6AJAQ88eqA1v0Ow6s9f2y7sk=;\n        b=IxpEiPG692kIz6+iKgDNGS6nzZmnD1UksM3wakni1gJN816BlXy91B7egD/NQerrds\n         +V+1cnWuGtdHFjhbPGg3Li/PM4wrGDCF52cTXoB1mQeLF1IYzcrwLCvs/xTTs4DghGG7\n         0e2u7hQO/DkSl0PG/M0cKR3Uug+2Ada9fcdng63OHcBnAVOcEIWodJLJr2XL4DALkClC\n         B5PcGqOoCRyJ3HSTJNHArXQZTYXc0y6EtRVISLVECxsiPO6BwtbXa2uPA5oDWgQHPcRj\n         bG1rizj9Q8E24tXIW96Oc+DwkI4l/t2x+j9QfC9COTK5dOvrczuqz0mq6Ltlpl9XPwqF\n         TyUA==","X-Forwarded-Encrypted":"i=1;\n AFNElJ9IHMnpankTVV3tyPL9DJlE6NNfNvgLeOM22RjVCatYiDnat7+EmAtZMWtyvj9b6yrcfQUEl4eafcaaTrA=@lists.ozlabs.org","X-Gm-Message-State":"AOJu0YwPmLfj9sZ3iZxtM8ZJ+3ESnhSy1+cBVUjN415mzQJNb/qqmSoh\n\tP1jZ2k1aStT73yP1SYJkpvS8aXd/K2Aw3Go7Jz+teT4VVf9sPl47gvKGVPvLI2cmUPY=","X-Gm-Gg":"AeBDietsOEsVjY1SEUgBgyuaSW+D8WEV8uFii+3SC7QC3MI0cUP3P/asuuXalOh4c1F\n\tbffAb03vppeNdTZ1WF3K2KcK1ssPEC+FhDCZ9yQ8hsyyx8pnQzr/Fz6LlyhgNQGGirC6n/fLCGq\n\tNEr7eaMf024qSQY+dKf6dapOq+NhkAVXx74eHSW8/9qDVKgnO1iGwf/mRoMPwR3QiQJyzA0lDy3\n\tVaI8ofonzAB8wyLviNvrPiaVpR06/gh8nrpBMmBkdMH5H4Nr15kQvzMsuPGhVBr5qgOjA7J5b/T\n\ttvaRUFQq1+w/iQ33Jkc8BhLHwvk7i1AtEA2UbCXCf4VRE/JSCOmydTnkgpImhXBoQM4Z85y+Tw7\n\tmB31HDHuKDEZmm1wDa6VIs7opZ4jhvQboWUqKit4P5Cl/YpOYSxdmwp0tTC/X7erzOEN74QF0LC\n\twzJj2+MqW98C72QSI6rojx7wmvqvrN","X-Received":"by 2002:a05:6a00:3e16:b0:82f:5571:1a8d with SMTP id\n d2e1a72fcca58-82f8c8308e0mr22842732b3a.2.1776845706907;\n        Wed, 22 Apr 2026 01:15:06 -0700 (PDT)","From":"Muchun Song <songmuchun@bytedance.com>","To":"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>","Cc":"Muchun Song <songmuchun@bytedance.com>,\n\tLorenzo Stoakes <ljs@kernel.org>,\n\t\"Liam R . Howlett\" <Liam.Howlett@oracle.com>,\n\tVlastimil Babka <vbabka@kernel.org>,\n\tMike Rapoport <rppt@kernel.org>,\n\tSuren Baghdasaryan <surenb@google.com>,\n\tMichal Hocko <mhocko@suse.com>,\n\tNicholas Piggin <npiggin@gmail.com>,\n\tChristophe Leroy <chleroy@kernel.org>,\n\taneesh.kumar@linux.ibm.com,\n\tjoao.m.martins@oracle.com,\n\tlinux-mm@kvack.org,\n\tlinuxppc-dev@lists.ozlabs.org,\n\tlinux-kernel@vger.kernel.org","Subject":"[PATCH v4 4/5] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE\n compound pages","Date":"Wed, 22 Apr 2026 16:14:19 +0800","Message-Id":"<20260422081420.4009847-5-songmuchun@bytedance.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20260422081420.4009847-1-songmuchun@bytedance.com>","References":"<20260422081420.4009847-1-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-Transfer-Encoding":"8bit","X-Spam-Status":"No, score=-0.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,\n\tDKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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"},"content":"The memmap_init_zone_device() function only initializes the migratetype\nof the first pageblock of a compound page. If the compound page size\nexceeds pageblock_nr_pages (e.g., 1GB hugepages with 2MB pageblocks),\nsubsequent pageblocks in the compound page remain uninitialized.\n\nMove the migratetype initialization out of __init_zone_device_page()\nand into a separate pageblock_migratetype_init_range() function. This\niterates over the entire PFN range of the memory, ensuring that all\npageblocks are correctly initialized.\n\nFixes: c4386bd8ee3a (\"mm/memremap: add ZONE_DEVICE support for compound pages\")\nSigned-off-by: Muchun Song <songmuchun@bytedance.com>\nReviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>\nReviewed-by: Oscar Salvador <osalvador@suse.de>\n---\n mm/mm_init.c | 45 ++++++++++++++++++++++++++++++---------------\n 1 file changed, 30 insertions(+), 15 deletions(-)","diff":"diff --git a/mm/mm_init.c b/mm/mm_init.c\nindex f9f8e1af921c..9d0fe79a94de 100644\n--- a/mm/mm_init.c\n+++ b/mm/mm_init.c\n@@ -674,6 +674,21 @@ static inline void fixup_hashdist(void)\n static inline void fixup_hashdist(void) {}\n #endif /* CONFIG_NUMA */\n \n+#ifdef CONFIG_ZONE_DEVICE\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+#endif\n+\n /*\n  * Initialize a reserved page unconditionally, finding its zone first.\n  */\n@@ -1011,21 +1026,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 +1122,9 @@ 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\tif (IS_ALIGNED(pfn, PAGES_PER_SECTION))\n+\t\t\tcond_resched();\n+\n \t\tif (pfns_per_compound == 1)\n \t\t\tcontinue;\n \n@@ -1129,6 +1132,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","prefixes":["v4","4/5"]}