Skip to content

Commit 2beea70

Browse files
jpemartinsakpm00
authored andcommitted
mm/sparse-vmemmap: refactor core of vmemmap_populate_basepages() to helper
In preparation for describing a memmap with compound pages, move the actual pte population logic into a separate function vmemmap_populate_address() and have a new helper vmemmap_populate_range() walk through all base pages it needs to populate. While doing that, change the helper to use a pte_t* as return value, rather than an hardcoded errno of 0 or -ENOMEM. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Joao Martins <[email protected]> Reviewed-by: Muchun Song <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Dan Williams <[email protected]> Cc: Jane Chu <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Vishal Verma <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e3246d8 commit 2beea70

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

mm/sparse-vmemmap.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -608,38 +608,57 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
608608
return pgd;
609609
}
610610

611-
int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end,
612-
int node, struct vmem_altmap *altmap)
611+
static pte_t * __meminit vmemmap_populate_address(unsigned long addr, int node,
612+
struct vmem_altmap *altmap)
613613
{
614-
unsigned long addr = start;
615614
pgd_t *pgd;
616615
p4d_t *p4d;
617616
pud_t *pud;
618617
pmd_t *pmd;
619618
pte_t *pte;
620619

620+
pgd = vmemmap_pgd_populate(addr, node);
621+
if (!pgd)
622+
return NULL;
623+
p4d = vmemmap_p4d_populate(pgd, addr, node);
624+
if (!p4d)
625+
return NULL;
626+
pud = vmemmap_pud_populate(p4d, addr, node);
627+
if (!pud)
628+
return NULL;
629+
pmd = vmemmap_pmd_populate(pud, addr, node);
630+
if (!pmd)
631+
return NULL;
632+
pte = vmemmap_pte_populate(pmd, addr, node, altmap);
633+
if (!pte)
634+
return NULL;
635+
vmemmap_verify(pte, node, addr, addr + PAGE_SIZE);
636+
637+
return pte;
638+
}
639+
640+
static int __meminit vmemmap_populate_range(unsigned long start,
641+
unsigned long end, int node,
642+
struct vmem_altmap *altmap)
643+
{
644+
unsigned long addr = start;
645+
pte_t *pte;
646+
621647
for (; addr < end; addr += PAGE_SIZE) {
622-
pgd = vmemmap_pgd_populate(addr, node);
623-
if (!pgd)
624-
return -ENOMEM;
625-
p4d = vmemmap_p4d_populate(pgd, addr, node);
626-
if (!p4d)
627-
return -ENOMEM;
628-
pud = vmemmap_pud_populate(p4d, addr, node);
629-
if (!pud)
630-
return -ENOMEM;
631-
pmd = vmemmap_pmd_populate(pud, addr, node);
632-
if (!pmd)
633-
return -ENOMEM;
634-
pte = vmemmap_pte_populate(pmd, addr, node, altmap);
648+
pte = vmemmap_populate_address(addr, node, altmap);
635649
if (!pte)
636650
return -ENOMEM;
637-
vmemmap_verify(pte, node, addr, addr + PAGE_SIZE);
638651
}
639652

640653
return 0;
641654
}
642655

656+
int __meminit vmemmap_populate_basepages(unsigned long start, unsigned long end,
657+
int node, struct vmem_altmap *altmap)
658+
{
659+
return vmemmap_populate_range(start, end, node, altmap);
660+
}
661+
643662
struct page * __meminit __populate_section_memmap(unsigned long pfn,
644663
unsigned long nr_pages, int nid, struct vmem_altmap *altmap,
645664
struct dev_pagemap *pgmap)

0 commit comments

Comments
 (0)