{"id":2225417,"url":"http://patchwork.ozlabs.org/api/patches/2225417/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260421022044.1217503-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":"<20260421022044.1217503-5-songmuchun@bytedance.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20260421022044.1217503-5-songmuchun@bytedance.com/","date":"2026-04-21T02:20:44","name":"[v3,4/4] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE compound pages","commit_ref":null,"pull_url":null,"state":"handled-elsewhere","archived":false,"hash":"c23af7c0cbf1822f42fc7d4255dc989f6588a6d3","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/20260421022044.1217503-5-songmuchun@bytedance.com/mbox/","series":[{"id":500709,"url":"http://patchwork.ozlabs.org/api/series/500709/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=500709","date":"2026-04-21T02:20:40","name":"mm: Fix vmemmap optimization accounting and initialization","version":3,"mbox":"http://patchwork.ozlabs.org/series/500709/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225417/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225417/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linuxppc-dev+bounces-19861-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=WR/GTrB7;\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-19861-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::42e\"","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=WR/GTrB7;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com\n (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.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 4g05hN6b0sz1yHB\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 12:21:40 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4g05hD2v82z30FD;\n\tTue, 21 Apr 2026 12:21:32 +1000 (AEST)","from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com\n [IPv6:2607:f8b0:4864:20::42e])\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 4g05hC4805z2xT6\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 21 Apr 2026 12:21:31 +1000 (AEST)","by mail-pf1-x42e.google.com with SMTP id\n d2e1a72fcca58-82f8bf96b46so1783640b3a.2\n        for <linuxppc-dev@lists.ozlabs.org>;\n Mon, 20 Apr 2026 19:21:31 -0700 (PDT)","from n232-176-004.byted.org ([240e:83:200::340])\n        by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-82f932dabd4sm11538780b3a.51.2026.04.20.19.21.24\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Mon, 20 Apr 2026 19:21:29 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776738092;\n\tcv=none;\n b=m6XK6rDmU9+ejE4XJP8Es4qgXDzdyhbMEiwll1ebsO1JVIT09RZnaDagPW3/5/UVYlDQ1QDuTm+DomWVlnX/Q4z/djEtbYiQU37G4P8zja64Uh4OnzL42kSDLLFWBHeeuhhiRBeMHGnZPO2IsoFXXg1y4EEJpUDUbhQufzTZhzWO8ogq8UXnMZXsHButs6Mbgjw6Eljuj9340l0olQ7TAnUkqfQQQ2dzefzZ34t0z04qR9u2X2i9lh1PiKRQJ7P8dONuj0bv6xHP+KscZWtaZCK3Xd9I30VC0rlIeoOznGXrQoDAPE/NuIVb6Sox35VGy25p9eNQs/HXPJ8Vm3iuFg==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1776738092; c=relaxed/relaxed;\n\tbh=AHmsLfWP4VqB6EidVCtZitT2oU+Ddzspq2XDJx69+hM=;\n\th=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n\t MIME-Version;\n b=B4kZiH9oU7NhuO6lfLwdORGMWdlj0B9PX4QB8bZYa2lMsLQDHWLRNPwvaquVf8BwtjuvPdXMFCE+OGZskmaHoRdv+b/ocKOJ9cOfWyCGZ10gUMdhoaHxPf1ZTl+JRslsSeqEWBhRYxSwfcbvuGKg7+Pwd6cKBPwET1nbe55YkZeSrN9uV1gpaS0SHS7TkQONTBHVTP1zKAGgq309Q/FTHp3KCEndtlkjeGt1GzTrbkXZ21rYcmIBQm9VIh7pr3tU516q99716NFFwGFT2wxCN8B8ikKkSLNBdDmUPc+p+Imrezp1kZC5PYkY4ODo3Oc3WxXgHyz2YG5HGFVxi1gj7Q==","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=WR/GTrB7; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.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=1776738090; x=1777342890;\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=AHmsLfWP4VqB6EidVCtZitT2oU+Ddzspq2XDJx69+hM=;\n        b=WR/GTrB7pLUyhu83NsY3oUsGhT3DgfaGzp9JF0dO9ugqVs6XNOOM59qkT2Dy/84Mjy\n         cFeiCwb6YH1qFxYf+5kOXqyumrG5ocA25mKOBtX7L65SitbLs1NTLwuS+rTRpz38GK9I\n         7Segg7CgCg11e9mjr0jfJKF/Z461k75flpZeq5Ft/shgcIVghu0vTY/n4Ol6jjy0APUz\n         B82aEqR8rlqzwjW1yYLgwGyPvTESfvp5bR4VnZgJXoA0RrkXfG7ZhNc6XNprMDcDb7nH\n         3Bwx0aWS/VjeqIHogj7PIm6Z+jpVSQwVJwx9tR94K/C3JYVty+kxCQ4TadJvmnIfXXNu\n         50nw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776738090; x=1777342890;\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=AHmsLfWP4VqB6EidVCtZitT2oU+Ddzspq2XDJx69+hM=;\n        b=RDTz068SRIknMN2k6A295xhO3PTuhUQvPsnZB6SI++Df061TCusrauU8SUxgymVB6s\n         6S4HSOJtAKGzp/pfcvMOL7MA7FCm7pRul4hbA/5uIedfWyQLeM9KPp6ol28ON7x1f6Wk\n         /tDyuf4OX2zqMQg6vRT9waljTL3Ly+B0r/7XYeH8AfXcTdrHyf6aGmteKoPuG16bu/qo\n         do23kmQuiPVk9DIDYd+vh62DeuKJgg4bO+vuZtFNaOS/13lqdoEEb6Nx2C+VViiv6uij\n         YT6yl0zx0QvP4bC4cGhlzSSjUTzyCp27mvzwERnmb6azZmMKCuU06xmjqePo1D1u9pFA\n         0tIw==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8cNW8aBaqsM+nH4bIxcJaYzu/K17Hey4r10h5ON5nt7CGXYVNk/cIBKS7Wcqs3pI2OkrNVBEmtI59kS/A=@lists.ozlabs.org","X-Gm-Message-State":"AOJu0Yyl59T8W52t9gH6obR/DVf4lb1yi+C/Sppv15pEy/MKbGsc6Bde\n\tkMUYuxbs+1kwt25x5/psqD0BDdSz5/jO11uDpIhwSf6qV2OWHyBY9TvT392tknHHDR0=","X-Gm-Gg":"AeBDiesx3ReoBRMU2ZzxU6RJQJhF4yZGscAfUaLKTe0NhqmSpZ/F6FspBmuoEvZBBoW\n\t3YqV3emr8rArHk9XS+RGGAGYZTjW1xeGaQgwsukA8JHRVwFWSaQ3ZMfVjLox16T0qS+dLGLoldU\n\t2SZzT80S+Cd9IXPdX+He/gWnMJZ6OAxTjFJ4GMuWG2XZKzYb5TZDIFrMVPGYsveKTPuJgcgnOIk\n\tY1y75mLfBqR8dSw7WquI9lTfIJMt96Ki3e49FeT8C6qOzRRcSDkacYpVV8KVZgQS34ckaL9keHa\n\tv0UVHvsBESwUrXwJJEPRCw6b8KdV+Ai3lm38AyUsW4dIPSzBoiqnkjkCrnX+NIfmp68mkzD1zic\n\tvB/+iLqwBn41tpFSYjEinBOSKtJCoR45LqpAkPLdbXRnjmLQ+CDfhnM3pR5uQzRh9cJ+nNatiFS\n\t/xRODmNtrJ2uHsYELuz1INJEOYyhRLEmmYZqf2pnQ=","X-Received":"by 2002:a05:6a00:2993:b0:82a:6461:6d1e with SMTP id\n d2e1a72fcca58-82f8c92a5fbmr15190526b3a.46.1776738089510;\n        Mon, 20 Apr 2026 19:21:29 -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\tMike Rapoport <rppt@kernel.org>,\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>,\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 v3 4/4] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE\n compound pages","Date":"Tue, 21 Apr 2026 10:20:44 +0800","Message-Id":"<20260421022044.1217503-5-songmuchun@bytedance.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20260421022044.1217503-1-songmuchun@bytedance.com>","References":"<20260421022044.1217503-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>\n---\n mm/mm_init.c | 43 ++++++++++++++++++++++++++++---------------\n 1 file changed, 28 insertions(+), 15 deletions(-)","diff":"diff --git a/mm/mm_init.c b/mm/mm_init.c\nindex f9f8e1af921c..e2d8eae23aa3 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,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 +1130,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":["v3","4/4"]}