Skip to contentSkip to conversation

i386: consolidate discontig functions into normal ones

RFC PATCH In review Dave Hansen 2 participants 5 messages Sep 12, 2005 Memory management

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 i386: consolidate discontig functions into normal ones

There are quite a few functions in i386's discontig.c which are actually NUMA-specific, not discontigmem. They are also very similar to the generic, flat functions found in setup.c.

This patch takes the versions in setup.c and makes them work for both NUMA and non-NUMA cases. In the process, quite a few nasty #ifdef and externs can be removed.

One of the main mechanisms to do this is that highstart_pfn and highend_pfn are now gone, replaced by node_start/end_pfn[]. However, this has no real impact on storage space, because those arrays are declared with a length of MAX_NUMNODES, which is 1 when NUMA is off.

---

 arch/i386/kernel/signal.c                |    0 
 memhotplug-dave/arch/i386/kernel/setup.c |  167 ++++++++++++++++++----
 memhotplug-dave/arch/i386/mm/discontig.c |  232 +++----------------------------
 memhotplug-dave/arch/i386/mm/init.c      |   43 +++--
 4 files changed, 186 insertions(+), 256 deletions(-)
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~i386-discontig-consolidate0 +24 -19
diff -puN arch/i386/mm/init.c~i386-discontig-consolidate0 arch/i386/mm/init.c
@@ -44,7 +44,6 @@
 unsigned int __VMALLOC_RESERVE = 128 << 20;
 
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
-unsigned long highstart_pfn, highend_pfn;
 
 static int noinline do_test_wp_bit(void);
 
@@ -310,18 +309,33 @@ void online_page(struct page *page)
 	add_one_highpage_hotplug(page, page_to_pfn(page));
 }
 
-
-#ifdef CONFIG_NUMA
-extern void set_highmem_pages_init(int);
-#else
-static void __init set_highmem_pages_init(int bad_ppro)
+void __init set_highmem_pages_init(int bad_ppro)
 {
-	int pfn;
-	for (pfn = highstart_pfn; pfn < highend_pfn; pfn++)
-		add_one_highpage_init(pfn_to_page(pfn), pfn, bad_ppro);
+	struct zone *zone;
+	struct page *page;
+
+	for_each_zone(zone) {
+		unsigned long node_pfn, zone_start_pfn, zone_end_pfn;
+
+		if (!is_highmem(zone))
+			continue;
+
+		zone_start_pfn = zone->zone_start_pfn;
+		zone_end_pfn = zone_start_pfn + zone->spanned_pages;
+
+		printk("Initializing %s for node %d (%08lx:%08lx)\n",
+				zone->name, zone->zone_pgdat->node_id,
+				zone_start_pfn, zone_end_pfn);
+
+		for (node_pfn = zone_start_pfn; node_pfn < zone_end_pfn; node_pfn++) {
+			if (!pfn_valid(node_pfn))
+				continue;
+			page = pfn_to_page(node_pfn);
+			add_one_highpage_init(page, node_pfn, bad_ppro);
+		}
+	}
 	totalram_pages += totalhigh_pages;
 }
-#endif /* CONFIG_FLATMEM */
 
 #else
 #define kmap_init() do { } while (0)
@@ -556,11 +570,6 @@ static void __init test_wp_bit(void)
 
 static void __init set_max_mapnr_init(void)
 {
-#ifdef CONFIG_HIGHMEM
-	num_physpages = highend_pfn;
-#else
-	num_physpages = max_low_pfn;
-#endif
 #ifdef CONFIG_FLATMEM
 	max_mapnr = num_physpages;
 #endif
@@ -594,11 +603,7 @@ void __init mem_init(void)
  
 	set_max_mapnr_init();
 
-#ifdef CONFIG_HIGHMEM
-	high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
-#else
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
-#endif
 
 	/* this will put all low memory onto the freelists */
 	totalram_pages += free_all_bootmem();
arch/i386/mm/discontig.c renamed from arch/i386/mm/discontig.c~i386-discontig-consolidate0 +26 -206

271 lines not on this page · raw message

diff -puN mm/page_alloc.c~i386-discontig-consolidate0 mm/page_alloc.c diff -puN mm/bootmem.c~i386-discontig-consolidate0 mm/bootmem.c

arch/i386/kernel/setup.c renamed from arch/i386/kernel/setup.c~i386-discontig-consolidate0 +136 -31

207 lines not on this page · raw message

diff -puN include/asm-i386/dma.h~i386-discontig-consolidate0 include/asm-i386/dma.h
diff -puN include/linux/mmzone.h~i386-discontig-consolidate0 include/linux/mmzone.h
diff -puN include/asm-i386/mmzone.h~i386-discontig-consolidate0 include/asm-i386/mmzone.h
diff -puN init/main.c~i386-discontig-consolidate0 init/main.c
diff -puN mm/memory.c~i386-discontig-consolidate0 mm/memory.c
diff -puN drivers/media/dvb/dvb-usb/dvb-usb-init.c~i386-discontig-consolidate0 drivers/media/dvb/dvb-usb/dvb-usb-init.c diff -puN include/asm-i386/page.h~i386-discontig-consolidate0 include/asm-i386/page.h
diff -puN arch/i386/kernel/numaq.c~i386-discontig-consolidate0 arch/i386/kernel/numaq.c
diff -puN arch/i386/kernel/signal.c~i386-discontig-consolidate0 arch/i386/kernel/signal.c
diff -L ser -puN /dev/null /dev/null
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

RFC PATCH 2/2 i386: move NUMA code into numa.c

This patch removes the final dependencies of CONFIG_NUMA on discontig.c. This is done by moving the NUMA KVA remap code from discontig.c into a new file: numa.c

---

 memhotplug-dave/arch/i386/kernel/setup.c          |    2 
 memhotplug-dave/arch/i386/mm/Makefile             |    3 
 memhotplug-dave/arch/i386/mm/discontig.c          |  177 ----------------------
 memhotplug-dave/arch/i386/mm/init.c               |    7 
 memhotplug-dave/arch/i386/mm/numa.c               |  167 ++++++++++++++++++++
 memhotplug-dave/include/asm-i386/mmzone.h         |    7 
 memhotplug-dave/include/asm-i386/pgtable-3level.h |    1 
 7 files changed, 177 insertions(+), 187 deletions(-)
arch/i386/mm/numa.c new file +167 -0
diff -puN /dev/null arch/i386/mm/numa.c
@@ -0,0 +1,167 @@
+#include <linux/bootmem.h>
+#include <linux/module.h>
+#include <linux/numa.h>
+
+#include <asm/pgtable.h>
+#include <asm/setup.h>
+
+unsigned long node_remap_start_pfn[MAX_NUMNODES];
+unsigned long node_remap_size[MAX_NUMNODES];
+unsigned long node_remap_offset[MAX_NUMNODES];
+void *node_remap_start_vaddr[MAX_NUMNODES];
+
+void *node_remap_end_vaddr[MAX_NUMNODES];
+void *node_remap_alloc_vaddr[MAX_NUMNODES];
+
+struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
+EXPORT_SYMBOL(node_data);
+
+/*
+ * Allocate memory for the pg_data_t for this node via a crude pre-bootmem
+ * method.  For node zero take this from the bottom of memory, for
+ * subsequent nodes place them at node_remap_start_vaddr which contains
+ * node local data in physically node local memory.  See setup_memory()
+ * for details.
+ */
+static bootmem_data_t node0_bdata;
+static void __init allocate_pgdat(int nid)
+{
+	if (nid && node_has_online_mem(nid))
+		NODE_DATA(nid) = (pg_data_t *)node_remap_start_vaddr[nid];
+	else {
+		NODE_DATA(nid) = (pg_data_t *)(__va(min_low_pfn << PAGE_SHIFT));
+		min_low_pfn += PFN_UP(sizeof(pg_data_t));
+		memset(NODE_DATA(0), 0, sizeof(struct pglist_data));
+		NODE_DATA(0)->bdata = &node0_bdata;
+	}
+}
+
+void setup_numa_kva_remap(void)
+{
+	int nid;
+	for_each_online_node(nid) {
+		if (NODE_DATA(nid))
+			continue;
+		node_remap_start_vaddr[nid] = pfn_to_kaddr(
+				max_low_pfn + node_remap_offset[nid]);
+		/* Init the node remap allocator */
+		node_remap_end_vaddr[nid] = node_remap_start_vaddr[nid] +
+			(node_remap_size[nid] * PAGE_SIZE);
+		node_remap_alloc_vaddr[nid] = node_remap_start_vaddr[nid] +
+			ALIGN(sizeof(pg_data_t), PAGE_SIZE);
+
+		allocate_pgdat(nid);
+		printk ("node %d will remap to vaddr %08lx - %08lx\n", nid,
+			(ulong) node_remap_start_vaddr[nid],
+			(ulong) pfn_to_kaddr(max_low_pfn
+			   + node_remap_offset[nid] + node_remap_size[nid]));
+	}
+}
+
+void *alloc_remap(int nid, unsigned long size)
+{
+	void *allocation = node_remap_alloc_vaddr[nid];
+
+	size = ALIGN(size, L1_CACHE_BYTES);
+
+	if (!allocation || (allocation + size) >= node_remap_end_vaddr[nid])
+		return 0;
+
+	node_remap_alloc_vaddr[nid] += size;
+	memset(allocation, 0, size);
+
+	return allocation;
+}
+
+void __init remap_numa_kva(void)
+{
+	void *vaddr;
+	unsigned long pfn;
+	int node;
+
+	for_each_online_node(node) {
+		for (pfn=0; pfn < node_remap_size[node]; pfn += PTRS_PER_PTE) {
+			vaddr = node_remap_start_vaddr[node]+(pfn<<PAGE_SHIFT);
+			set_pmd_pfn((ulong) vaddr,
+				node_remap_start_pfn[node] + pfn,
+				PAGE_KERNEL_LARGE);
+		}
+	}
+}
+
+unsigned long calculate_numa_remap_pages(void)
+{
+	int nid;
+	unsigned long size, reserve_pages = 0;
+	unsigned long pfn;
+
+	for_each_online_node(nid) {
+		/*
+		 * The acpi/srat node info can show hot-add memroy zones
+		 * where memory could be added but not currently present.
+		 */
+		if (node_start_pfn[nid] > max_pfn)
+			continue;
+		if (node_end_pfn[nid] > max_pfn)
+			node_end_pfn[nid] = max_pfn;
+
+		/* ensure the remap includes space for the pgdat. */
+		size = node_remap_size[nid] + sizeof(pg_data_t);
+
+		/* convert size to large (pmd size) pages, rounding up */
+		size = (size + PMD_SIZE - 1) / PMD_SIZE;
+		/* now the roundup is correct, convert to PAGE_SIZE pages */
+		size = size * PTRS_PER_PTE;
+
+		/*
+		 * Validate the region we are allocating only contains valid
+		 * pages.
+		 */
+		for (pfn = node_end_pfn[nid] - size;
+		     pfn < node_end_pfn[nid]; pfn++)
+			if (!page_is_ram(pfn))
+				break;
+
+		if (pfn != node_end_pfn[nid])
+			size = 0;
+
+		printk("Reserving %ld pages of KVA for lmem_map of node %d\n",
+				size, nid);
+		node_remap_size[nid] = size;
+		node_remap_offset[nid] = reserve_pages;
+		reserve_pages += size;
+		printk("Shrinking node %d from %ld pages to %ld pages\n",
+			nid, node_end_pfn[nid], node_end_pfn[nid] - size);
+
+		if (node_end_pfn[nid] & (PTRS_PER_PTE-1)) {
+			/*
+			 * Align node_end_pfn[] and node_remap_start_pfn[] to
+			 * pmd boundary. remap_numa_kva will barf otherwise.
+			 */
+			printk("Shrinking node %d further by %ld pages for proper alignment\n",
+				nid, node_end_pfn[nid] & (PTRS_PER_PTE-1));
+			size +=  node_end_pfn[nid] & (PTRS_PER_PTE-1);
+		}
+
+		node_end_pfn[nid] -= size;
+		node_remap_start_pfn[nid] = node_end_pfn[nid];
+	}
+	printk("Reserving total of %ld pages for numa KVA remap\n",
+			reserve_pages);
+	return reserve_pages;
+}
+
+/* Find the owning node for a pfn. */
+int early_pfn_to_nid(unsigned long pfn)
+{
+	int nid;
+
+	for_each_node(nid) {
+		if (node_end_pfn[nid] == 0)
+			break;
+		if (node_start_pfn[nid] <= pfn && node_end_pfn[nid] >= pfn)
+			return nid;
+	}
+
+	return 0;
+}
arch/i386/mm/discontig.c renamed from arch/i386/mm/discontig.c~i386-numa.c +0 -177

190 lines not on this page · raw message

arch/i386/mm/Makefile renamed from arch/i386/mm/Makefile~i386-numa.c +2 -1
diff -puN arch/i386/mm/Makefile~i386-numa.c arch/i386/mm/Makefile
@@ -4,7 +4,8 @@
 
 obj-y	:= init.o pgtable.o fault.o ioremap.o extable.o pageattr.o mmap.o
 
-obj-$(CONFIG_NUMA) += discontig.o
+obj-$(CONFIG_DISCONTIGMEM) += discontig.o
+obj-$(CONFIG_NUMA) += numa.o
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
 obj-$(CONFIG_HIGHMEM) += highmem.o
 obj-$(CONFIG_BOOT_IOREMAP) += boot_ioremap.o

diff -puN include/linux/mmzone.h~i386-numa.c include/linux/mmzone.h

include/asm-i386/mmzone.h renamed from include/asm-i386/mmzone.h~i386-numa.c +6 -1
diff -puN include/asm-i386/mmzone.h~i386-numa.c include/asm-i386/mmzone.h
@@ -38,10 +38,15 @@ static inline void get_memcfg_numa(void)
 }
 
 extern int early_pfn_to_nid(unsigned long pfn);
