{"id":2219947,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2219947/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260405125240.2558577-23-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-23-songmuchun@bytedance.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20260405125240.2558577-23-songmuchun@bytedance.com/","date":"2026-04-05T12:52:13","name":"[22/49] mm/sparse: introduce compound page order to mem_section","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a896b56952d86bc62a75bfadcf5cb47028216c77","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-23-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/2219947/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219947/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linuxppc-dev+bounces-19352-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=G1kwqW+l;\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-19352-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::1033\"","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=G1kwqW+l;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com\n (client-ip=2607:f8b0:4864:20::1033; helo=mail-pj1-x1033.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 4fpXWf6QtDz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 05 Apr 2026 22:55:58 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fpXWT2FPtz2ytT;\n\tSun, 05 Apr 2026 22:55:49 +1000 (AEST)","from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com\n [IPv6:2607:f8b0:4864:20::1033])\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 4fpXWS4Wmfz2ytJ\n\tfor <linuxppc-dev@lists.ozlabs.org>; Sun, 05 Apr 2026 22:55:48 +1000 (AEST)","by mail-pj1-x1033.google.com with SMTP id\n 98e67ed59e1d1-356337f058aso1639117a91.2\n        for <linuxppc-dev@lists.ozlabs.org>;\n Sun, 05 Apr 2026 05:55:48 -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.55.39\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Sun, 05 Apr 2026 05:55:46 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775393749;\n\tcv=none;\n b=S4aXtQcxDIzBA89dCFwotGNtelLccnrGQpDo5/3zDfjFgdD6vj4XxZahR87Jx/f7+EjZU83rJR6ndqX4bXQxMm89RfOVOJA35o7GCshOIKJCQSMDJ9Fz/nTl6maEiAmofJ25O6868FovKJT/ZcYfkxt8gbaBe0wxumMrkxCUKKUtZnwK/E2yf61V2k6C8ByM89b9sSBx44XCaZ3vU0idU2XTYrOTu+nUwuEya3mGNPKwEv/RnmWGiU/h8NANUhTGHz+ZBSpHDiXebxtKnI8Zk7zo/lJms1GtOg2G9T+NsWjXNpO6l8u0080KUjocUElmQ581GZ9j+g3Z3wEIRMtsQA==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1775393749; c=relaxed/relaxed;\n\tbh=sb6cTU6E76tVxQHa/I/Ro9Ws0lLMXSEWXuSGv9owj/A=;\n\th=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n\t MIME-Version;\n b=AmLrlL5S0IzZJFjoxWrO4IkNDL1mXY01ZN+zx/uh0AQxeq+VvnQZHrM1tZdT1de6ZFdM7EUx189CQb2jVhGhnXDyhg6onfj9G0y7UFecRCn1KTR4Q+zJs3yfqeAAamaOmRfbyuAVoCvaPRYTa2bYL/8C8bE1QWybC7/kFPTRPlsF+fVClL0MQMByrlVbnTtfAtIJ+23MSEw7Zu2BeNYVX4EnEQhJ7Zu98/k3m9pwonsFr7m0em1Fsxb0jpVXADH6tUrVz5bVxEFRjyyOwpE/N6hk5aDLV5NxPbTZ2rJBNPQ26/MNqGy3PGl6HOAsmOxl9XmsGGTxVpZAqu1Bt4welg==","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=G1kwqW+l; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::1033; helo=mail-pj1-x1033.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=1775393746; x=1775998546;\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=sb6cTU6E76tVxQHa/I/Ro9Ws0lLMXSEWXuSGv9owj/A=;\n        b=G1kwqW+lvn43MrVM6h7cGLAt3088LJ45Xvu+LAbfxWRlT93P6azz6gBasVMqT5wigL\n         HhhKX1m1oHwJOCxzALu/50pVJtW7foxBc+HBLciLLdyFFkVV62WB4NpSwrYMgdEQAhUi\n         pTYDKRn+U8LWpjpntKUd0DH9/81/LJhI9NIcX1z/heVke9QTPJ8kl4dBjMsWZjzKajOE\n         zosXW0a0DaCcJfopHTXDvQlb2Ef8CiWU+68OAyV82Go8gqti6BkLcTn5utTgB4VJ5EIW\n         dwawVecgPYn/INK5ko9wNAVF7cHOtfloRyOx+jvSyKjyCRFRlo6ZDGYaUCZWyABdJeZW\n         //iw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775393746; x=1775998546;\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=sb6cTU6E76tVxQHa/I/Ro9Ws0lLMXSEWXuSGv9owj/A=;\n        b=dlyTOiISZpbCASRoFxyGLjDJOY8UO4KgOkKd0pPSfyHJSOTvH4NGpvumVJrcreu5mj\n         7crP3yD5mxUmten20Q3osAyDAKFP0RZUe987RE9idC3if3Ty3ZfC2x7xvU582/A8z1zy\n         q5TXLY0DiKfRZ6YSNXLSDG0EJQrUNJe5s5Nt28d2KjxdkhAfn+4xL0KVodW1mZ/hr/5/\n         oupacoj5M3g6MFmXpLLvdPpm7a8QWTGbTG5Smhfdi9sU0mtetW7J2wJrz6fWuZQY7ELM\n         YXqHqXOMm1K0mnVutMl7zgSRVIuKjlTqAOxBQgFKCFZbx9SyqDToAYdx9olK7UpNKgvs\n         M+kQ==","X-Forwarded-Encrypted":"i=1;\n AJvYcCVaCjf1qX3etPur9wqOeqqzTmRkJfeRv0TAMyRDy2newcCGmTzpu6tE4WpoCjPMPOCuWAKYakW5k6pwpLA=@lists.ozlabs.org","X-Gm-Message-State":"AOJu0YzjCNxZN2uYGkZqCfIkZwRhkicJbY/amKW82EUzV7537dPC7sjX\n\tfGFVob1QClwl6y+V2dZmGdvvxcOTlv4PzGOBGHgTICyaFxmF6iS3uNcNyJYJcr9Syd8=","X-Gm-Gg":"AeBDietqmOmeEQW/Ajm9Nov8wwpoJyo6dKO/P5O4jq+mPK1Uu9H3jItrt8QNARtIYiH\n\t/PrMkc+Ld0Zzw4EUgAXp5pQZaYLwfP/7F1dOaYtRZp66R/KwX4O9mVOTp/PiBJNbeQV5CqSDVoE\n\tWXp0h5BHqtFQJRDAQC4/cZU8oVgkiR0sYa8j0Q2S1rnrkB1uhCBrpj9/wOl1NI+y0jzz/DOF4mJ\n\t9bS0vrqNSsGeTsGlUQfIv/nFHzq3BGmtugpM58B/xTUtrfeXs4zb5fPmpWjt0YT8CwWn/7AGn+p\n\tJYO+dGImrTwK08ypG8W+9A0A3anSM/r67zqt1SHk8HxnK6lbHyT8q1F57J1FXK93G4XzD5kFLkp\n\tjVyqxuyCvr2Ym3TVKhag4x/inVaU9UQgcXnAPnY+TWTpOgsjAgRZsV6mfcV/7lY1k+NyWU5G2/0\n\todh3RBLqvX0WtW+LwmeLCfQBcz9e4fFMryia7S3sUdzLs=","X-Received":"by 2002:a17:90b:2ccc:b0:35d:a0b7:9608 with SMTP id\n 98e67ed59e1d1-35de67dc7d4mr8298573a91.7.1775393746346;\n        Sun, 05 Apr 2026 05:55:46 -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 22/49] mm/sparse: introduce compound page order to mem_section","Date":"Sun,  5 Apr 2026 20:52:13 +0800","Message-Id":"<20260405125240.2558577-23-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":"During early system boot and DAX device initialization, the establishment\nof vmemmap page mappings via __populate_section_memmap() is done on a\nper-section basis, followed by the initialization of the struct page area.\n\nCurrently, there are two scenarios utilizing HugeTLB Vmemmap Optimization\n(HVO): HugeTLB and DAX.\n\nFor HugeTLB, the SPARSEMEM_VMEMMAP_PREINIT mechanism is used to apply HVO\n(with Read-Write mappings), and later, vmemmap_wrprotect_hvo() is used to\nenforce Read-Only mappings. HugeTLB has to manage its own related statistics\nand metadata updates; the work done by hugetlb_vmemmap_init_early() is\nsomewhat similar to what sparse_init_nid() does. Furthermore, the shared\nvmemmap tail pages allocated by vmemmap_get_tail() are left uninitialized\nbecause they would be overwritten by the subsequent memmap_init(). We are\nforced to compensate for this in hugetlb_vmemmap_init(). This limitation\nalso forces us to maintain two separate implementations of vmemmap_get_tail()\n(one in hugetlb_vmemmap.c and another in sparse-vmemmap.c).\n\nFor DAX, HVO is already applied via __populate_section_memmap(), but it\ndoes not employ Read-Only mappings, which introduces potential security\nrisks. Moreover, the fact that HugeTLB and DAX implement different logics\nfor what is essentially the same purpose increases code complexity and\nmaintenance burden.\n\nThe root cause of these issues is that a memory section is completely unaware\nof the concept of compound pages. It cannot properly handle HVO or struct\npage initialization for them.\n\nTo solve this, introduce the concept of compound page order to the memory\nsection (`struct mem_section`). Typically, a section holds compound pages\nof a specific order, and a larger compound page will span multiple sections.\nIn the future, this order information can be utilized to unify and streamline\nthe aforementioned scenarios.\n\nSigned-off-by: Muchun Song <songmuchun@bytedance.com>\n---\n include/linux/mmzone.h | 28 ++++++++++++++++++++++++++++\n 1 file changed, 28 insertions(+)","diff":"diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h\nindex 3e3755666846..620503aa29ba 100644\n--- a/include/linux/mmzone.h\n+++ b/include/linux/mmzone.h\n@@ -2014,6 +2014,14 @@ struct mem_section {\n \t */\n \tstruct page_ext *page_ext;\n #endif\n+#ifdef CONFIG_SPARSEMEM_VMEMMAP\n+\t/*\n+\t * The order of compound pages in this section. Typically, the section\n+\t * holds compound pages of this order; a larger compound page will span\n+\t * multiple sections.\n+\t */\n+\tunsigned int order;\n+#endif\n };\n \n #ifdef CONFIG_SPARSEMEM_EXTREME\n@@ -2210,6 +2218,17 @@ static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long\n \t*pfn = (*pfn & PAGE_SECTION_MASK) + (bit * PAGES_PER_SUBSECTION);\n \treturn true;\n }\n+\n+static inline void section_set_order(struct mem_section *section, unsigned int order)\n+{\n+\tVM_BUG_ON(section->order && order && section->order != order);\n+\tsection->order = order;\n+}\n+\n+static inline unsigned int section_order(const struct mem_section *section)\n+{\n+\treturn section->order;\n+}\n #else\n static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)\n {\n@@ -2220,6 +2239,15 @@ static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long\n {\n \treturn true;\n }\n+\n+static inline void section_set_order(struct mem_section *section, unsigned int order)\n+{\n+}\n+\n+static inline unsigned int section_order(const struct mem_section *section)\n+{\n+\treturn 0;\n+}\n #endif\n \n void sparse_init_early_section(int nid, struct page *map, unsigned long pnum,\n","prefixes":["22/49"]}