Generalize vmemmap_populate_hugepages to sparc
Subsystems (3)
v6 cover Generalize vmemmap_populate_hugepages to sparc
Change sparc's implementation of vmemmap_populate() using vmemmap_populate_hugepages() to streamline the code. Another benefit is that it allows us to eliminate the external declarations of vmemmap_p?d_populate functions and convert them to static functions.
Since vmemmap_populate_hugepages may fallback to vmemmap_populate- _basepages, which differs from sparc's original implementation. During the v1 discussion with Mike Rapoport, sparc uses base pages in the kernel page tables, so it should be able to use them in vmemmap as well. Consequently, no additional special handling is required.
Changes in v6:
- Ignore handling of altmap
Changes in v5:
- Remove [PATCH v4 3/3] sparc: Remove unnecessary whitespace
Changes in v4:
- Add commit message
- Add verification that pmd actually maps a large page in the vmemmap_check_pmd function
Changes in v3:
- Allow sparc to fallback to vmemmap_populate_basepages
- Convert vmemmap_p?d_populate() to static functions
- Split the v1 patch
Changes in v2:
- Revert the whitespace deletions
- Change vmemmap_false_pmd to vmemmap_pte_fallback_allowed
Link to V5:
https://lore.kernel.org/all/[email protected]/
Link to V4:
https://lore.kernel.org/all/[email protected]/
Link to V3:
https://lore.kernel.org/all/[email protected]/
Link to V2:
https://lore.kernel.org/all/[email protected]/
Link to V1:
https://lore.kernel.org/all/[email protected]/
Chengkaitao (2):
sparc: Use vmemmap_populate_hugepages for vmemmap_populate
mm: Convert vmemmap_p?d_populate() to static functions
arch/sparc/mm/init_64.c | 47 ++++++++++++++--------------------------- include/linux/mm.h | 7 ------ mm/sparse-vmemmap.c | 10 ++++----- 3 files changed, 21 insertions(+), 43 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v6 1/2 sparc: Use vmemmap_populate_hugepages for vmemmap_populate
From: Chengkaitao <[email protected]>
1. In the SPARC architecture, reimplement vmemmap_populate using vmemmap_populate_hugepages.
2. Allow the SPARC arch to fallback to vmemmap_populate_basepages(), when vmemmap_alloc_block returns NULL.
--- arch/sparc/mm/init_64.c | 47 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 31 deletions(-)
arch/sparc/mm/init_64.c +16 -31
@@ -2581,8 +2581,8 @@ unsigned long _PAGE_CACHE __read_mostly;EXPORT_SYMBOL (_PAGE_CACHE);#ifdef CONFIG_SPARSEMEM_VMEMMAP -int __meminit vmemmap_populate (unsigned long vstart,unsigned long vend, -int node,struct vmem_altmap *altmap) +void __meminit vmemmap_set_pmd (pmd_t *pmd,void *p,int node, +unsigned long addr,unsigned long next) {unsigned long pte_base;
@@ -2595,39 +2595,24 @@ int __meminit vmemmap_populate(unsigned long vstart, unsigned long vend, pte_base |= _PAGE_PMD_HUGE; - vstart = vstart &PMD_MASK ; - vend =ALIGN (vend,PMD_SIZE ); -for (; vstart < vend; vstart +=PMD_SIZE ) { -pgd_t *pgd =vmemmap_pgd_populate (vstart, node); -unsigned long pte; -p4d_t *p4d; -pud_t *pud; -pmd_t *pmd; - -if (!pgd) -return -ENOMEM ; - - p4d =vmemmap_p4d_populate (pgd, vstart, node); -if (!p4d) -return -ENOMEM ; - - pud =vmemmap_pud_populate (p4d, vstart, node); -if (!pud) -return -ENOMEM ; + pmd_val(*pmd) = pte_base | __pa(p); +} - pmd =pmd_offset (pud, vstart); - pte =pmd_val (*pmd); -if (!(pte & _PAGE_VALID)) { -void *block =vmemmap_alloc_block (PMD_SIZE , node); +int __meminit vmemmap_check_pmd (pmd_t *pmdp,int node, +unsigned long addr,unsigned long next) +{ +int large =pmd_leaf (*pmdp); -if (!block) -return -ENOMEM ; +if (large) +vmemmap_verify ((pte_t *)pmdp, node, addr, next); -pmd_val (*pmd) = pte_base |__pa (block); - } - } +return large; +} - return 0; +int __meminit vmemmap_populate (unsigned long vstart,unsigned long vend, +int node,struct vmem_altmap *altmap) +{ +return vmemmap_populate_hugepages (vstart, vend, node,NULL ); }#endif /* CONFIG_SPARSEMEM_VMEMMAP */
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v6 1/2] sparc: Use vmemmap_populate_hugepages for vmemmap_populate
Quoted 71 lines · chengkaitao
From: Chengkaitao <[email protected]>
1. In the SPARC architecture, reimplement
vmemmap_populateusingvmemmap_populate_hugepages.
2. Allow the SPARC arch to fallback tovmemmap_populate_basepages(), whenvmemmap_alloc_blockreturns NULL.Signed-off-by Chengkaitao <[email protected]>--- arch/sparc/mm/init_64.c | 47 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 31 deletions(-)arch/sparc/mm/init_64.c +11
-30@@ -2581,8 +2581,8 @@ unsigned long _PAGE_CACHE __read_mostly;EXPORT_SYMBOL (_PAGE_CACHE);#ifdef CONFIG_SPARSEMEM_VMEMMAP -int __meminit vmemmap_populate (unsigned long vstart,unsigned long vend, -int node,struct vmem_altmap *altmap) +void __meminit vmemmap_set_pmd (pmd_t *pmd,void *p,int node, +unsigned long addr,unsigned long next) {unsigned long pte_base;@@ -2595,39 +2595,24 @@ int __meminit vmemmap_populate(unsigned long vstart, unsigned long vend, pte_base |= _PAGE_PMD_HUGE; - vstart = vstart &PMD_MASK ; - vend =ALIGN (vend,PMD_SIZE ); -for (; vstart < vend; vstart +=PMD_SIZE ) { -pgd_t *pgd =vmemmap_pgd_populate (vstart, node); -unsigned long pte; -p4d_t *p4d; -pud_t *pud; -pmd_t *pmd; - -if (!pgd) -return -ENOMEM ; - - p4d =vmemmap_p4d_populate (pgd, vstart, node); -if (!p4d) -return -ENOMEM ; - - pud =vmemmap_pud_populate (p4d, vstart, node); -if (!pud) -return -ENOMEM ; +pmd_val (*pmd) = pte_base |__pa (p); +} - pmd =pmd_offset (pud, vstart); - pte =pmd_val (*pmd); -if (!(pte & _PAGE_VALID)) { -void *block =vmemmap_alloc_block (PMD_SIZE , node); +int __meminit vmemmap_check_pmd (pmd_t *pmdp,int node, +unsigned long addr,unsigned long next) +{ +int large =pmd_leaf (*pmdp); -if (!block) -return -ENOMEM ; +if (large) +vmemmap_verify ((pte_t *)pmdp, node, addr, next); -pmd_val (*pmd) = pte_base |__pa (block); - } - } +return large;
arch/sparc/mm/init_64.c int __meminit vmemmap_populate(unsigned long vstart, unsigned long vend, · line 2618
Quoted 10 lines
arch/sparc/mm/init_64.c +5
-1+} - return 0; +int __meminit vmemmap_populate (unsigned long vstart,unsigned long vend, +int node,struct vmem_altmap *altmap) +{ +return vmemmap_populate_hugepages (vstart, vend, node,NULL ); }#endif /* CONFIG_SPARSEMEM_VMEMMAP */
I assume this goes through the mm tree.
Cheers,
Andreas
PATCH v6 2/2 mm: Convert vmemmap_p?d_populate() to static functions
In reply to chengkaitaoFrom: Chengkaitao <[email protected]>
Since the vmemmap_p?d_populate functions are unused outside the mm subsystem, we can remove their external declarations and convert them to static functions.
--- include/linux/mm.h | 7 ------- mm/sparse-vmemmap.c | 10 +++++----- 2 files changed, 5 insertions(+), 12 deletions(-)
include/linux/mm.h +0 -7
@@ -4238,13 +4238,6 @@ unsigned long section_map_size(void);struct page *__populate_section_memmap (unsigned long pfn,unsigned long nr_pages,int nid,struct vmem_altmap *altmap,struct dev_pagemap *pgmap); -pgd_t *vmemmap_pgd_populate (unsigned long addr,int node); -p4d_t *vmemmap_p4d_populate (pgd_t *pgd,unsigned long addr,int node); -pud_t *vmemmap_pud_populate (p4d_t *p4d,unsigned long addr,int node); -pmd_t *vmemmap_pmd_populate (pud_t *pud,unsigned long addr,int node); -pte_t *vmemmap_pte_populate (pmd_t *pmd,unsigned long addr,int node, -struct vmem_altmap *altmap,unsigned long ptpfn, -unsigned long flags);void *vmemmap_alloc_block (unsigned long size,int node);struct vmem_altmap ; void *vmemmap_alloc_block_buf(unsigned long size, int node,
mm/sparse-vmemmap.c +5 -5
@@ -151,7 +151,7 @@ void __meminit vmemmap_verify(pte_t *pte, int node, start, end - 1); } -pte_t *__meminit vmemmap_pte_populate (pmd_t *pmd,unsigned long addr,int node, +static pte_t *__meminit vmemmap_pte_populate (pmd_t *pmd,unsigned long addr,int node,struct vmem_altmap *altmap,unsigned long ptpfn,unsigned long flags) {
@@ -195,7 +195,7 @@ static void * __meminit vmemmap_alloc_block_zero(unsigned long size, int node)return p; } -pmd_t *__meminit vmemmap_pmd_populate (pud_t *pud,unsigned long addr,int node) +static pmd_t *__meminit vmemmap_pmd_populate (pud_t *pud,unsigned long addr,int node) {pmd_t *pmd =pmd_offset (pud, addr);if (pmd_none (*pmd)) {
@@ -208,7 +208,7 @@ pmd_t * __meminit vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node)return pmd; } -pud_t *__meminit vmemmap_pud_populate (p4d_t *p4d,unsigned long addr,int node) +static pud_t *__meminit vmemmap_pud_populate (p4d_t *p4d,unsigned long addr,int node) {pud_t *pud =pud_offset (p4d, addr);if (pud_none (*pud)) {
@@ -221,7 +221,7 @@ pud_t * __meminit vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node)return pud; } -p4d_t *__meminit vmemmap_p4d_populate (pgd_t *pgd,unsigned long addr,int node) +static p4d_t *__meminit vmemmap_p4d_populate (pgd_t *pgd,unsigned long addr,int node) {p4d_t *p4d =p4d_offset (pgd, addr);if (p4d_none (*p4d)) {
@@ -234,7 +234,7 @@ p4d_t * __meminit vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node)return p4d; } -pgd_t *__meminit vmemmap_pgd_populate (unsigned long addr,int node) +static pgd_t *__meminit vmemmap_pgd_populate (unsigned long addr,int node) {pgd_t *pgd =pgd_offset_k (addr);if (pgd_none (*pgd)) {
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v6 2/2] mm: Convert vmemmap_p?d_populate() to static functions
Quoted 8 lines · chengkaitao
From: Chengkaitao <[email protected]>
Since the vmemmap_p?d_populate functions are unused outside the mm subsystem, we can remove their external declarations and convert them to static functions.
Signed-off-by Chengkaitao <[email protected]>---
Signature · 3 lines
Cheers David
Re: [PATCH v6 2/2] mm: Convert vmemmap_p?d_populate() to static functions
In reply to chengkaitaoHi Andrew Morton,
I noticed this patch was dropped; the failure report is here:
https://lore.kernel.org/all/[email protected]/#R
Could this be a false positive? The series has two patches: the first one already removed references to vmemmap_p?d_populate() on sparc; see:
https://lore.kernel.org/all/[email protected]/T/#mefaa36aeff173d08f0508cd44be46e830c067fe9
Might the build error be because only the second patch was applied, without the first?
Quoted 83 lines · chengkaitao
From: Chengkaitao <[email protected]>
Since the vmemmap_p?d_populate functions are unused outside the mm subsystem, we can remove their external declarations and convert them to static functions.
Signed-off-by Chengkaitao <[email protected]>--- include/linux/mm.h | 7 ------- mm/sparse-vmemmap.c | 10 +++++----- 2 files changed, 5 insertions(+), 12 deletions(-)include/linux/mm.h +0
-7@@ -4238,13 +4238,6 @@ unsigned long section_map_size(void);struct page *__populate_section_memmap (unsigned long pfn,unsigned long nr_pages,int nid,struct vmem_altmap *altmap,struct dev_pagemap *pgmap); -pgd_t *vmemmap_pgd_populate (unsigned long addr,int node); -p4d_t *vmemmap_p4d_populate (pgd_t *pgd,unsigned long addr,int node); -pud_t *vmemmap_pud_populate (p4d_t *p4d,unsigned long addr,int node); -pmd_t *vmemmap_pmd_populate (pud_t *pud,unsigned long addr,int node); -pte_t *vmemmap_pte_populate (pmd_t *pmd,unsigned long addr,int node, -struct vmem_altmap *altmap,unsigned long ptpfn, -unsigned long flags);void *vmemmap_alloc_block (unsigned long size,int node);struct vmem_altmap ; void *vmemmap_alloc_block_buf(unsigned long size, int node,mm/sparse-vmemmap.c +5
-6@@ -151,7 +151,7 @@ void __meminit vmemmap_verify(pte_t *pte, int node, start, end - 1); } -pte_t *__meminit vmemmap_pte_populate (pmd_t *pmd,unsigned long addr,int node, +static pte_t *__meminit vmemmap_pte_populate (pmd_t *pmd,unsigned long addr,int node,struct vmem_altmap *altmap,unsigned long ptpfn,unsigned long flags) {@@ -195,7 +195,7 @@ static void * __meminit vmemmap_alloc_block_zero(unsigned long size, int node)return p; } -pmd_t *__meminit vmemmap_pmd_populate (pud_t *pud,unsigned long addr,int node) +static pmd_t *__meminit vmemmap_pmd_populate (pud_t *pud,unsigned long addr,int node) {pmd_t *pmd =pmd_offset (pud, addr);if (pmd_none (*pmd)) {@@ -208,7 +208,7 @@ pmd_t * __meminit vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node)return pmd; } -pud_t *__meminit vmemmap_pud_populate (p4d_t *p4d,unsigned long addr,int node) +static pud_t *__meminit vmemmap_pud_populate (p4d_t *p4d,unsigned long addr,int node) {pud_t *pud =pud_offset (p4d, addr);if (pud_none (*pud)) {@@ -221,7 +221,7 @@ pud_t * __meminit vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node)return pud; } -p4d_t *__meminit vmemmap_p4d_populate (pgd_t *pgd,unsigned long addr,int node) +static p4d_t *__meminit vmemmap_p4d_populate (pgd_t *pgd,unsigned long addr,int node) {p4d_t *p4d =p4d_offset (pgd, addr);if (p4d_none (*p4d)) {@@ -234,7 +234,7 @@ p4d_t * __meminit vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node)return p4d; } -pgd_t *__meminit vmemmap_pgd_populate (unsigned long addr,int node) +static pgd_t *__meminit vmemmap_pgd_populate (unsigned long addr,int node) {pgd_t *pgd =pgd_offset_k (addr);if (pgd_none (*pgd)) { --2.50.1 (Apple Git-155)
Signature · 2 lines
Yours, Chengkaitao
Andrew Morton
maintainerRe: [PATCH v6 2/2] mm: Convert vmemmap_p?d_populate() to static functions
Quoted 11 lines · On Tue, 31 Mar 2026 11:16:33 +0800 Chengkaitao <[email protected]> wrote:
Hi Andrew Morton,
I noticed this patch was dropped; the failure report is here:
https://lore.kernel.org/all/[email protected]/#RCould this be a false positive? The series has two patches: the first one already removed references to vmemmap_p?d_populate() on sparc; see:
https://lore.kernel.org/all/[email protected]/T/#mefaa36aeff173d08f0508cd44be46e830c067fe9Might the build error be because only the second patch was applied, without the first?
There was some confusion over a later patch which was there to fix an earlier patch, only the earlier patch was dropped!
Sorry 'bout that. Can you please resend the patch after -rc1 and we'll try again.