{"id":2219958,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2219958/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260405125240.2558577-34-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-34-songmuchun@bytedance.com>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20260405125240.2558577-34-songmuchun@bytedance.com/","date":"2026-04-05T12:52:24","name":"[33/49] mm: introduce CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"24f1f66db2f8090021a8fecf9265d16665ed94d2","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-34-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/2219958/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219958/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linuxppc-dev+bounces-19363-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=f3I2oSYh;\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-19363-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::102b\"","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=f3I2oSYh;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com\n (client-ip=2607:f8b0:4864:20::102b; helo=mail-pj1-x102b.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 4fpXY718Qcz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 05 Apr 2026 22:57:15 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fpXXs1rY8z2yvQ;\n\tSun, 05 Apr 2026 22:57:01 +1000 (AEST)","from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com\n [IPv6:2607:f8b0:4864:20::102b])\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 4fpXXr3f9Cz2ynZ\n\tfor <linuxppc-dev@lists.ozlabs.org>; Sun, 05 Apr 2026 22:57:00 +1000 (AEST)","by mail-pj1-x102b.google.com with SMTP id\n 98e67ed59e1d1-35d99031e4eso1813599a91.1\n        for <linuxppc-dev@lists.ozlabs.org>;\n Sun, 05 Apr 2026 05:57:00 -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.56.52\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Sun, 05 Apr 2026 05:56:58 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775393821;\n\tcv=none;\n b=FuLY39of4cvDlPy7CSBlZGNJTFmn3IbiwBspshm5BlGxSvOC2wAZBwFULnogIJDY2CEjUHY8qqqcWRi9UaJDXHpox5FvRwRg7P8n0TOwhsBoA42Q7mfaQ0tUfINPBjgDHHYFN9gHja6LOjKBmDLvxj8clfWWSlFM+HvvXp0JtCCZSBb6UW+dCFwhjTBjKML1dR4QetEedbTf2hyk3uhWfZx+ly7N58NH9R9TxJ3AlhVdPzZKt7PJ1+w3MWnY2uWhOlOwbkjzggs1xy1YmtNAAOAIDh93ldMfvFA4UrSdJ2qnVxhGFyHOCmeev0RU/KF5uHJxZLFf/H7A4Z5ZFBjBWw==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1775393821; c=relaxed/relaxed;\n\tbh=6htym6+MXjsCESpIggFByDAobBonwD3F5r0quJbwaas=;\n\th=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n\t MIME-Version;\n b=K80PMzhukExQWAKG3rKAgdWxNY+EAsB1clTFeRJN3MTS+qjBk0+YUHeJS3Ci1EeXuOLb8yGA1ch2EOh+f1t7lP9L/EUfB1PVFS2IXjMyvkGj/UnEK+HcbBZNxZQRDfoT/GeXagyYhOkok1SosCbZNaIZ6m4EnMsisqBdRJ99CONdJaoxr0ViD7S5ANIuxrfTibZtpyCjTDmxlTNgQJFaWmklJnvFpwIFVxUDinip5+fLciFqugKbjJUPr4Su/fMnwn13xXdxC3eIsO9ts4W4J+kh3bsxY99gADXTUgDG/Lcly0b7r6TJvKC1cWwZ+/q700/b51uC0bNRO0gtQuggcQ==","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=f3I2oSYh; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::102b; helo=mail-pj1-x102b.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=1775393818; x=1775998618;\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=6htym6+MXjsCESpIggFByDAobBonwD3F5r0quJbwaas=;\n        b=f3I2oSYh6YlYVoPt6PqKBii6QNvlHfe2qUPRKdvxOQvuhN/o0gTYN6zR4lcUmw31DC\n         VhLswxNFx8/PW8i0+rVShL/2Ub+XX5Bllahbor8+T1TzJOvM5jFwNDfazhBiyfo2M2hH\n         LOP5keCvuys+GaJ/VnBTPfQb0fRII9U5vM5C1kjxgHwlyjhGw2Xd2VHY9OVDK1F09Si1\n         aaNgp2mbHJA/T9iSSx21qVh2Ol+r7IhgF1Nfdv/M+EQmAmt34eQFxuBfPJ0U/ez2XMu2\n         TiwBFVZm7jKGVhha2Hx/NyGxR3e/T5AkApzNGsUyvMtW0dbXBXMn3IeiNgIv0SaCEKC9\n         J4Rw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775393818; x=1775998618;\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=6htym6+MXjsCESpIggFByDAobBonwD3F5r0quJbwaas=;\n        b=CgVH9ZNoy9wu3wFzgVrcLnn3HJ3GOur5EzyQyEMU6qRXcxmCWdneSI6fObr904Ifwp\n         xi1EMLVyi+taumyHWWIP5YKBpzzX6RCMYKfdtX7ZfDsili4bNRiVDaknjJwZaoeaqLhh\n         xRfUzwbrPRonbFv9vSB+nJZ3oFqjOba59IChUfSaGmTO2bPIEc3lFV9xjpf6lwdQlE7p\n         kyNQ4y6gqdZdWfyFsTZYjeP0DUpszJflIIbOlT3ysfpDBc4c8oR5iAghCCXUF6oUFlh8\n         H9m/f0e35pkMpFYxnS7SPxWQ9kpiEBUtm87y8nz9ca4+BANZlo7B1oRIIKGRrh6ax6Rd\n         JwvQ==","X-Forwarded-Encrypted":"i=1;\n AJvYcCXCZOv3jSQsGLwOtrj7z7Ob9P+pgMezzphDMlhnhKPGDfYXLpw8VpiqF4gtEHmgQIJoTnG9JydJCvsu570=@lists.ozlabs.org","X-Gm-Message-State":"AOJu0YwceS039XZ0kA0oafSHq7+IoYFrHOKkr0k1O8pSlnm4y4REjg0D\n\toNaLmXbZvLrnY91lE1PRllUhW3YcunUeRErvHdMtOXvL/9PdlYW6sKS66WZ+oRwbc0o=","X-Gm-Gg":"AeBDieuq6vZl982t1s30FCozZCjmYAvGVFgOs28NsP/RTnZknOixkU6nPgvQe0BiFml\n\t1xx+zG7CLmST8ALBwSCnlS01Sm2OStI0+bYXrAuj3JlVxWnpQGbQEMLRoCu/9oBvZSexKKpn0aI\n\tbblDfsJJ/NKzNHqYvPojpRQbMuhg0c1bouQyllvaTeEbLkhaXeoDuzftIfLPF2dLQy5rEi+i5SY\n\tsriPT8ldDx2EiRP4GmqUzKwMM7Z51E3SQMMs3cur1dyzn70qq62pMavOkJyRLle4N9Gp/TfoTKq\n\t7uAiOzC61rjbTRWeh2HioHOof07FuNUVomctjslCEuDkBTH/F3B1cxP9k/woMLTtxjlU+94Uc7H\n\tCbNkoVj8hvUDn5lcPyHVT1uS1InU30esL4EGd2WV/k1W5JP4kLjBwWZgf1VoLRSs1q8CiYL5xRi\n\tcfnEluAwTWqwNev06M8XazEGwy/4Behk51JwneRwMTCwk=","X-Received":"by 2002:a17:90b:3809:b0:35d:9560:3efc with SMTP id\n 98e67ed59e1d1-35de68ce84bmr7967133a91.14.1775393818406;\n        Sun, 05 Apr 2026 05:56:58 -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 33/49] mm: introduce CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION","Date":"Sun,  5 Apr 2026 20:52:24 +0800","Message-Id":"<20260405125240.2558577-34-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":"Previously, the vmemmap optimization logic in mm/sparse-vmemmap.c was\nclosely tied to HugeTLB via CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP.\nWith recent refactoring (e.g., introducing compound page order to struct\nmem_section), the core vmemmap optimization machinery has become more\ngeneric and can be utilized by other subsystems like DAX.\n\nTo reflect this generalization and decouple the core optimization logic\nfrom HugeTLB-specific configurations, this patch introduces a new common\nKconfig option: CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION.\n\nBoth HugeTLB and DAX now select this generic option, ensuring that the\nshared optimization infrastructure is enabled whenever either subsystem\nrequires it.\n\nSigned-off-by: Muchun Song <songmuchun@bytedance.com>\n---\n fs/Kconfig                 |  1 +\n include/linux/mmzone.h     | 33 ++++++++++++++++++---------------\n include/linux/page-flags.h |  5 +----\n mm/Kconfig                 |  5 +++++\n 4 files changed, 25 insertions(+), 19 deletions(-)","diff":"diff --git a/fs/Kconfig b/fs/Kconfig\nindex e70aa5f0429a..9b56a90e13db 100644\n--- a/fs/Kconfig\n+++ b/fs/Kconfig\n@@ -278,6 +278,7 @@ config HUGETLB_PAGE_OPTIMIZE_VMEMMAP\n \tdef_bool HUGETLB_PAGE\n \tdepends on ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP\n \tdepends on SPARSEMEM_VMEMMAP\n+\tselect SPARSEMEM_VMEMMAP_OPTIMIZATION\n \n config HUGETLB_PMD_PAGE_TABLE_SHARING\n \tdef_bool HUGETLB_PAGE\ndiff --git a/include/linux/mmzone.h b/include/linux/mmzone.h\nindex 75425407e0c4..6edcb0cc46c4 100644\n--- a/include/linux/mmzone.h\n+++ b/include/linux/mmzone.h\n@@ -102,9 +102,9 @@\n  *\n  * HVO which is only active if the size of struct page is a power of 2.\n  */\n-#define MAX_FOLIO_VMEMMAP_ALIGN \\\n-\t(IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP) && \\\n-\t is_power_of_2(sizeof(struct page)) ? \\\n+#define MAX_FOLIO_VMEMMAP_ALIGN\t\t\t\t\t\\\n+\t(IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION) &&\t\\\n+\t is_power_of_2(sizeof(struct page)) ?\t\t\t\\\n \t MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0)\n \n /* The number of vmemmap pages required by a vmemmap-optimized folio. */\n@@ -115,7 +115,8 @@\n \n #define __NR_OPTIMIZABLE_FOLIO_SIZES\t\t(MAX_FOLIO_ORDER - OPTIMIZABLE_FOLIO_MIN_ORDER + 1)\n #define NR_OPTIMIZABLE_FOLIO_SIZES\t\t\\\n-\t(__NR_OPTIMIZABLE_FOLIO_SIZES > 0 ? __NR_OPTIMIZABLE_FOLIO_SIZES : 0)\n+\t((__NR_OPTIMIZABLE_FOLIO_SIZES > 0 &&\t\\\n+\t  IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION)) ? __NR_OPTIMIZABLE_FOLIO_SIZES : 0)\n \n enum migratetype {\n \tMIGRATE_UNMOVABLE,\n@@ -2014,7 +2015,7 @@ struct mem_section {\n \t */\n \tstruct page_ext *page_ext;\n #endif\n-#ifdef CONFIG_SPARSEMEM_VMEMMAP\n+#ifdef CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION\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@@ -2194,7 +2195,19 @@ 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+#else\n+static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)\n+{\n+\treturn 1;\n+}\n+\n+static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn)\n+{\n+\treturn true;\n+}\n+#endif\n \n+#ifdef CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION\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@@ -2206,16 +2219,6 @@ static inline unsigned int section_order(const struct mem_section *section)\n \treturn section->order;\n }\n #else\n-static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)\n-{\n-\treturn 1;\n-}\n-\n-static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn)\n-{\n-\treturn true;\n-}\n-\n static inline void section_set_order(struct mem_section *section, unsigned int order)\n {\n }\ndiff --git a/include/linux/page-flags.h b/include/linux/page-flags.h\nindex 0e03d816e8b9..12665b34586c 100644\n--- a/include/linux/page-flags.h\n+++ b/include/linux/page-flags.h\n@@ -208,14 +208,11 @@ enum pageflags {\n static __always_inline bool compound_info_has_mask(void)\n {\n \t/*\n-\t * Limit mask usage to HugeTLB vmemmap optimization (HVO) where it\n-\t * makes a difference.\n-\t *\n \t * The approach with mask would work in the wider set of conditions,\n \t * but it requires validating that struct pages are naturally aligned\n \t * for all orders up to the MAX_FOLIO_ORDER, which can be tricky.\n \t */\n-\tif (!IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP))\n+\tif (!IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION))\n \t\treturn false;\n \n \treturn is_power_of_2(sizeof(struct page));\ndiff --git a/mm/Kconfig b/mm/Kconfig\nindex 3cce862088f1..e81aa77182b2 100644\n--- a/mm/Kconfig\n+++ b/mm/Kconfig\n@@ -410,12 +410,17 @@ config SPARSEMEM_VMEMMAP\n \t  pfn_to_page and page_to_pfn operations.  This is the most\n \t  efficient option when sufficient kernel resources are available.\n \n+config SPARSEMEM_VMEMMAP_OPTIMIZATION\n+\tbool\n+\tdepends on SPARSEMEM_VMEMMAP\n+\n #\n # Select this config option from the architecture Kconfig, if it is preferred\n # to enable the feature of HugeTLB/dev_dax vmemmap optimization.\n #\n config ARCH_WANT_OPTIMIZE_DAX_VMEMMAP\n \tbool\n+\tselect SPARSEMEM_VMEMMAP_OPTIMIZATION if SPARSEMEM_VMEMMAP\n \n config ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP\n \tbool\n","prefixes":["33/49"]}