From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-112.ptr.blmpb.com (va-1-112.ptr.blmpb.com [209.127.230.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3834400968 for ; Mon, 27 Jul 2026 12:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785155821; cv=none; b=mDrx4qCl0E3Utfqzok3E1nUMQy+Qu/EfT3A1O6CjpGybss5iJGJ4/Iril0UJ6Ef3nJMcYkWiPtqUNSn3zubNO40bm5WH1Y0J9V+iA+5+UzVMnBE7FTlO0wkj8F46HqdwA/QX8QPhlA7pnddAB+lAgelFLts7QGAnAF5UWqq6Alk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785155821; c=relaxed/simple; bh=xQcXvcyM7Mv+ZqJO2OPVPW/XAtgr8BtonMyNybIklzI=; h=Content-Type:Mime-Version:In-Reply-To:Message-Id:From:Subject: Date:References:To:Cc; b=g2XsLkeAt+WvbVVpMHh7WtnPuNkCz4PpG5gfUgxoRpvB4TLkVK8BmohDy9gUjZ4tnwe/XwhIPLq9OkK8VMdG+booHnuFVLVJpcLRjkn4a3SUWIAzsXM6gZy/NGHHVd3ZfNkSvDYAN4EAB+KpGBJPsuGx4sH6X3mNFH0lD9z5nTM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=EjF/FVF7; arc=none smtp.client-ip=209.127.230.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="EjF/FVF7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1785155815; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=jxmgrDMAVpE6lcX28qNeYhL42ykWrhIjdDLod/Kz2Jg=; b=EjF/FVF7mERZudwuitFgmGJTzOcsR+2kyfboteYHPLcRUftOumgPL9J5EPdiiX6ZmTklno dOUES7UCI23frutQ2hDCJ8fArxbFszlbGA6M5N4Eium4bs5XpDhdZL16atStH7GVSyu5L3 Go0iyZ04X5Qu++4l9/zTb182H7LAJFl9ztPorT2qC2rRFb83iVRI3VbSeuHeBRa0UjoZM0 b7hj6+Hc+gvuA8n+NTZLJlP2F9XFKHP1USKvLwOxwaB6JigsZIzaZiD2y/OITch1ZBNqmn lk4nFxWyxUj7M7cRhQ9ileSR5Ctntc5RE1hCBoik9kZrgb6YLge2x9amfKBFcg== X-Original-From: Li Zhe X-Mailer: git-send-email 2.45.2 Content-Type: text/plain; charset=UTF-8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: 7bit In-Reply-To: <20260727123429.5673-1-lizhe.67@bytedance.com> X-Lms-Return-Path: Message-Id: <20260727123429.5673-6-lizhe.67@bytedance.com> From: "Li Zhe" Subject: [PATCH v8 5/9] mm: extend the template fast path to zone-device compound tails Date: Mon, 27 Jul 2026 20:34:25 +0800 References: <20260727123429.5673-1-lizhe.67@bytedance.com> To: , , , , , , , , , , , Cc: , , , , , 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 --- 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