{"id":2219971,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2219971/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260405125240.2558577-47-songmuchun@bytedance.com/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/1.2/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":"<20260405125240.2558577-47-songmuchun@bytedance.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20260405125240.2558577-47-songmuchun@bytedance.com/","date":"2026-04-05T12:52:37","name":"[46/49] mm/sparse: replace pgmap with order and zone in sparse_add_section()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b3919f4e548f8f0dac45f0958e23e2dbf778ee8e","submitter":{"id":78930,"url":"http://patchwork.ozlabs.org/api/1.2/people/78930/?format=json","name":"Muchun Song","email":"songmuchun@bytedance.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260405125240.2558577-47-songmuchun@bytedance.com/mbox/","series":[{"id":498783,"url":"http://patchwork.ozlabs.org/api/1.2/series/498783/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=498783","date":"2026-04-05T12:51:51","name":"mm: Generalize vmemmap optimization for DAX and HugeTLB","version":1,"mbox":"http://patchwork.ozlabs.org/series/498783/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219971/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219971/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linuxppc-dev+bounces-19376-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=EF6hbLDd;\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-19376-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::1031\"","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=EF6hbLDd;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com\n (client-ip=2607:f8b0:4864:20::1031; helo=mail-pj1-x1031.google.com;\n envelope-from=songmuchun@bytedance.com; 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)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fpXZr0Jjpz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 05 Apr 2026 22:58:44 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fpXZh66Yrz3fFT;\n\tSun, 05 Apr 2026 22:58:36 +1000 (AEST)","from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com\n [IPv6:2607:f8b0:4864:20::1031])\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 4fpXZh03ntz304l\n\tfor <linuxppc-dev@lists.ozlabs.org>; Sun, 05 Apr 2026 22:58:35 +1000 (AEST)","by mail-pj1-x1031.google.com with SMTP id\n 98e67ed59e1d1-35d99bae2ebso2819991a91.3\n        for <linuxppc-dev@lists.ozlabs.org>;\n Sun, 05 Apr 2026 05:58:35 -0700 (PDT)","from n232-176-004.byted.org ([36.110.163.97])\n        by smtp.gmail.com with ESMTPSA id\n 98e67ed59e1d1-35de66b4808sm3748505a91.2.2026.04.05.05.58.27\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Sun, 05 Apr 2026 05:58:33 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775393916;\n\tcv=none;\n b=m6xP/gKIIRsEulHcvyWb5cJMup70bYrMWUv6WuE3N5osD6tZYyiErC69x5tbJJkWs8CIkUd+cGGyK0m28EjvWDrddgP3c69RWhD0ZEz93xT9LnfyeKDS+/yBcqrpTXzonZ5AVulakiBJpuBXWAwrM+fAwz/sRCNr2/ThbTL5Tt089j7sc+h+TlxLDbFUz15t2EMV9dVFrug2ss2wG7g0UnLK4x2CYl0Jnoyszcs3vJNoqRH0AVUKTYhQAy4V35ktLscmtESgPi29ZC1lgidSpvzJEJSv3edQdYJbAfe4FtZsSKA9RQ1A7eJYD06x4TbvcXm4ol/3TmVOcm0S2zNUTg==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1775393916; c=relaxed/relaxed;\n\tbh=64qVqbFMPmvyYt7CQKJ/AlutLuZCqUEnEB7XrUuUTaU=;\n\th=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n\t MIME-Version;\n b=O5JybHAutBCNg6fovRnj9nQ3GC1pHu3Fin5LIX1KRTmQsSU3Sy/ys1D4wF+mv6wIPe8YjiKIJRQfJ4e1Rx5MUCSVuowGrRSmIoEJ3nVIiQmcvN2g2LKUeeUFodg3KwRMwa1Ms1RgS2B5gpR370RTG4rkm2i93N5P4qimptaSAFePTv3idDMLMHThyYZNCCYmGx1x5ME3a/ZGbdO5zkvHjaqI8mAJNLuQu6/cJRVya881qlw1v2Z9CDlTng9jfzM8d93Hv1hkDaXm92ZzbJkAaP8l1a+MJXObwvtJ021vc9vzQOalT6jOlIUuI/Gz+lcVK15jCPsnTMRaTlT8QDGc0Q==","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=EF6hbLDd; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::1031; helo=mail-pj1-x1031.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=1775393914; x=1775998714;\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=64qVqbFMPmvyYt7CQKJ/AlutLuZCqUEnEB7XrUuUTaU=;\n        b=EF6hbLDdWNNqQhearDhoy6QVgLa3411Ugbk+oA29oVka6fHjRKVpksIs/8eaPZy8PB\n         ufMFyE9PQyGyHZJRuMPOrUmBKfYnW86yStv/M5zqoo+MB2Dw9BKMpxJe1lw+5ma/EUzS\n         XHab3IL+cuxZeCWVPEWRqO0NX84jV+64pzsUoKwsHWSc9WyRSCMLyCwRSTuq7asvbtJ5\n         fNmP5WuKm0JUw8uN1UiGV+74fTnk/dX6rMw7oEpk395PPC2TCS3+g2mjSdpdu7Crcorj\n         z0gvhWe88yaPD4jGsaN4Rb+USz2V4PAD72Nt52qLeb27GHkhOlIeKTBIEjWXn+TjL+1y\n         tcbw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775393914; x=1775998714;\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=64qVqbFMPmvyYt7CQKJ/AlutLuZCqUEnEB7XrUuUTaU=;\n        b=cJFRFP5j2fLVPnOebXBhvD5Sbk6R/Z4U2tHREfkczWV3/aqRlAPz8GXe11ti/U0wtv\n         AgY/14OF/W0bhybn8Fj1h/UMPV4xzPMeJlEF8YO8cwcwSl+enaKjPz3RDC6D2e69tQyQ\n         QXIU10KsWsM2I2trEuLBC3mOwYD1D7LyID+Nv7zMvOfzS76ZWEgAnkT4EZH/9KmD0AKw\n         BBBA0nUz2P4GVsFqSM3MtUtHRhKAhAFrojqJ6kSm+USwlouzR/fOTXvn3tbDeaOzPy+k\n         RVc+g1QzFA/4WAQ3PA5vkOFN032XAXLwNi6UXwnGIX6gk/aIkFE2su8hfkIiTY8lwvbl\n         sHLA==","X-Forwarded-Encrypted":"i=1;\n AJvYcCXUst0X9nhCiiqzyTPD1zqr6QxR8YVJ+eKRUmmW3L8SmwA+FjQKrYMTRhBuzGwyclpluQNZ28+Aqk+LmsU=@lists.ozlabs.org","X-Gm-Message-State":"AOJu0YxZorRnuou1GQ1WwIxCDjos7djdOtM+8GhSl43J9L0R8mybMh1e\n\tSNKMw0W9fuA4HhUin+lmuJXXfNKpGGgweZFSUObuRyCqzh7RiX5IxvvHKacrlBC9thI=","X-Gm-Gg":"AeBDiesi9riMc7tufcRVQIqMO8GGoTyhU8g8fUXdsK3C5lfzaixGzMQwyHnNoN4c0pb\n\tvQq4ttBr8DlPoA5qZZKWvq+np0NwfZVqB+EEfQiwVfHZOhykDRcJ/Uun+Wi0ofRDND+V8wGWCFF\n\tNefeHWUrAA2hy2Z2xqQ2PyCV/scmb6FZK8n9z4L+dLYbwBCl4DOH3TWP8t/xvmrrEt4BsrEhP6Y\n\tABh2y8bgFKdK1lJkql2aOsQgEmV3YOBoNH6iGqCoOxKaatALKu/qC6Fls290IKFBecEGX5a19ij\n\taJc9p3Dd23v7MPTp7OpntgqmQQOS0mxokrQzhDJWRRN0uIEp2MqLiihnhDIJdl0GKGZfg2HNqzQ\n\tFUym2AddKiwSr4tYmPzkMXXFavD5wIwW+y/7LN8OpIA7JO0RJuGLFWkov/yaGRHh9ZdxNhH8F72\n\t0uRybwOgZJVKhSBTKwUXBtHL1aiIWtU64387cb+wJPFOk=","X-Received":"by 2002:a17:90b:55cb:b0:35b:b52d:f34d with SMTP id\n 98e67ed59e1d1-35de679faa8mr8791452a91.5.1775393913904;\n        Sun, 05 Apr 2026 05:58:33 -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":"Lorenzo 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,\n\tMuchun Song <songmuchun@bytedance.com>","Subject":"[PATCH 46/49] mm/sparse: replace pgmap with order and zone in\n sparse_add_section()","Date":"Sun,  5 Apr 2026 20:52:37 +0800","Message-Id":"<20260405125240.2558577-47-songmuchun@bytedance.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20260405125240.2558577-1-songmuchun@bytedance.com>","References":"<20260405125240.2558577-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 sparse_add_section() function was using the struct dev_pagemap\nargument only to extract the vmemmap_shift value to set the compound\npage order for vmemmap optimization, and to set the zone to ZONE_DEVICE.\n\nSince the full struct dev_pagemap is not needed here and is being\nremoved from the rest of the vmemmap APIs, replace the pgmap parameter\nwith direct order and zone parameters in sparse_add_section().\n\nThis cleanly decouples the sparse memory infrastructure from the\nZONE_DEVICE struct dev_pagemap. The main motivation behind this decouple\nis to make sparse_add_section() a more generic memory population interface\nthat can be easily reused for other non ZONE_DEVICE population use cases\nin the future.\n\nSigned-off-by: Muchun Song <songmuchun@bytedance.com>\n---\n include/linux/memory_hotplug.h |  2 +-\n mm/memory_hotplug.c            | 10 ++++++++--\n mm/sparse-vmemmap.c            | 14 +++++++-------\n 3 files changed, 16 insertions(+), 10 deletions(-)","diff":"diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h\nindex 815e908c4135..089052d64b01 100644\n--- a/include/linux/memory_hotplug.h\n+++ b/include/linux/memory_hotplug.h\n@@ -305,7 +305,7 @@ extern void remove_pfn_range_from_zone(struct zone *zone,\n \t\t\t\t       unsigned long nr_pages);\n extern int sparse_add_section(int nid, unsigned long pfn,\n \t\tunsigned long nr_pages, struct vmem_altmap *altmap,\n-\t\tstruct dev_pagemap *pgmap);\n+\t\tunsigned int order, enum zone_type zone);\n extern void sparse_remove_section(unsigned long pfn, unsigned long nr_pages,\n \t\t\t\t  struct vmem_altmap *altmap);\n extern struct zone *zone_for_pfn_range(enum mmop online_type,\ndiff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c\nindex 68dd56dd9f74..0f7707f3d4bb 100644\n--- a/mm/memory_hotplug.c\n+++ b/mm/memory_hotplug.c\n@@ -385,10 +385,17 @@ int __add_pages(int nid, unsigned long pfn, unsigned long nr_pages,\n \tunsigned long cur_nr_pages;\n \tint err;\n \tstruct vmem_altmap *altmap = params->altmap;\n+\tunsigned int order = params->pgmap ? params->pgmap->vmemmap_shift : 0;\n+\tenum zone_type zid = 0;\n \n \tif (WARN_ON_ONCE(!pgprot_val(params->pgprot)))\n \t\treturn -EINVAL;\n \n+#ifdef CONFIG_ZONE_DEVICE\n+\tif (params->pgmap)\n+\t\tzid = ZONE_DEVICE;\n+#endif\n+\n \tVM_BUG_ON(!mhp_range_allowed(PFN_PHYS(pfn), nr_pages * PAGE_SIZE, false));\n \n \tif (altmap) {\n@@ -412,8 +419,7 @@ int __add_pages(int nid, unsigned long pfn, unsigned long nr_pages,\n \t\t/* Select all remaining pages up to the next section boundary */\n \t\tcur_nr_pages = min(end_pfn - pfn,\n \t\t\t\t   SECTION_ALIGN_UP(pfn + 1) - pfn);\n-\t\terr = sparse_add_section(nid, pfn, cur_nr_pages, altmap,\n-\t\t\t\t\t params->pgmap);\n+\t\terr = sparse_add_section(nid, pfn, cur_nr_pages, altmap, order, zid);\n \t\tif (err)\n \t\t\tbreak;\n \t\tcond_resched();\ndiff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c\nindex 68dcc52591d5..894352cb8957 100644\n--- a/mm/sparse-vmemmap.c\n+++ b/mm/sparse-vmemmap.c\n@@ -666,7 +666,8 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn,\n  * @start_pfn: start pfn of the memory range\n  * @nr_pages: number of pfns to add in the section\n  * @altmap: alternate pfns to allocate the memmap backing store\n- * @pgmap: alternate compound page geometry for devmap mappings\n+ * @order: section order\n+ * @zone: section zone. Note that it is ignored when @order is 0.\n  *\n  * This is only intended for hotplug.\n  *\n@@ -681,7 +682,7 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn,\n  */\n int __meminit sparse_add_section(int nid, unsigned long start_pfn,\n \t\tunsigned long nr_pages, struct vmem_altmap *altmap,\n-\t\tstruct dev_pagemap *pgmap)\n+\t\tunsigned int order, enum zone_type zone)\n {\n \tunsigned long section_nr = pfn_to_section_nr(start_pfn);\n \tstruct mem_section *ms;\n@@ -693,11 +694,10 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,\n \t\treturn ret;\n \n \tms = __nr_to_section(section_nr);\n-\tif (!altmap && pgmap && nr_pages == PAGES_PER_SECTION) {\n-\t\tsection_set_order(ms, pgmap->vmemmap_shift);\n-#ifdef CONFIG_ZONE_DEVICE\n-\t\tsection_set_zone(ms, ZONE_DEVICE);\n-#endif\n+\t/* HVO is not supported when memmap pages are backed by an altmap. */\n+\tif (!altmap && nr_pages == PAGES_PER_SECTION && order) {\n+\t\tsection_set_order(ms, order);\n+\t\tsection_set_zone(ms, zone);\n \t}\n \tmemmap = section_activate(nid, start_pfn, nr_pages, altmap);\n \tif (IS_ERR(memmap))\n","prefixes":["46/49"]}