Skip to contentSkip to conversation

mm: Add CONFIG_SPARSEMEM_CLASSIC

PATCH In review Kaitao Cheng 4 participants 4 messages Sep 20 – Sep 23

Subsystems (6)
Memory management x86 MM core MGLRU +2 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: Add CONFIG_SPARSEMEM_CLASSIC

From: Kaitao Cheng <[email protected]>

Several MM paths identify classic sparse memory by testing CONFIG_SPARSEMEM while also testing that CONFIG_SPARSEMEM_VMEMMAP is disabled. Repeating the compound condition obscures the memory model being selected and requires the local SECTION_IN_PAGE_FLAGS alias for the same state.

Add CONFIG_SPARSEMEM_CLASSIC as a hidden derived option and use it at the conditional sites. Remove SECTION_IN_PAGE_FLAGS and test the new option directly.

The x86 32-bit vDSO build starts with the x86_64 configuration and then undefines CONFIG_SPARSEMEM_VMEMMAP to emulate a 32-bit configuration. Kconfig-derived symbols are not recomputed by the C preprocessor, so define CONFIG_SPARSEMEM_CLASSIC there when CONFIG_SPARSEMEM is enabled. This preserves the existing behavior.

---
 arch/x86/entry/vdso/vdso32/fake_32bit_build.h |  3 +++
 include/linux/mm.h                            | 12 ++++--------
 include/linux/mmzone.h                        |  2 +-
 include/linux/page-flags-layout.h             |  2 +-
 mm/Kconfig                                    |  3 +++
 mm/util.c                                     |  2 +-
 6 files changed, 13 insertions(+), 11 deletions(-)
arch/x86/entry/vdso/vdso32/fake_32bit_build.h +3 -0
index 72a92cb9b53d..3e07389c4d2b 100644
@@ -20,6 +20,9 @@
 #define CONFIG_PAGE_OFFSET 0
 #define CONFIG_ILLEGAL_POINTER_VALUE 0
 #define CONFIG_NR_CPUS 1
+#ifdef CONFIG_SPARSEMEM
+#define CONFIG_SPARSEMEM_CLASSIC 1
+#endif
 
 #define BUILD_VDSO32_64
 
include/linux/mm.h +4 -8
index ae56d6a2c9f9..b786ee73a20f 100644
@@ -201,7 +201,7 @@ static inline void __mm_zero_struct_page(struct page *page)
 extern unsigned long sysctl_user_reserve_kbytes;
 extern unsigned long sysctl_admin_reserve_kbytes;
 
-#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
+#ifdef CONFIG_SPARSEMEM_CLASSIC
 bool page_range_contiguous(const struct page *page, unsigned long nr_pages);
 #else
 static inline bool page_range_contiguous(const struct page *page,
@@ -2531,10 +2531,6 @@ static inline bool is_nommu_shared_vma_flags(const vma_flags_t *flags)
 }
 #endif
 
