Commit b584c254 authored by Oliver O'Halloran's avatar Oliver O'Halloran Committed by Michael Ellerman

powerpc/vmemmap: Add altmap support

Adds support to powerpc for the altmap feature of ZONE_DEVICE memory. An
altmap is a driver provided region that is used to provide the backing
storage for the struct pages of ZONE_DEVICE memory. In situations where
large amount of ZONE_DEVICE memory is being added to the system the
altmap reduces pressure on main system memory by allowing the mm/
metadata to be stored on the device itself rather in main memory.
Reviewed-by: default avatarBalbir Singh <bsingharora@gmail.com>
Signed-off-by: default avatarOliver O'Halloran <oohall@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent d7d9b612
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/of_fdt.h> #include <linux/of_fdt.h>
#include <linux/libfdt.h> #include <linux/libfdt.h>
#include <linux/memremap.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#include <asm/page.h> #include <asm/page.h>
...@@ -192,13 +193,17 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node) ...@@ -192,13 +193,17 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node)
pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node); pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node);
for (; start < end; start += page_size) { for (; start < end; start += page_size) {
struct vmem_altmap *altmap;
void *p; void *p;
int rc; int rc;
if (vmemmap_populated(start, page_size)) if (vmemmap_populated(start, page_size))
continue; continue;
p = vmemmap_alloc_block(page_size, node); /* altmap lookups only work at section boundaries */
altmap = to_vmem_altmap(SECTION_ALIGN_DOWN(start));
p = __vmemmap_alloc_block_buf(page_size, node, altmap);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
...@@ -263,6 +268,8 @@ void __ref vmemmap_free(unsigned long start, unsigned long end) ...@@ -263,6 +268,8 @@ void __ref vmemmap_free(unsigned long start, unsigned long end)
for (; start < end; start += page_size) { for (; start < end; start += page_size) {
unsigned long nr_pages, addr; unsigned long nr_pages, addr;
struct vmem_altmap *altmap;
struct page *section_base;
struct page *page; struct page *page;
/* /*
...@@ -278,9 +285,13 @@ void __ref vmemmap_free(unsigned long start, unsigned long end) ...@@ -278,9 +285,13 @@ void __ref vmemmap_free(unsigned long start, unsigned long end)
continue; continue;
page = pfn_to_page(addr >> PAGE_SHIFT); page = pfn_to_page(addr >> PAGE_SHIFT);
section_base = pfn_to_page(vmemmap_section_start(start));
nr_pages = 1 << page_order; nr_pages = 1 << page_order;
if (PageReserved(page)) { altmap = to_vmem_altmap((unsigned long) section_base);
if (altmap) {
vmem_altmap_free(altmap, nr_pages);
} else if (PageReserved(page)) {
/* allocated from bootmem */ /* allocated from bootmem */
if (page_size < PAGE_SIZE) { if (page_size < PAGE_SIZE) {
/* /*
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <linux/hugetlb.h> #include <linux/hugetlb.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/memremap.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#include <asm/prom.h> #include <asm/prom.h>
...@@ -159,11 +160,20 @@ int arch_remove_memory(u64 start, u64 size) ...@@ -159,11 +160,20 @@ int arch_remove_memory(u64 start, u64 size)
{ {
unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long start_pfn = start >> PAGE_SHIFT;
unsigned long nr_pages = size >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT;
struct zone *zone; struct vmem_altmap *altmap;
struct page *page;
int ret; int ret;
zone = page_zone(pfn_to_page(start_pfn)); /*
ret = __remove_pages(zone, start_pfn, nr_pages); * If we have an altmap then we need to skip over any reserved PFNs
* when querying the zone.
*/
page = pfn_to_page(start_pfn);
altmap = to_vmem_altmap((unsigned long) page);
if (altmap)
page += vmem_altmap_offset(altmap);
ret = __remove_pages(page_zone(page), start_pfn, nr_pages);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment