From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pz2-f41.google.com (mail-pz2-f41.google.com [74.125.228.41]) (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 6B95D51354D for ; Wed, 30 Sep 2026 14:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790777287; cv=none; b=KA7ICHYlD3MGBhAIDEju5545dYix3MGX1CRdkZLqmv2+Qt2Mp+d6WgWFiS6jfK3SRz4Iy9jdJXmzsCnpVzRLi+BWXdKzaam3BLpLQVvnPxcT5H1PMoSMT1Cv6ipaXwgSoacJQzqaCNK4Ji3r2Hb4wbUC3gk/pdpBB1C3w7VemCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790777287; c=relaxed/simple; bh=KIbYZIFt/J2ukIvG0ZooIQzOXnVqAUoNzKHjpFuV2yU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o+KiXHMVqr3eb7pTMBz24WANGe5Cie2KY3KgYz/WkN8645Gc4A94tN9qK+oZjkJQv84PUeu31WwOPoeqPKKxWX9gFkwM5JL5oA4EWiSjtPnbyzht4quKiv1dlgRdDuVuCVTLsbnnCQUNlnc4Bdb5RqXdVOBU3vBTam+iJGqcnU8= 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=NieONNwk; arc=none smtp.client-ip=74.125.228.41 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="NieONNwk" Received: by mail-pz2-f41.google.com with SMTP id 41be03b00d2f7-cc4c3304833so2101367a12.3 for ; Wed, 30 Sep 2026 07:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1790777279; x=1791382079; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SfMxtfxa+3COrIjgzxsQNjSW0BqNRs0OC1S2RzR7Pys=; b=NieONNwkuR0LF/4PF2jUQnZojT1e5cP1Puep0rGLauPg29kAHqK9QF2kF9mhfhojJ6 Mqw/bbjuEYxvF+YO1V3vllprCVY+xIkVd2CX/02ZwfsBrjlKKJepQskSe698b6e4gYHc vjNqFn1I5FXOTY0bsvg/SINS2eeJun+J+7BqKmKbkb6CqP3oXV3atTM8ofuIQ2/1Yy0a +AcZpiT7VE7b/IN0GS1NyUeaiIqP4pDhZD1Wtpj62yi+sOslTBKPOiwqC3WqBygGsEVQ lNnIQDqVpK5/EGGUhg52MH3WnUXKBF0SrGOrmBexLwbj7VVJ3Tk5hWxyP6O3inc0kES4 R66g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790777279; x=1791382079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SfMxtfxa+3COrIjgzxsQNjSW0BqNRs0OC1S2RzR7Pys=; b=Qxo50xmaxvk3ICr+gWWnqRmYTT6d0cIyPzwbRdzvLzWcXAaKDcqPJ3hsrfmTFhEvTH hzvcTxEe9dsd7X8qeSeNblSgTZaTT00OlhQd/a3MPdT8L4i6Xvnl+UOBPknATW5iy95U KvCg2WLhJnejonwDQW7m4ZoqCpTR4HxtQpHNniHuxuUW80s5fSmFLXr1nh3YoQpmlWbQ r6Ii0pMW//eHxODYKCJD4elrWSpm4irMG2uawskeW2MsCHt/Anu+SqAKSwbGEBFIoi0Q dWfqe1IQZyPCwqiv1fDz1Vz1AXM9e5lKreKhlZI5uL+J/PXfN5N8bfqIyhAvavZkfF9d FBiw== X-Forwarded-Encrypted: i=1; AKwUvBzBR721kzd6tSqtBMZB2JgqBU44fbbiKO5VUOI61FuvbjNiYeEClcQ4NhLEHidEg/pu2xLNMA7NUKA=@vger.kernel.org X-Gm-Message-State: AFq9FYLlWFwUXFftTphrgHK9s7qc4uSGC9TYcrXkcpR9Tyc6mjmvoptW ZagrTXkRLiTdBnNO6Lqi22DwGH6D3+54gnG7vfMmSeNWV4SeeovYb3Az72lis3lqqbw= X-Gm-Gg: AYBFou0sPRrN4Jj80Bv++8NPXOzevYCi8OZ21Zj3zx4PtJqjnvwPXbyE1KVjNdi1a7f RF8UCnp6BiKOk40dJcTXDejszzpvmJXstFpV4p7B6qwODGBSS5qmzerSrv/n5JsfUK0ouJcZgY1 hFlpszkEK4bFmKP8oi9PKqco0FtcPjNyCMP6i7iP4Wv2q13TzVIN55DbWBeIqiyfWxLhp+t6/Q0 kJC4mrtz3RH1/HbMSbdVRBxkvgHLimCBk+C3pRDI3QTG5qpDhhIe3WvcvOa8bS+O1d3H1wNE02r /XRLOb9OqQ20GvY8DpdUcWH1PzWcguZGd8OdvlOQ19uudMr6ZLivRSEDEJ3NeXnjGZrHJYgUuJj PkmVIM14JRkRSTJYG2PuqODLJ9FJY39UqEjNQxG3ctNxUQb1W+JMmhzmjebZxYbU+oYcS97eSiU A8NGr+nsaeQKSl1sqGyjWQQZfDFyT+ewNQcFd8t2FTVNCPyNU5ftfIYufh0bk2165eDHqJo/qp0 IQD3qf7fdmRig== X-Received: by 2002:a17:90b:4acf:b0:39e:4c7f:8b1b with SMTP id 98e67ed59e1d1-3a4d19d23e4mr1306484a91.32.1790777279220; Wed, 30 Sep 2026 07:07:59 -0700 (PDT) Received: from G6L4RL2QG9 ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a4e60ea12csm639509a91.1.2026.09.30.07.07.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 30 Sep 2026 07:07:58 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Oscar Salvador , Madhavan Srinivasan , Michael Ellerman , Jonathan Corbet Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-doc@vger.kernel.org, Muchun Song , Lorenzo Stoakes , Mike Rapoport , Qi Zheng , Nicholas Piggin , Christophe Leroy , Ritesh Harjani , Shrikanth Hegde , Randy Dunlap , Muchun Song , Lance Yang Subject: [PATCH v6 05/12] mm/sparse-vmemmap: prepare DAX vmemmap population for compound page orders Date: Wed, 30 Sep 2026 22:06:20 +0800 Message-ID: <20260930140627.57431-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260930140627.57431-1-songmuchun@bytedance.com> References: <20260930140627.57431-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Device DAX still uses vmemmap_populate_compound_pages() to populate its compound-page vmemmap mappings. That helper allocates the head and first tail vmemmap pages explicitly, then reuses the first tail page for the remaining tail page mappings. Device DAX is being moved to the section-based vmemmap optimization infrastructure, but it cannot switch to the generic section-based population path yet. Once a later patch records the DAX compound page order in section metadata, DAX head and first-tail PFNs can look optimizable to the generic helpers as well. Rename the existing VMEMMAP_POPULATE_PAGEREF flag to VMEMMAP_POPULATE_DAX and pass it through all paths in vmemmap_populate_compound_pages() during this transition. This keeps DAX head/first-tail allocations on the normal vmemmap allocation path, while preserving the existing page reference for reused DAX tail mappings. Signed-off-by: Muchun Song Acked-by: Qi Zheng --- v6: - Clarify that the DAX flag is renamed and used on additional paths (suggested by David Hildenbrand) - Make flags const and move it to the top of the function (suggested by David Hildenbrand) v3: - Update the subject and commit message to use compound page order terminology v2: - Collect Acked-by from Qi Zheng --- mm/sparse-vmemmap.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index f77e6e1e5a8b..b4b72f233bf6 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -35,8 +35,8 @@ /* * Flags for vmemmap_populate_range and friends. */ -/* Get a ref on the head page struct page, for ZONE_DEVICE compound pages */ -#define VMEMMAP_POPULATE_PAGEREF 0x0001 +/* Vmemmap population for ZONE_DEVICE compound pages */ +#define VMEMMAP_POPULATE_DAX 0x0001 #include "internal.h" #include "mm_init.h" @@ -247,13 +247,17 @@ static inline struct page *vmemmap_shared_tail_page(unsigned int order, #endif static __meminit void *vmemmap_alloc_pte(unsigned long pfn, int node, - struct vmem_altmap *altmap) + struct vmem_altmap *altmap, unsigned long flags) { struct zone *zone; struct page *page; const unsigned int order = pfn_to_section_compound_order(pfn); - if (!vmemmap_optimizable_pfn(pfn)) + /* + * Device DAX still relies on vmemmap_populate_compound_pages() for + * head/first-tail allocation and tail-page reuse. + */ + if (!vmemmap_optimizable_pfn(pfn) || flags & VMEMMAP_POPULATE_DAX) return vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap); zone = pfn_to_zone(pfn, node); @@ -275,7 +279,7 @@ static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in pte_t entry; if (ptpfn == (unsigned long)-1) { - void *p = vmemmap_alloc_pte(pfn, node, altmap); + void *p = vmemmap_alloc_pte(pfn, node, altmap, flags); if (!p) return NULL; @@ -290,7 +294,7 @@ static pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, in * and through vmemmap_populate_compound_pages() when * slab is available. */ - if (flags & VMEMMAP_POPULATE_PAGEREF) + if (flags & VMEMMAP_POPULATE_DAX) get_page(pfn_to_page(ptpfn)); } entry = pfn_pte(ptpfn, PAGE_KERNEL); @@ -547,6 +551,7 @@ static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn, unsigned long end, int node, struct dev_pagemap *pgmap) { + const unsigned long flags = VMEMMAP_POPULATE_DAX; unsigned long size, addr; pte_t *pte; int rc; @@ -561,8 +566,7 @@ static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn, * with just tail struct pages. */ return vmemmap_populate_range(start, end, node, NULL, - pte_pfn(ptep_get(pte)), - VMEMMAP_POPULATE_PAGEREF); + pte_pfn(ptep_get(pte)), flags); } size = min(end - start, pgmap_vmemmap_nr(pgmap) * sizeof(struct page)); @@ -570,13 +574,13 @@ static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn, unsigned long next, last = addr + size; /* Populate the head page vmemmap page */ - pte = vmemmap_populate_address(addr, node, NULL, -1, 0); + pte = vmemmap_populate_address(addr, node, NULL, -1, flags); if (!pte) return -ENOMEM; /* Populate the tail pages vmemmap page */ next = addr + PAGE_SIZE; - pte = vmemmap_populate_address(next, node, NULL, -1, 0); + pte = vmemmap_populate_address(next, node, NULL, -1, flags); if (!pte) return -ENOMEM; @@ -586,8 +590,7 @@ static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn, */ next += PAGE_SIZE; rc = vmemmap_populate_range(next, last, node, NULL, - pte_pfn(ptep_get(pte)), - VMEMMAP_POPULATE_PAGEREF); + pte_pfn(ptep_get(pte)), flags); if (rc) return -ENOMEM; } -- 2.54.0