Re: [PATCH 03/17] mm/sparse-vmemmap: introduce folio-oriented vmemmap optimization macros

From: Muchun Song

Date: Thu Jul 16 2026 - 03:39:21 EST




On 2026/7/15 13:08, Mike Rapoport wrote:
Introduce macros for those folio-oriented properties and use them to
replace the tail-based names in the HVO paths. This makes the code read
in terms of folio semantics instead of an implementation detail and
better matches other folio-based users such as DAX.

No functional change intended.

Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index bacd89572c5c..ea884245f499 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -107,13 +107,15 @@
is_power_of_2(sizeof(struct page)) ? \
MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0)
-/*
- * vmemmap optimization (like HVO) is only possible for page orders that fill
- * two or more pages with struct pages.
- */
-#define VMEMMAP_TAIL_MIN_ORDER (ilog2(2 * PAGE_SIZE / sizeof(struct page)))
-#define __NR_VMEMMAP_TAILS (MAX_FOLIO_ORDER - VMEMMAP_TAIL_MIN_ORDER + 1)
-#define NR_VMEMMAP_TAILS (__NR_VMEMMAP_TAILS > 0 ? __NR_VMEMMAP_TAILS : 0)
+/* The number of vmemmap pages required by a vmemmap-optimized folio. */
+#define OPTIMIZED_FOLIO_VMEMMAP_PAGES 1
+#define OPTIMIZED_FOLIO_VMEMMAP_SIZE (OPTIMIZED_FOLIO_VMEMMAP_PAGES * PAGE_SIZE)
+#define OPTIMIZED_FOLIO_VMEMMAP_NR_STRUCT_PAGES (OPTIMIZED_FOLIO_VMEMMAP_SIZE / sizeof(struct page))
+#define OPTIMIZABLE_FOLIO_MIN_ORDER (ilog2(OPTIMIZED_FOLIO_VMEMMAP_NR_STRUCT_PAGES) + 1)
+
+#define __NR_OPTIMIZABLE_FOLIO_ORDERS (MAX_FOLIO_ORDER - OPTIMIZABLE_FOLIO_MIN_ORDER + 1)
+#define NR_OPTIMIZABLE_FOLIO_ORDERS \
+ (__NR_OPTIMIZABLE_FOLIO_ORDERS > 0 ? __NR_OPTIMIZABLE_FOLIO_ORDERS : 0)
I can't say I like the new names, they read like some folio optimization
rather than vmemmap optimization.

I think they should be namespaced with VMEMMAP_ or even
VMEMMAP_OPTIMIZATION_ (or VMEMMAP_OPT_) and should not mention folio.

If you're okay with it, I'll update those macros to:

VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES
VMEMMAP_OPTIMIZATION_MIN_ORDER
VMEMMAP_OPTIMIZATION_NR_ORDERS


I'd also drop intermediate defines OPTIMIZED_FOLIO_VMEMMAP_PAGES and
OPTIMIZED_FOLIO_VMEMMAP_SIZE and use 1 and PAGE_SIZE directly.

OK. I'll not introduce OPTIMIZED_FOLIO_VMEMMAP_PAGES and
OPTIMIZED_FOLIO_VMEMMAP_SIZE

Muchun,
Thanks.