-#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
-#define SECTION_IN_PAGE_FLAGS
-#endif
-
 /*
  * The identification function is mainly used by the buddy allocator for
  * determining if two pages could be buddies. We are not really identifying
@@ -2805,7 +2801,7 @@ static inline struct zone *folio_zone(const struct folio *folio)
 	return &folio_pgdat(folio)->node_zones[folio_zonenum(folio)];
 }
 
-#ifdef SECTION_IN_PAGE_FLAGS
+#ifdef CONFIG_SPARSEMEM_CLASSIC
 static inline void set_page_section(struct page *page, unsigned long section)
 {
 	page->flags.f &= ~(SECTIONS_MASK << SECTIONS_PGSHIFT);
@@ -2823,7 +2819,7 @@ static inline unsigned long memdesc_section(const memdesc_flags_t *mdf)
 	ASSERT_EXCLUSIVE_BITS(mdf->f, SECTIONS_MASK << SECTIONS_PGSHIFT);
 	return (mdf->f >> SECTIONS_PGSHIFT) & SECTIONS_MASK;
 }
-#else /* !SECTION_IN_PAGE_FLAGS */
+#else /* !CONFIG_SPARSEMEM_CLASSIC */
 static inline void set_page_section_from_pfn(struct page *page,
 		unsigned long pfn)
 {
@@ -2833,7 +2829,7 @@ static inline unsigned long memdesc_section(const memdesc_flags_t *mdf)
 {
 	return 0;
 }
-#endif /* SECTION_IN_PAGE_FLAGS */
+#endif /* CONFIG_SPARSEMEM_CLASSIC */
 
 /**
  * folio_pfn - Return the Page Frame Number of a folio.
include/linux/mmzone.h +1 -1
index ebbda6f31139..c83529ad6e35 100644
@@ -68,7 +68,7 @@
  * memory sections).
  */
 #define MAX_FOLIO_ORDER		MAX_PAGE_ORDER
-#elif defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
+#elif defined(CONFIG_SPARSEMEM_CLASSIC)
 /*
  * Only pages within a single memory section are guaranteed to be
  * contiguous. By limiting folios to a single memory section, all folio
include/linux/page-flags-layout.h +1 -1
index 760006b1c480..536003b364a7 100644
@@ -49,7 +49,7 @@
  *      " plus space for last_cpupid: | SECTION | NODE | ZONE | LAST_CPUPID ... | FLAGS |
  * classic sparse no space for node:  | SECTION |     ZONE    | ... | FLAGS |
  */
-#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
+#ifdef CONFIG_SPARSEMEM_CLASSIC
 #define SECTIONS_WIDTH		SECTIONS_SHIFT
 #else
 #define SECTIONS_WIDTH		0
mm/Kconfig +3 -0
index 30170a936f1f..c7bbcf086f21 100644
@@ -461,6 +461,9 @@ config SPARSEMEM_VMEMMAP
 	  pfn_to_page and page_to_pfn operations.  This is the most
 	  efficient option when sufficient kernel resources are available.
 
+config SPARSEMEM_CLASSIC
+	def_bool SPARSEMEM && !SPARSEMEM_VMEMMAP
+
 config VMEMMAP_OPTIMIZATION
 	bool
 	depends on SPARSEMEM_VMEMMAP
mm/util.c +1 -1
index c5ee52aede1e..6910b47ca415 100644
@@ -1590,7 +1590,7 @@ unsigned int folio_pte_batch(struct folio *folio, pte_t *ptep, pte_t pte,
 }
 #endif /* CONFIG_MMU */
 
-#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
+#ifdef CONFIG_SPARSEMEM_CLASSIC
 /**
  * page_range_contiguous - test whether the page range is contiguous
  * @page: the start of the page range.
Signature · 1 line
2.54.0 (Apple Git-157)
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

Several MM paths identify classic sparse memory by testing CONFIG_SPARSEMEM while also testing that CONFIG_SPARSEMEM_VMEMMAP is disabled. Repeating the compound condition obscures the memory model being selected and requires the local SECTION_IN_PAGE_FLAGS alias for the same state.

Add CONFIG_SPARSEMEM_CLASSIC as a hidden derived option and use it at the conditional sites. Remove SECTION_IN_PAGE_FLAGS and test the new option directly.

Quoted 7 lines

The x86 32-bit vDSO build starts with the x86_64 configuration and then undefines CONFIG_SPARSEMEM_VMEMMAP to emulate a 32-bit configuration. Kconfig-derived symbols are not recomputed by the C preprocessor, so define CONFIG_SPARSEMEM_CLASSIC there when CONFIG_SPARSEMEM is enabled. This preserves the existing behavior.

Thanks.

#2 lore raw
In reply to Kaitao Cheng
Quoted 11 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

Several MM paths identify classic sparse memory by testing CONFIG_SPARSEMEM while also testing that CONFIG_SPARSEMEM_VMEMMAP is disabled. Repeating the compound condition obscures the memory model being selected and requires the local SECTION_IN_PAGE_FLAGS alias for the same state.

Add CONFIG_SPARSEMEM_CLASSIC as a hidden derived option and use it at the conditional sites. Remove SECTION_IN_PAGE_FLAGS and test the new option directly.

Sorry, but reading CONFIG_SPARSEMEM_CLASSIC I would have no idea how it relates to VMEMMAP.

CONFIG_SPARSEMEM && !CONFIG_SPARSEMEM_VMEMMAP

is pretty clear in comparison.

Signature · 3 lines
Cheers,

David
#3 lore raw
Quoted 13 lines · David Hildenbrand (Arm)
Quoted 11 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

Several MM paths identify classic sparse memory by testing CONFIG_SPARSEMEM while also testing that CONFIG_SPARSEMEM_VMEMMAP is disabled. Repeating the compound condition obscures the memory model being selected and requires the local SECTION_IN_PAGE_FLAGS alias for the same state.

Add CONFIG_SPARSEMEM_CLASSIC as a hidden derived option and use it at the conditional sites. Remove SECTION_IN_PAGE_FLAGS and test the new option directly.

Quoted 6 lines

Sorry, but reading CONFIG_SPARSEMEM_CLASSIC I would have no idea how it relates to VMEMMAP.

CONFIG_SPARSEMEM && !CONFIG_SPARSEMEM_VMEMMAP

is pretty clear in comparison.

Probably there could be an argument to clearly differentiate base and vmemmmap sparsemem mechanisms, but the proposed patch here does not make it any better.

Quoted 5 lines
Signature · 4 lines
-- 
Cheers,

David