-
+extern void __init remap_numa_kva(void);
+extern unsigned long calculate_numa_remap_pages(void);
+extern void setup_numa_kva_remap(void);
 #else /* !CONFIG_NUMA */
 #define get_memcfg_numa get_memcfg_numa_flat
 #define get_zholes_size(n) (0)
+#define remap_numa_kva() do {} while (0)
+#define setup_numa_kva_remap() do {} while (0)
+#define calculate_numa_remap_pages()	(0)
 #endif /* CONFIG_NUMA */
 
 #ifdef CONFIG_DISCONTIGMEM
include/asm-i386/pgtable-3level.h renamed from include/asm-i386/pgtable-3level.h~i386-numa.c +1 -0
diff -puN include/asm-i386/pgtable-3level.h~i386-numa.c include/asm-i386/pgtable-3level.h
@@ -65,6 +65,7 @@ static inline void set_pte(pte_t *ptep, 
 		set_64bit((unsigned long long *)(pmdptr),pmd_val(pmdval))
 #define set_pud(pudptr,pudval) \
 		(*(pudptr) = (pudval))
+extern void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags);
 
 /*
  * Pentium-II erratum A13: in PAE mode we explicitly have to flush
arch/i386/kernel/setup.c renamed from arch/i386/kernel/setup.c~i386-numa.c +0 -2
diff -puN arch/i386/kernel/setup.c~i386-numa.c arch/i386/kernel/setup.c
@@ -1157,8 +1157,6 @@ static void __init find_max_pfn_node(int
 		BUG();
 }
 
-unsigned long calculate_numa_remap_pages(void);
-void setup_numa_kva_remap(void);
 void __init setup_bootmem_allocator(void);
 unsigned long __init setup_memory(void)
 {
arch/i386/mm/init.c renamed from arch/i386/mm/init.c~i386-numa.c +1 -6
diff -puN arch/i386/mm/init.c~i386-numa.c arch/i386/mm/init.c
@@ -36,6 +36,7 @@
 #include <asm/dma.h>
 #include <asm/fixmap.h>
 #include <asm/e820.h>
+#include <asm/mmzone.h>
 #include <asm/apic.h>
 #include <asm/tlb.h>
 #include <asm/tlbflush.h>
@@ -347,12 +348,6 @@ unsigned long long __PAGE_KERNEL = _PAGE
 EXPORT_SYMBOL(__PAGE_KERNEL);
 unsigned long long __PAGE_KERNEL_EXEC = _PAGE_KERNEL_EXEC;
 
-#ifdef CONFIG_NUMA
-extern void __init remap_numa_kva(void);
-#else
-#define remap_numa_kva() do {} while (0)
-#endif
-
 static void __init pagetable_init (void)
 {
 	unsigned long vaddr;

_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
In reply to Dave Hansen
Quoted 8 lines · Dave Hansen

There are quite a few functions in i386's discontig.c which are actually NUMA-specific, not discontigmem. They are also very similar to the generic, flat functions found in setup.c.

This patch takes the versions in setup.c and makes them work for both NUMA and non-NUMA cases. In the process, quite a few nasty #ifdef and externs can be removed.

Quoted 9 lines

One of the main mechanisms to do this is that highstart_pfn and highend_pfn are now gone, replaced by node_start/end_pfn[]. However, this has no real impact on storage space, because those arrays are declared with a length of MAX_NUMNODES, which is 1 when NUMA is off.

I think you allocate remap pages for nothing in the flatmem case for node0...those aren't used for the mem map in !NUMA.

--Mika

#3 lore raw
Quoted 2 lines · Mika Penttila

I think you allocate remap pages for nothing in the flatmem case for node0...those aren't used for the mem map in !NUMA.

I believe that is fixed up in the second patch. It should compile a do{}while(0) version instead of doing a real call.

-- Dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 15 lines · Dave Hansen
Quoted 3 lines · Mika Penttilä

I think you allocate remap pages for nothing in the flatmem case for node0...those aren't used for the mem map in !NUMA.

I believe that is fixed up in the second patch. It should compile a do{}while(0) version instead of doing a real call.

-- Dave

Oh, yes, indeend it is.
Thanks,
Mika