From: "Li Zhe" <lizhe.67@bytedance.com>
To: <akpm@linux-foundation.org>, <apopple@nvidia.com>,
<arnd@arndb.de>, <balbirs@nvidia.com>, <bp@alien8.de>,
<dave.hansen@linux.intel.com>, <david@kernel.org>,
<kees@kernel.org>, <mingo@redhat.com>, <rppt@kernel.org>,
<tglx@kernel.org>, <muchun.song@linux.dev>
Cc: <linux-arch@vger.kernel.org>, <linux-hardening@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<x86@kernel.org>, <lizhe.67@bytedance.com>
Subject: [PATCH v7 5/9] mm: extend the template fast path to zone-device compound tails
Date: Mon, 20 Jul 2026 20:02:55 +0800 [thread overview]
Message-ID: <20260720120259.1545-7-lizhe.67@bytedance.com> (raw)
In-Reply-To: <20260720120259.1545-1-lizhe.67@bytedance.com>
The template fast path from the previous patch only accelerates head
pages. Compound tails in memmap_init_compound() still go through the
zone_device_page_init_slow() one by one.
Build separate head and tail templates and reuse one prepared tail
template across the tail pages in a compound range. Head pages preserve
the existing refcount policy, while compound tails always start with a
refcount of 0 after prep_compound_tail().
This extends the template-copy fast path to pfns_per_compound > 1
without changing the existing zone_device_page_init_slow() helper.
Tail-page PFN-dependent fields are refreshed in the reusable tail
template before each copy.
Tested in a VM with a 100 GB devdax namespace (align=2097152) on Intel
Ice Lake server. This test exercises the dax_pmem rebind path and
measures memmap initialization latency.
Test procedure:
Unbind and rebind the dax_pmem driver 30 times, collect memmap
initialization time from the pr_debug() output of memmap_init_zone_device().
Base(v7.2-rc1):
First binding: 1462 ms
Average of subsequent rebinds: 273.31 ms
With this patch and its prerequisites applied:
First binding: 1403 ms
Average of subsequent rebinds: 244.37 ms
This reduces the average memmap initialization time measured during rebind
from 273.31 ms to 244.37 ms, or about 10.6%.
Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
---
mm/mm_init.c | 40 +++++++++++++++++++++++++++++++++++-----
1 file changed, 35 insertions(+), 5 deletions(-)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index c2645b9bcef3..2668acef4fe6 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1074,6 +1074,16 @@ static inline bool zone_device_page_init_optimization_enabled(void)
return !page_ref_tracepoint_active(page_ref_set);
}
+static inline void zone_device_tail_page_init(struct page *page,
+ unsigned long pfn, unsigned long zone_idx, int nid,
+ struct dev_pagemap *pgmap, const struct page *head,
+ unsigned int order)
+{
+ zone_device_page_init_slow(page, pfn, zone_idx, nid, pgmap);
+ prep_compound_tail(page, head, order);
+ set_page_count(page, 0);
+}
+
/*
* 'template' is a reusable page prototype rather than a strictly immutable
* object. Most ZONE_DEVICE fields stay constant across the pages covered by
@@ -1131,10 +1141,12 @@ static void __ref memmap_init_compound(struct page *head,
unsigned long head_pfn,
unsigned long zone_idx, int nid,
struct dev_pagemap *pgmap,
- unsigned long nr_pages)
+ unsigned long nr_pages,
+ bool use_template)
{
unsigned long pfn, end_pfn = head_pfn + nr_pages;
unsigned int order = pgmap->vmemmap_shift;
+ struct page template;
/*
* We have to initialize the pages, including setting up page links.
@@ -1143,12 +1155,29 @@ static void __ref memmap_init_compound(struct page *head,
* the pages in the same go.
*/
__SetPageHead(head);
+
for (pfn = head_pfn + 1; pfn < end_pfn; pfn++) {
struct page *page = pfn_to_page(pfn);
- zone_device_page_init_slow(page, pfn, zone_idx, nid, pgmap);
- prep_compound_tail(page, head, order);
- set_page_count(page, 0);
+ if (!use_template) {
+ zone_device_tail_page_init(page, pfn, zone_idx, nid,
+ pgmap, head, order);
+ } else if (pfn == head_pfn + 1) {
+ /*
+ * All tails of the same compound page share the
+ * state established by prep_compound_tail(). Reuse
+ * one tail template for the whole range and
+ * refresh only the PFN-dependent fields in that
+ * template before each copy.
+ */
+ zone_device_tail_page_init(page, pfn, zone_idx, nid,
+ pgmap, head, order);
+ /* init template page */
+ memcpy(&template, page, sizeof(*page));
+ } else {
+ zone_device_page_init_from_template(page, pfn,
+ &template);
+ }
}
prep_compound_head(head, order);
}
@@ -1210,7 +1239,8 @@ void __ref memmap_init_zone_device(struct zone *zone,
continue;
memmap_init_compound(page, pfn, zone_idx, nid, pgmap,
- compound_nr_pages(pfn, altmap, pgmap));
+ compound_nr_pages(pfn, altmap, pgmap),
+ use_template);
}
pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE);
--
2.20.1
next prev parent reply other threads:[~2026-07-20 12:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 12:02 [PATCH v7 0/9] mm: optimize zone-device memmap initialization Li Zhe
2026-07-20 12:02 ` Li Zhe
2026-07-28 16:48 ` Mike Rapoport
2026-07-30 7:53 ` Li Zhe
2026-07-20 12:02 ` [PATCH v7 1/9] mm: fix stale ZONE_DEVICE refcount comment Li Zhe
2026-07-20 12:02 ` [PATCH v7 2/9] mm: factor zone-device page init helpers out of __init_zone_device_page Li Zhe
2026-07-20 12:02 ` [PATCH v7 3/9] mm: add a set_page_section_from_pfn() helper Li Zhe
2026-07-20 12:02 ` [PATCH v7 4/9] mm: add a template-based fast path for zone-device page init Li Zhe
2026-07-20 12:02 ` Li Zhe [this message]
2026-07-20 12:02 ` [PATCH v7 6/9] string: introduce memcpy_nontemporal() Li Zhe
2026-07-20 12:02 ` [PATCH v7 7/9] x86/string: extend memcpy_flushcache() fixed-size fastpaths Li Zhe
2026-07-20 12:02 ` [PATCH v7 8/9] mm: use memcpy_nontemporal() in zone-device template copies Li Zhe
2026-07-20 12:02 ` [PATCH v7 9/9] mm: always use the zone-device template init path Li Zhe
2026-07-28 16:48 ` Mike Rapoport
2026-07-30 7:58 ` Li Zhe
2026-07-20 13:05 ` [PATCH v7 0/9] mm: optimize zone-device memmap initialization Dave Hansen
2026-07-22 4:00 ` Li Zhe
2026-07-20 22:43 ` Andrew Morton
2026-07-22 8:18 ` Li Zhe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260720120259.1545-7-lizhe.67@bytedance.com \
--to=lizhe.67@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=arnd@arndb.de \
--cc=balbirs@nvidia.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=kees@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=muchun.song@linux.dev \
--cc=rppt@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®