[PATCH 5/6] powerpc: Implement DISCONTIGMEM and allow selection on PPC32
From: Jonathan NeuschÃfer
Date: Tue Feb 20 2018 - 11:22:05 EST
The implementation of pfn_to_nid and pfn_valid in mmzone.h is based on
arch/metag's implementation.
Signed-off-by: Jonathan NeuschÃfer <j.neuschaefer@xxxxxxx>
---
NOTE: Checking NODE_DATA(nid) in pfn_to_nid appears to be uncommon.
Running up to MAX_NUMNODES instead of checking NODE_DATA(nid) would
require the node_data array to be filled with valid pointers.
---
arch/powerpc/Kconfig | 5 ++++-
arch/powerpc/include/asm/mmzone.h | 21 +++++++++++++++++++++
arch/powerpc/mm/numa.c | 7 +++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 73ce5dd07642..c2633b7b8ed9 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -639,7 +639,6 @@ config HAVE_MEMORYLESS_NODES
config ARCH_SELECT_MEMORY_MODEL
def_bool y
- depends on PPC64
config ARCH_FLATMEM_ENABLE
def_bool y
@@ -654,6 +653,10 @@ config ARCH_SPARSEMEM_DEFAULT
def_bool y
depends on PPC_BOOK3S_64
+config ARCH_DISCONTIGMEM_ENABLE
+ def_bool y
+ depends on PPC32
+
config SYS_SUPPORTS_HUGETLBFS
bool
diff --git a/arch/powerpc/include/asm/mmzone.h b/arch/powerpc/include/asm/mmzone.h
index 91c69ff53a8a..1684a5c98d23 100644
--- a/arch/powerpc/include/asm/mmzone.h
+++ b/arch/powerpc/include/asm/mmzone.h
@@ -26,6 +26,27 @@ extern struct pglist_data *node_data[];
*/
#define NODE_DATA(nid) (node_data[nid])
+static inline int pfn_to_nid(unsigned long pfn)
+{
+ int nid;
+
+ for (nid = 0; nid < MAX_NUMNODES && NODE_DATA(nid); nid++)
+ if (pfn >= node_start_pfn(nid) && pfn <= node_end_pfn(nid))
+ return nid;
+
+ return -1;
+}
+
+static inline int pfn_valid(int pfn)
+{
+ int nid = pfn_to_nid(pfn);
+
+ if (nid >= 0)
+ return pfn < node_end_pfn(nid);
+
+ return 0;
+}
+
/*
* Following are specific to this numa platform.
*/
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index dfe279529463..ec47f1081509 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -744,6 +744,13 @@ static void __init setup_nonnuma(void)
PFN_PHYS(end_pfn - start_pfn),
&memblock.memory, nid);
node_set_online(nid);
+
+ /*
+ * On DISCONTIGMEM systems, place different memory blocks into
+ * different nodes.
+ */
+ if (IS_ENABLED(CONFIG_DISCONTIGMEM) && nid < MAX_NUMNODES - 1)
+ nid++;
}
}
--
2.16.1