Skip to content

Commit 56993b4

Browse files
Anshuman Khandualtorvalds
authored andcommitted
mm/sparsemem: enable vmem_altmap support in vmemmap_alloc_block_buf()
There are many instances where vmemap allocation is often switched between regular memory and device memory just based on whether altmap is available or not. vmemmap_alloc_block_buf() is used in various platforms to allocate vmemmap mappings. Lets also enable it to handle altmap based device memory allocation along with existing regular memory allocations. This will help in avoiding the altmap based allocation switch in many places. To summarize there are two different methods to call vmemmap_alloc_block_buf(). vmemmap_alloc_block_buf(size, node, NULL) /* Allocate from system RAM */ vmemmap_alloc_block_buf(size, node, altmap) /* Allocate from altmap */ This converts altmap_alloc_block_buf() into a static function, drops it's entry from the header and updates Documentation/vm/memory-model.rst. Suggested-by: Robin Murphy <[email protected]> Signed-off-by: Anshuman Khandual <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Tested-by: Jia He <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Will Deacon <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Dan Williams <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Hsin-Yi Wang <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Mark Rutland <[email protected]> Cc: "Matthew Wilcox (Oracle)" <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: Steve Capper <[email protected]> Cc: Tony Luck <[email protected]> Cc: Yu Zhao <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1d9cfee commit 56993b4

File tree

6 files changed

+20
-25
lines changed

6 files changed

+20
-25
lines changed

Documentation/vm/memory-model.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ for persistent memory devices in pre-allocated storage on those
178178
devices. This storage is represented with :c:type:`struct vmem_altmap`
179179
that is eventually passed to vmemmap_populate() through a long chain
180180
of function calls. The vmemmap_populate() implementation may use the
181-
`vmem_altmap` along with :c:func:`altmap_alloc_block_buf` helper to
181+
`vmem_altmap` along with :c:func:`vmemmap_alloc_block_buf` helper to
182182
allocate memory map on the persistent memory device.
183183

184184
ZONE_DEVICE

arch/arm64/mm/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
11021102
if (pmd_none(READ_ONCE(*pmdp))) {
11031103
void *p = NULL;
11041104

1105-
p = vmemmap_alloc_block_buf(PMD_SIZE, node);
1105+
p = vmemmap_alloc_block_buf(PMD_SIZE, node, NULL);
11061106
if (!p)
11071107
return -ENOMEM;
11081108

arch/powerpc/mm/init_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
225225
* fall back to system memory if the altmap allocation fail.
226226
*/
227227
if (altmap && !altmap_cross_boundary(altmap, start, page_size)) {
228-
p = altmap_alloc_block_buf(page_size, altmap);
228+
p = vmemmap_alloc_block_buf(page_size, node, altmap);
229229
if (!p)
230230
pr_debug("altmap block allocation failed, falling back to system memory");
231231
}
232232
if (!p)
233-
p = vmemmap_alloc_block_buf(page_size, node);
233+
p = vmemmap_alloc_block_buf(page_size, node, NULL);
234234
if (!p)
235235
return -ENOMEM;
236236

arch/x86/mm/init_64.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,10 +1515,7 @@ static int __meminit vmemmap_populate_hugepages(unsigned long start,
15151515
if (pmd_none(*pmd)) {
15161516
void *p;
15171517

1518-
if (altmap)
1519-
p = altmap_alloc_block_buf(PMD_SIZE, altmap);
1520-
else
1521-
p = vmemmap_alloc_block_buf(PMD_SIZE, node);
1518+
p = vmemmap_alloc_block_buf(PMD_SIZE, node, altmap);
15221519
if (p) {
15231520
pte_t entry;
15241521

include/linux/mm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,8 +2982,8 @@ pte_t *vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node,
29822982
struct vmem_altmap *altmap);
29832983
void *vmemmap_alloc_block(unsigned long size, int node);
29842984
struct vmem_altmap;
2985-
void *vmemmap_alloc_block_buf(unsigned long size, int node);
2986-
void *altmap_alloc_block_buf(unsigned long size, struct vmem_altmap *altmap);
2985+
void *vmemmap_alloc_block_buf(unsigned long size, int node,
2986+
struct vmem_altmap *altmap);
29872987
void vmemmap_verify(pte_t *, int, unsigned long, unsigned long);
29882988
int vmemmap_populate_basepages(unsigned long start, unsigned long end,
29892989
int node, struct vmem_altmap *altmap);

mm/sparse-vmemmap.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,19 @@ void * __meminit vmemmap_alloc_block(unsigned long size, int node)
6969
__pa(MAX_DMA_ADDRESS));
7070
}
7171

72+
static void * __meminit altmap_alloc_block_buf(unsigned long size,
73+
struct vmem_altmap *altmap);
74+
7275
/* need to make sure size is all the same during early stage */
73-
void * __meminit vmemmap_alloc_block_buf(unsigned long size, int node)
76+
void * __meminit vmemmap_alloc_block_buf(unsigned long size, int node,
77+
struct vmem_altmap *altmap)
7478
{
75-
void *ptr = sparse_buffer_alloc(size);
79+
void *ptr;
80+
81+
if (altmap)
82+
return altmap_alloc_block_buf(size, altmap);
7683

84+
ptr = sparse_buffer_alloc(size);
7785
if (!ptr)
7886
ptr = vmemmap_alloc_block(size, node);
7987
return ptr;
@@ -94,15 +102,8 @@ static unsigned long __meminit vmem_altmap_nr_free(struct vmem_altmap *altmap)
94102
return 0;
95103
}
96104

97-
/**
98-
* altmap_alloc_block_buf - allocate pages from the device page map
99-
* @altmap: device page map
100-
* @size: size (in bytes) of the allocation
101-
*
102-
* Allocations are aligned to the size of the request.
103-
*/
104-
void * __meminit altmap_alloc_block_buf(unsigned long size,
105-
struct vmem_altmap *altmap)
105+
static void * __meminit altmap_alloc_block_buf(unsigned long size,
106+
struct vmem_altmap *altmap)
106107
{
107108
unsigned long pfn, nr_pfns, nr_align;
108109

@@ -147,10 +148,7 @@ pte_t * __meminit vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node,
147148
pte_t entry;
148149
void *p;
149150

150-
if (altmap)
151-
p = altmap_alloc_block_buf(PAGE_SIZE, altmap);
152-
else
153-
p = vmemmap_alloc_block_buf(PAGE_SIZE, node);
151+
p = vmemmap_alloc_block_buf(PAGE_SIZE, node, altmap);
154152
if (!p)
155153
return NULL;
156154
entry = pfn_pte(__pa(p) >> PAGE_SHIFT, PAGE_KERNEL);

0 commit comments

Comments
 (0)