From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Muchun Song <songmuchun@bytedance.com>,
Andrew Morton <akpm@linux-foundation.org>,
Oscar Salvador <osalvador@suse.de>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Jonathan Corbet <corbet@lwn.net>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-doc@vger.kernel.org,
Muchun Song <muchun.song@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>, Mike Rapoport <rppt@kernel.org>,
Qi Zheng <qi.zheng@linux.dev>,
Nicholas Piggin <npiggin@gmail.com>,
Christophe Leroy <chleroy@kernel.org>,
Randy Dunlap <rdunlap@infradead.org>,
Lance Yang <lance.yang@linux.dev>
Subject: Re: [PATCH v5 02/12] mm/sparse-vmemmap: allocate shared tail page array dynamically
Date: Tue, 29 Sep 2026 09:21:28 +0200 [thread overview]
Message-ID: <36a93f95-2fb4-4310-bef2-88c12dbe7971@kernel.org> (raw)
In-Reply-To: <20260927025441.741633-3-songmuchun@bytedance.com>
On 9/27/26 04:54, Muchun Song wrote:
> Commit 622026e87c40 ("mm/hugetlb: remove fake head pages") added the
> per-zone vmemmap_tails array. Its size depends on MAX_FOLIO_ORDER, which
> had been moved to mmzone.h in preparation for the array.
>
> PUD_ORDER is defined by linux/pgtable.h, which cannot be included from
> mmzone.h without creating an include cycle. It was therefore open-coded
> as PUD_SHIFT - PAGE_SHIFT.
>
> This removed the dependency on PUD_ORDER, but not the underlying
> dependency on architecture page-table definitions. PUD_SHIFT is
> generally provided by architecture page-table headers, which are not
> guaranteed to have been included when mmzone.h is parsed.
>
> The dependency remained hidden because vmemmap_tails was originally
> guarded by CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP. Under that condition,
> MAX_FOLIO_ORDER resolves to either MAX_PAGE_ORDER or the fixed HugeTLB
> limit, rather than the PUD_SHIFT-based definition.
>
> Device DAX, however, does not require CONFIG_HUGETLB_PAGE. When it is
> converted to use section-based vmemmap optimization, MAX_FOLIO_ORDER can
> resolve to PUD_SHIFT - PAGE_SHIFT while it is being used to size
> vmemmap_tails. This would make struct zone depend on architecture
> page-table definitions being available when mmzone.h is parsed.
>
> Replace the embedded array with a pointer and allocate it on first use.
> This moves the order-count evaluation into sparse-vmemmap.c, after the
> architecture page-table definitions are available, and removes the
> dependency from mmzone.h.
>
> Removing the compile-time array also removes the original reason for
> keeping MAX_FOLIO_ORDER and the vmemmap optimization sizing definitions
> in mmzone.h. Follow-up cleanups can place each definition in the header
> owned by its respective subsystem.
>
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---
> v5:
> - Add this patch to fix the RISC-V build failure under the configuration
> reported by the kernel test robot
> ---
> include/linux/mmzone.h | 7 +------
> mm/sparse-vmemmap.c | 35 +++++++++++++++++++++++++++++++----
> 2 files changed, 32 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index acd94cecc0d3..68807ff7f946 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -113,11 +113,6 @@
> (VMEMMAP_OPTIMIZATION_PAGES * PAGE_SIZE / sizeof(struct page))
> #define VMEMMAP_OPTIMIZATION_MIN_ORDER (ilog2(VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES) + 1)
>
> -#define __VMEMMAP_OPTIMIZATION_NR_ORDERS \
> - (MAX_FOLIO_ORDER - VMEMMAP_OPTIMIZATION_MIN_ORDER + 1)
> -#define VMEMMAP_OPTIMIZATION_NR_ORDERS \
> - (__VMEMMAP_OPTIMIZATION_NR_ORDERS > 0 ? __VMEMMAP_OPTIMIZATION_NR_ORDERS : 0)
> -
> enum migratetype {
> MIGRATE_UNMOVABLE,
> MIGRATE_MOVABLE,
> @@ -1156,7 +1151,7 @@ struct zone {
> atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
> atomic_long_t vm_numa_event[NR_VM_NUMA_EVENT_ITEMS];
> #ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
> - struct page *vmemmap_tails[VMEMMAP_OPTIMIZATION_NR_ORDERS];
> + struct page **vmemmap_tails;
> #endif
> } ____cacheline_internodealigned_in_smp;
>
[...]
> struct page __ref *vmemmap_shared_tail_page(unsigned int order, struct zone *zone)
> {
> void *addr;
> - struct page *page;
> + struct page *page, **pages;
> const unsigned int idx = order - VMEMMAP_OPTIMIZATION_MIN_ORDER;
>
> if (WARN_ON_ONCE(idx >= VMEMMAP_OPTIMIZATION_NR_ORDERS))
> return NULL;
>
> - page = READ_ONCE(zone->vmemmap_tails[idx]);
> + pages = READ_ONCE(zone->vmemmap_tails) ? : vmemmap_tails_alloc(zone);
This reads much nicer if you handle the READ_ONCE(zone->vmemmap_tails) inside
the function.
pages = vmemmap_tails(zone);
So just place the entire logic of obtaining the array in there.
Apart from that LGTM.
--
Cheers,
David
next prev parent reply other threads:[~2026-09-29 7:21 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-27 2:54 [PATCH v5 00/12] mm: Switch device DAX to section-based vmemmap optimization Muchun Song
2026-09-27 2:54 ` [PATCH v5 01/12] mm/sparse-vmemmap: factor out shared vmemmap tail page allocation Muchun Song
2026-09-29 7:16 ` David Hildenbrand (Arm)
2026-09-29 7:55 ` Muchun Song
2026-09-27 2:54 ` [PATCH v5 02/12] mm/sparse-vmemmap: allocate shared tail page array dynamically Muchun Song
2026-09-29 7:21 ` David Hildenbrand (Arm) [this message]
2026-09-29 8:00 ` Muchun Song
2026-09-27 2:54 ` [PATCH v5 03/12] mm/sparse-vmemmap: introduce CONFIG_VMEMMAP_OPTIMIZATION Muchun Song
2026-09-29 7:11 ` David Hildenbrand (Arm)
2026-09-29 7:53 ` Muchun Song
2026-09-29 8:43 ` David Hildenbrand (Arm)
2026-09-27 2:54 ` [PATCH v5 04/12] mm/sparse-vmemmap: open-code init_compound_tail() Muchun Song
2026-09-27 2:54 ` [PATCH v5 05/12] mm/sparse-vmemmap: prepare DAX vmemmap population for compound page orders Muchun Song
2026-09-29 7:24 ` David Hildenbrand (Arm)
2026-09-29 8:04 ` Muchun Song
2026-09-27 2:54 ` [PATCH v5 06/12] mm/sparse-vmemmap: set compound page order for device DAX Muchun Song
2026-09-29 7:30 ` David Hildenbrand (Arm)
2026-09-29 8:22 ` Muchun Song
2026-09-29 8:43 ` David Hildenbrand (Arm)
2026-09-27 2:54 ` [PATCH v5 07/12] mm/sparse-vmemmap: switch device DAX to shared tail vmemmap pages Muchun Song
2026-09-28 4:41 ` [PATCH] fixup! " Muchun Song
2026-09-29 7:36 ` [PATCH v5 07/12] " David Hildenbrand (Arm)
2026-09-29 8:36 ` Muchun Song
2026-09-27 2:54 ` [PATCH v5 08/12] mm/sparse-vmemmap: move vmemmap optimization helpers to a public header Muchun Song
2026-09-29 7:39 ` David Hildenbrand (Arm)
2026-09-29 8:44 ` Muchun Song
2026-09-29 10:03 ` Muchun Song
2026-09-27 2:54 ` [PATCH v5 09/12] powerpc/mm: switch device DAX to shared tail vmemmap pages Muchun Song
2026-09-29 8:44 ` David Hildenbrand (Arm)
2026-09-27 2:54 ` [PATCH v5 10/12] mm/sparse-vmemmap: drop the extra tail page from device DAX reservation Muchun Song
2026-09-29 7:45 ` David Hildenbrand (Arm)
2026-09-27 2:54 ` [PATCH v5 11/12] mm/sparse-vmemmap: drop unused section_nr_vmemmap_pages() arguments Muchun Song
2026-09-29 7:41 ` David Hildenbrand (Arm)
2026-09-27 2:54 ` [PATCH v5 12/12] Documentation/mm: update DAX vmemmap deduplication docs Muchun Song
2026-09-29 7:43 ` David Hildenbrand (Arm)
2026-09-27 5:51 ` [PATCH v5 00/12] mm: Switch device DAX to section-based vmemmap optimization Andrew Morton
2026-09-27 10:51 ` Muchun Song
2026-09-27 19:54 ` Andrew Morton
2026-09-28 4:25 ` Muchun Song
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=36a93f95-2fb4-4310-bef2-88c12dbe7971@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chleroy@kernel.org \
--cc=corbet@lwn.net \
--cc=lance.yang@linux.dev \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=ljs@kernel.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=muchun.song@linux.dev \
--cc=npiggin@gmail.com \
--cc=osalvador@suse.de \
--cc=qi.zheng@linux.dev \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=songmuchun@bytedance.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.