Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/2219959/?format=api
{ "id": 2219959, "url": "http://patchwork.ozlabs.org/api/1.2/patches/2219959/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260405125240.2558577-35-songmuchun@bytedance.com/", "project": { "id": 2, "url": "http://patchwork.ozlabs.org/api/1.2/projects/2/?format=api", "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-35-songmuchun@bytedance.com>", "list_archive_url": "https://lore.kernel.org/linuxppc-dev/20260405125240.2558577-35-songmuchun@bytedance.com/", "date": "2026-04-05T12:52:25", "name": "[34/49] mm/sparse-vmemmap: switch DAX to use generic vmemmap optimization", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "4d826ddd0392644694fb9d1cc90b3d35ed63c8af", "submitter": { "id": 78930, "url": "http://patchwork.ozlabs.org/api/1.2/people/78930/?format=api", "name": "Muchun Song", "email": "songmuchun@bytedance.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20260405125240.2558577-35-songmuchun@bytedance.com/mbox/", "series": [ { "id": 498783, "url": "http://patchwork.ozlabs.org/api/1.2/series/498783/?format=api", "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/2219959/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2219959/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linuxppc-dev+bounces-19364-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=VLHUY2wF;\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-19364-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::102c\"", "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=VLHUY2wF;\n\tdkim-atps=neutral", "lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=bytedance.com\n (client-ip=2607:f8b0:4864:20::102c; helo=mail-pj1-x102c.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 4fpXYF6lWbz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 05 Apr 2026 22:57:21 +1000 (AEST)", "from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fpXXy6Q1Xz2yvS;\n\tSun, 05 Apr 2026 22:57:06 +1000 (AEST)", "from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com\n [IPv6:2607:f8b0:4864:20::102c])\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 4fpXXy0dDKz2ynZ\n\tfor <linuxppc-dev@lists.ozlabs.org>; Sun, 05 Apr 2026 22:57:05 +1000 (AEST)", "by mail-pj1-x102c.google.com with SMTP id\n 98e67ed59e1d1-35c1d101355so1241815a91.1\n for <linuxppc-dev@lists.ozlabs.org>;\n Sun, 05 Apr 2026 05:57:05 -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.58\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Sun, 05 Apr 2026 05:57:03 -0700 (PDT)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775393826;\n\tcv=none;\n b=FXjJSX0GSNRVN3Yv/XiDqoTs+OTKbywm1Uv5s6DRQccOKYVy+TqdiNmsP6vyJQckurbmUuy6LC3bJbGMqUo5WRp3n+LSdy/VNrmsblUM5NcAUtwdYvUq2BuiC6FPoVvMiFMspNFG901wnk7ao83eT2EAoYd6K1bFd2iS0eMlU5K8d3EdQpPZfrgIJQXjp+A22/di9PB7pDVfCDAO4FxbFav98OG0PsZ6WXy4wP5qMr3bky73nbWtIbhqwfM8h5Ue+hvek3mn31j1B7lbBp/iWr3mxWiDeLssarwBPnIQ35ndZenENYyBl2nOD9q/OitqOuFsEYRpiXpVmVJAyLpy2A==", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1775393826; c=relaxed/relaxed;\n\tbh=dvO4goCvgbIDjzyl1a4aazkWRerXOYwkBjCejKe9WH8=;\n\th=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n\t MIME-Version;\n b=SP1H9Axhf+9m/cYmjn+GyYt2zdUwQyQNHQzysFVxb7WXuLsvLRRBKReWZl+GCBEWBQSFHmin6ReAQWrmO/WMWUqAUHMh0ATqown3JJLEPqcRhgkhlegd/nUyb5WmjEQsiUXk74031pNjm1gq2jS0TxiZ3n4p9GNCalD10m5M8WQsVo4vUfpc5VAQtnEXGO41n5jDUrBjpF8Vbktq2iY3x15Hnl2ayB8huUwIIsTWG8/Preb2cBPnohkGoTVJDNRYwAZfOIHYYKUNsn1+4kARxjPOqU60eEkPbjW7/v4aUAm97dPHVcwQMz97FIeUd0fCU9ew51kTGfBUdzOK0lY46g==", "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=VLHUY2wF; dkim-atps=neutral;\n spf=pass (client-ip=2607:f8b0:4864:20::102c; helo=mail-pj1-x102c.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=1775393824; x=1775998624;\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=dvO4goCvgbIDjzyl1a4aazkWRerXOYwkBjCejKe9WH8=;\n b=VLHUY2wFHjketRhSzoOYXJ8M9DJAi1OnZsk9n+KDmij3glfrc8E1vK7E0b8yioOVkq\n 5VVPaOCQg6XikusxhgRKMPVV/4aS4e5ctl4/QHDYp8XDgU6eemxZKgrnDOOO2i3Ta6UR\n j4H6UHIjCK3Tds82TJm86yGGwfTKA3TnpSRhfSfjH6YVa4dg4SEVqEMh5+1QPdtQGpKT\n 6LbLZ27ayGIyaCy0H8ths/6tAes91MvJBiyRXYNi+WcAeJ4rKeTQeR8LbtFTExUKF7cR\n ajeg7gHWWmqLOHqhNAhYsys8sTMfA48smViQl4D+uGFdysTw35FvVtUl9VDniYQMrlTY\n X1+g==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775393824; x=1775998624;\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=dvO4goCvgbIDjzyl1a4aazkWRerXOYwkBjCejKe9WH8=;\n b=sKh0FGnzghq/wxTUqScehgedBtPOd3zrlCArUyrhAlTV6pZAml8Xoj30KZmp2Y1lZU\n AQFQv/CjFY/nu9oAvEPe7W62Sr2pvRBRB8y9hYA0boV764WqCn+EIKZLrq2832gOQ/5F\n 98FOiD3qrs/RgUtxzQOAKgc+0owAf2wkF16iB7juY7scRlEmQQWapVvgb8xonCcR55DB\n BT0JYf9upGz7vMyBvZ4XwaCZ2FDjUagnMdD3wuAWbvqw10xPo7mnoxgYMTZjtV3l4f+O\n GP6VL7GWzdvcBrMpmXycO0QdkcXKvz8EGb58og7KrO9QXgQWzbwtCAXxLwC8B9wQstca\n +o6g==", "X-Forwarded-Encrypted": "i=1;\n AJvYcCVKj9LuLYnfWQm/APdPBHf+TxfSBR2VK3QxJulXjlvKBxn7Rfm458ptKvQ81m1E7FV6zv0OEWJ5LvSe6IY=@lists.ozlabs.org", "X-Gm-Message-State": "AOJu0Ywu4LQAzQhTKy2QXHpFC2IWFovrT6kmY7dmD3AVqwHCkURPrQ2I\n\tExGUV+0OFjWbznhxSLgaUOCPa7AHBLCqu/99WhofpHzY74R7WMta01yPLSIqoAdcAxw=", "X-Gm-Gg": "AeBDievKqGnqbdMeepzy7U6DQficUU1Yq5HHfJY0u11CLlHJM+BkIxKnEGTCiedyF8V\n\tJjIv7tMrV6cCDwXnca8zTrWg1/jcEu7znLE6r92xXQKc3si+9c+p/etkFoQH5wF8H6zS8+CsN8f\n\tSja/PlsqBDkxMqiK6HoygeK4oyYKULNWhz5p2FbdwCYepKoYCpO9pSV5eMcaFOHEyv1H1xbvovd\n\t65hkcQU5UvaU7Mrz6XbIIIkrgkxctXM30/ND7l33gB/y3PIWPzdc5dlvXfQK+x7MDTq2XoTQXPJ\n\tBcACAGx2p3ac1RPhwXPsyYg2P+CstKjEgag+ngGmKycWbC+/Lr1tKq9JR6FKU3X+NUkQhvAu1N5\n\tujLf7GiczB5Fpbz/F1MjML0Mhwp9RgqUQGGMJ83Z9FHm/Q/HYzmkCgBcOe3wXfYp6Rjc1zuq6q9\n\teRXDbnl6cJ74TnhCFmihDP8NZLBsofriz9jTGRVo1e7k0=", "X-Received": "by 2002:a17:90a:d2c7:b0:35c:cba:344f with SMTP id\n 98e67ed59e1d1-35de68414eemr9240766a91.13.1775393824055;\n Sun, 05 Apr 2026 05:57:04 -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 34/49] mm/sparse-vmemmap: switch DAX to use generic vmemmap\n optimization", "Date": "Sun, 5 Apr 2026 20:52:25 +0800", "Message-Id": "<20260405125240.2558577-35-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": "Recent refactoring introduced common vmemmap optimization logic via\nCONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION. While HugeTLB already uses it,\nDAX requires slightly different handling because it needs to preserve\n2 vmemmap pages, instead of the 1 page HugeTLB preserves.\n\nThis patch updates DAX vmemmap optimization to manually allocate the\nsecond vmemmap page, and integrates DAX memory setup to correctly set\nthe compound order and allocate/reuse the shared vmemmap tail page.\n\nNote that manually allocating the vmemmap page is a temporary solution\nand will be unified with the logic that HugeTLB relies on in the future.\n\nSigned-off-by: Muchun Song <songmuchun@bytedance.com>\n---\n arch/powerpc/mm/book3s64/radix_pgtable.c | 5 +-\n mm/memory_hotplug.c | 5 +-\n mm/mm_init.c | 8 ++-\n mm/sparse-vmemmap.c | 82 ++++++++++++++----------\n 4 files changed, 58 insertions(+), 42 deletions(-)", "diff": "diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c\nindex dfa2f7dc7e15..ad44883b1030 100644\n--- a/arch/powerpc/mm/book3s64/radix_pgtable.c\n+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c\n@@ -1124,9 +1124,10 @@ int __meminit radix__vmemmap_populate(unsigned long start, unsigned long end, in\n \tpud_t *pud;\n \tpmd_t *pmd;\n \tpte_t *pte;\n+\tunsigned long pfn = page_to_pfn((struct page *)start);\n \n-\tif (vmemmap_can_optimize(altmap, pgmap))\n-\t\treturn vmemmap_populate_compound_pages(page_to_pfn((struct page *)start), start, end, node, pgmap);\n+\tif (vmemmap_can_optimize(altmap, pgmap) && section_vmemmap_optimizable(__pfn_to_section(pfn)))\n+\t\treturn vmemmap_populate_compound_pages(pfn, start, end, node, pgmap);\n \t/*\n \t * If altmap is present, Make sure we align the start vmemmap addr\n \t * to PAGE_SIZE so that we calculate the correct start_pfn in\ndiff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c\nindex 05f5df12d843..28306196c0fe 100644\n--- a/mm/memory_hotplug.c\n+++ b/mm/memory_hotplug.c\n@@ -551,8 +551,9 @@ void remove_pfn_range_from_zone(struct zone *zone,\n \t\t/* Select all remaining pages up to the next section boundary */\n \t\tcur_nr_pages =\n \t\t\tmin(end_pfn - pfn, SECTION_ALIGN_UP(pfn + 1) - pfn);\n-\t\tpage_init_poison(pfn_to_page(pfn),\n-\t\t\t\t sizeof(struct page) * cur_nr_pages);\n+\t\tif (!section_vmemmap_optimizable(__pfn_to_section(pfn)))\n+\t\t\tpage_init_poison(pfn_to_page(pfn),\n+\t\t\t\t\t sizeof(struct page) * cur_nr_pages);\n \t}\n \n \t/*\ndiff --git a/mm/mm_init.c b/mm/mm_init.c\nindex e47d08b63154..636a0f9644f6 100644\n--- a/mm/mm_init.c\n+++ b/mm/mm_init.c\n@@ -1069,9 +1069,10 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,\n * of an altmap. See vmemmap_populate_compound_pages().\n */\n static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap,\n-\t\t\t\t\t struct dev_pagemap *pgmap)\n+\t\t\t\t\t struct dev_pagemap *pgmap,\n+\t\t\t\t\t const struct mem_section *ms)\n {\n-\tif (!vmemmap_can_optimize(altmap, pgmap))\n+\tif (!section_vmemmap_optimizable(ms))\n \t\treturn pgmap_vmemmap_nr(pgmap);\n \n \treturn VMEMMAP_RESERVE_NR * (PAGE_SIZE / sizeof(struct page));\n@@ -1140,7 +1141,8 @@ void __ref memmap_init_zone_device(struct zone *zone,\n \t\t\tcontinue;\n \n \t\tmemmap_init_compound(page, pfn, zone_idx, nid, pgmap,\n-\t\t\t\t compound_nr_pages(altmap, pgmap));\n+\t\t\t\t compound_nr_pages(altmap, pgmap,\n+\t\t\t\t\t\t __pfn_to_section(pfn)));\n \t}\n \n \t/*\ndiff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c\nindex 309d935fb05e..6f959a999d5b 100644\n--- a/mm/sparse-vmemmap.c\n+++ b/mm/sparse-vmemmap.c\n@@ -353,8 +353,12 @@ struct page *vmemmap_shared_tail_page(unsigned int order, struct zone *zone)\n \tif (!addr)\n \t\treturn NULL;\n \n-\tfor (int i = 0; i < PAGE_SIZE / sizeof(struct page); i++)\n-\t\tinit_compound_tail((struct page *)addr + i, NULL, order, zone);\n+\tfor (int i = 0; i < PAGE_SIZE / sizeof(struct page); i++) {\n+\t\tpage = (struct page *)addr + i;\n+\t\tif (zone_is_zone_device(zone))\n+\t\t\t__SetPageReserved(page);\n+\t\tinit_compound_tail(page, NULL, order, zone);\n+\t}\n \n \tpage = virt_to_page(addr);\n \tif (cmpxchg(&zone->vmemmap_tails[idx], NULL, page) != NULL) {\n@@ -458,23 +462,6 @@ static bool __meminit reuse_compound_section(unsigned long start_pfn,\n \treturn !IS_ALIGNED(offset, nr_pages) && nr_pages > PAGES_PER_SUBSECTION;\n }\n \n-static pte_t * __meminit compound_section_tail_page(unsigned long addr)\n-{\n-\tpte_t *pte;\n-\n-\taddr -= PAGE_SIZE;\n-\n-\t/*\n-\t * Assuming sections are populated sequentially, the previous section's\n-\t * page data can be reused.\n-\t */\n-\tpte = pte_offset_kernel(pmd_off_k(addr), addr);\n-\tif (!pte)\n-\t\treturn NULL;\n-\n-\treturn pte;\n-}\n-\n static int __meminit vmemmap_populate_compound_pages(unsigned long start,\n \t\t\t\t\t\t unsigned long end, int node,\n \t\t\t\t\t\t struct dev_pagemap *pgmap)\n@@ -483,42 +470,62 @@ static int __meminit vmemmap_populate_compound_pages(unsigned long start,\n \tpte_t *pte;\n \tint rc;\n \tunsigned long start_pfn = page_to_pfn((struct page *)start);\n+\tconst struct mem_section *ms = __pfn_to_section(start_pfn);\n+\tstruct page *tail = NULL;\n \n-\tif (reuse_compound_section(start_pfn, pgmap)) {\n-\t\tpte = compound_section_tail_page(start);\n-\t\tif (!pte)\n-\t\t\treturn -ENOMEM;\n+\t/* This may occur in sub-section scenarios. */\n+\tif (!section_vmemmap_optimizable(ms))\n+\t\treturn vmemmap_populate_range(start, end, node, NULL, -1);\n \n-\t\t/*\n-\t\t * Reuse the page that was populated in the prior iteration\n-\t\t * with just tail struct pages.\n-\t\t */\n+#ifdef CONFIG_ZONE_DEVICE\n+\ttail = vmemmap_shared_tail_page(section_order(ms),\n+\t\t\t\t\t&NODE_DATA(node)->node_zones[ZONE_DEVICE]);\n+#endif\n+\tif (!tail)\n+\t\treturn -ENOMEM;\n+\n+\tif (reuse_compound_section(start_pfn, pgmap))\n \t\treturn vmemmap_populate_range(start, end, node, NULL,\n-\t\t\t\t\t pte_pfn(ptep_get(pte)));\n-\t}\n+\t\t\t\t\t page_to_pfn(tail));\n \n \tsize = min(end - start, pgmap_vmemmap_nr(pgmap) * sizeof(struct page));\n \tfor (addr = start; addr < end; addr += size) {\n \t\tunsigned long next, last = addr + size;\n+\t\tvoid *p;\n \n \t\t/* Populate the head page vmemmap page */\n \t\tpte = vmemmap_populate_address(addr, node, NULL, -1);\n \t\tif (!pte)\n \t\t\treturn -ENOMEM;\n \n+\t\t/*\n+\t\t * Allocate manually since vmemmap_populate_address() will assume DAX\n+\t\t * only needs 1 vmemmap page to be reserved, however DAX now needs 2\n+\t\t * vmemmap pages. This is a temporary solution and will be unified\n+\t\t * with HugeTLB in the future.\n+\t\t */\n+\t\tp = vmemmap_alloc_block_buf(PAGE_SIZE, node, NULL);\n+\t\tif (!p)\n+\t\t\treturn -ENOMEM;\n+\n \t\t/* Populate the tail pages vmemmap page */\n \t\tnext = addr + PAGE_SIZE;\n-\t\tpte = vmemmap_populate_address(next, node, NULL, -1);\n+\t\tpte = vmemmap_populate_address(next, node, NULL, PHYS_PFN(__pa(p)));\n+\t\t/*\n+\t\t * get_page() is called above. Since we are not actually\n+\t\t * reusing it, to avoid a memory leak, we call put_page() here.\n+\t\t */\n+\t\tput_page(virt_to_page(p));\n \t\tif (!pte)\n \t\t\treturn -ENOMEM;\n \n \t\t/*\n-\t\t * Reuse the previous page for the rest of tail pages\n+\t\t * Reuse the shared vmemmap page for the rest of tail pages\n \t\t * See layout diagram in Documentation/mm/vmemmap_dedup.rst\n \t\t */\n \t\tnext += PAGE_SIZE;\n \t\trc = vmemmap_populate_range(next, last, node, NULL,\n-\t\t\t\t\t pte_pfn(ptep_get(pte)));\n+\t\t\t\t\t page_to_pfn(tail));\n \t\tif (rc)\n \t\t\treturn -ENOMEM;\n \t}\n@@ -744,8 +751,10 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,\n \t\tfree_map_bootmem(memmap);\n \t}\n \n-\tif (empty)\n+\tif (empty) {\n \t\tms->section_mem_map = (unsigned long)NULL;\n+\t\tsection_set_order(ms, 0);\n+\t}\n }\n \n static struct page * __meminit section_activate(int nid, unsigned long pfn,\n@@ -824,6 +833,9 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,\n \tif (ret < 0)\n \t\treturn ret;\n \n+\tms = __nr_to_section(section_nr);\n+\tif (vmemmap_can_optimize(altmap, pgmap) && nr_pages == PAGES_PER_SECTION)\n+\t\tsection_set_order(ms, pgmap->vmemmap_shift);\n \tmemmap = section_activate(nid, start_pfn, nr_pages, altmap, pgmap);\n \tif (IS_ERR(memmap))\n \t\treturn PTR_ERR(memmap);\n@@ -832,9 +844,9 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,\n \t * Poison uninitialized struct pages in order to catch invalid flags\n \t * combinations.\n \t */\n-\tpage_init_poison(memmap, sizeof(struct page) * nr_pages);\n+\tif (!section_vmemmap_optimizable(ms))\n+\t\tpage_init_poison(memmap, sizeof(struct page) * nr_pages);\n \n-\tms = __nr_to_section(section_nr);\n \t__section_mark_present(ms, section_nr);\n \n \t/* Align memmap to section boundary in the subsection case */\n", "prefixes": [ "34/49" ] }