Skip to contentSkip to conversation

Generic Virtual Memmap suport for SPARSEMEM V2

PATCH New Christoph Lameter 1 participant 3 messages Apr 3, 2007

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Generic Virtual Memmap suport for SPARSEMEM V2

Spare Virtual: Virtual Memmap support for SPARSEMEM V2

V1->V2
- Support for PAGE_SIZE vmemmap which allows the general use of of virtual memmap on any MMU capable platform (enabled IA64 support).
- Fix various issues as suggested by Dave Hansen.
- Add comments and error handling.

SPARSEMEM is a pretty nice framework that unifies quite a bit of code over all the arches. It would be great if it could be the default so that we can get rid of various forms of DISCONTIG and other variations on memory maps. So far what has hindered this are the additional lookups that SPARSEMEM introduces for virt_to_page and page_address. This goes so far that the code to do this has to be kept in a separate function and cannot be used inline.

This patch introduces virtual memmap support for sparsemem. virt_to_page page_address and consorts become simple shift/add operations. No page flag fields, no table lookups, nothing involving memory is required.

The two key operations pfn_to_page and page_to_page become:

#define pfn_to_page(pfn) (vmemmap + (pfn))
#define page_to_pfn(page) ((page) - vmemmap)

In order for this to work we will have to use a virtual mapping. These are usually for free since kernel memory is already mapped via a 1-1 mapping requiring a page tabld. The virtual mapping must be big enough to span all of memory that an arch can support which may make a virtual memmap difficult to use on 32 bit platforms that support 36 address bits.

However, if there is enough virtual space available and the arch already maps its 1-1 kernel space using TLBs (f.e. true of IA64 and x86_64) then this technique makes sparsemem lookups even more effiecient than CONFIG_FLATMEM. FLATMEM still needs to read the contents of mem_map. mem_map is constant for a virtual memory map.

Maybe this patch will allow us to make SPARSEMEM the default configuration that will work on UP, SMP and NUMA on most platforms? Then we may hopefully be able to remove the various forms of support for FLATMEM, DISCONTIG etc etc.

include/asm-generic/memory_model.h +8 -0
Index: linux-2.6.21-rc5-mm2/include/asm-generic/memory_model.h
===================================================================
@@ -46,6 +46,14 @@
 	 __pgdat->node_start_pfn;					\
 })
 
+#elif defined(CONFIG_SPARSE_VIRTUAL)
+
+/*
+ * We have a virtual memmap that makes lookups very simple
+ */
+#define __pfn_to_page(pfn)	(vmemmap + (pfn))
+#define __page_to_pfn(page)	((page) - vmemmap)
+
 #elif defined(CONFIG_SPARSEMEM)
 /*
  * Note: section's mem_map is encorded to reflect its start_pfn.
mm/sparse.c +213 -1

238 lines not on this page · raw message

include/linux/mmzone.h +2 -0
Index: linux-2.6.21-rc5-mm2/include/linux/mmzone.h
===================================================================
@@ -836,6 +836,8 @@ void sparse_init(void);
 
 void memory_present(int nid, unsigned long start, unsigned long end);
 unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long);
+int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
+void *vmemmap_alloc_block(unsigned long size, int node);
 
 /*
  * If it is possible to have holes within a MAX_ORDER_NR_PAGES, then we

--
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

PATCH 2/3 x86_64: Implement SPARSE_VIRTUAL

x86_64 implement SPARSE_VIRTUAL

x86_64 is using 2M page table entries to map its 1-1 kernel space. We implement the virtual memmap also using 2M page table entries. So there is no difference at all to FLATMEM. Both schemes require a page table and a TLB for each 2MB. FLATMEM still references memory since the mem_map pointer itself a variable. SPARSE_VIRTUAL uses a constant for vmemmap. Thus no memory reference. SPARSE_VIRTUAL should be superior to even FLATMEM.

With this SPARSEMEM becomes the most efficient way of handling virt_to_page, pfn_to_page and friends for UP, SMP and NUMA on x86_64.

include/asm-x86_64/page.h +1 -0
Index: linux-2.6.21-rc5-mm3/include/asm-x86_64/page.h
===================================================================
@@ -127,6 +127,7 @@
 	 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
 
 #define __HAVE_ARCH_GATE_AREA 1	
+#define vmemmap ((struct page *)0xffffe20000000000UL)
 
 #include <asm-generic/memory_model.h>
 #include <asm-generic/page.h>
Documentation/x86_64/mm.txt +1 -0
Index: linux-2.6.21-rc5-mm3/Documentation/x86_64/mm.txt
===================================================================
@@ -9,6 +9,7 @@
 ffff810000000000 - ffffc0ffffffffff (=46 bits) direct mapping of all phys. memory
 ffffc10000000000 - ffffc1ffffffffff (=40 bits) hole
 ffffc20000000000 - ffffe1ffffffffff (=45 bits) vmalloc/ioremap space
+ffffe20000000000 - ffffe2ffffffffff (=40 bits) virtual memory map
 ... unused hole ...
 ffffffff80000000 - ffffffff82800000 (=40 MB)   kernel text mapping, from phys 0
 ... unused hole ...
arch/x86_64/Kconfig +6 -0
Index: linux-2.6.21-rc5-mm3/arch/x86_64/Kconfig
===================================================================
@@ -392,6 +392,12 @@
 	def_bool y
 	depends on (NUMA || EXPERIMENTAL)
 
+config SPARSE_VIRTUAL
+	def_bool y
+
+config ARCH_SUPPORTS_PMD_MAPPING
+	def_bool y
+
 config ARCH_MEMORY_PROBE
 	def_bool y
 	depends on MEMORY_HOTPLUG

--
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

PATCH 3/3 IA64: Implement SPARSE_VIRTUAL

In reply to Christoph Lameter

[IA64] Sparse virtual implementation

Equip IA64 sparsemem with a virtual memmap. This is similar to the existing CONFIG_VMEMMAP functionality for discontig. It uses a page size mapping.

This is provided as a minimally intrusive solution. We split the 128TB VMALLOC area into two 64TB areas and use one for the virtual memmap.

I have another patch in testing that uses granule sized 16MB pages to map the memmap but this would require changes to the interrupt vector table and there are certain discussions that would need to take place before we can accept such a large page size for the memmap. That version is better because is improves IA64 performance by reducing TLB pressure.

arch/ia64/Kconfig +4 -0
Index: linux-2.6.21-rc5-mm2/arch/ia64/Kconfig
===================================================================
@@ -350,6 +350,10 @@ config ARCH_SPARSEMEM_ENABLE
 	def_bool y
 	depends on ARCH_DISCONTIGMEM_ENABLE
 
+config SPARSE_VIRTUAL
+	def_bool y
+	depends on ARCH_SPARSEMEM_ENABLE
+
 config ARCH_DISCONTIGMEM_DEFAULT
 	def_bool y if (IA64_SGI_SN2 || IA64_GENERIC || IA64_HP_ZX1 || IA64_HP_ZX1_SWIOTLB)
 	depends on ARCH_DISCONTIGMEM_ENABLE
include/asm-ia64/page.h +3 -0
Index: linux-2.6.21-rc5-mm2/include/asm-ia64/page.h
===================================================================
@@ -106,6 +106,9 @@ extern int ia64_pfn_valid (unsigned long
 # define ia64_pfn_valid(pfn) 1
 #endif
 
+#define vmemmap ((struct page *)(RGN_BASE(RGN_GATE) + \
+				(1UL << (4*PAGE_SHIFT - 10))))
+
 #ifdef CONFIG_VIRTUAL_MEM_MAP
 extern struct page *vmem_map;
 #ifdef CONFIG_DISCONTIGMEM
include/asm-ia64/pgtable.h +5 -0
Index: linux-2.6.21-rc5-mm2/include/asm-ia64/pgtable.h
===================================================================
@@ -236,8 +236,13 @@ ia64_phys_addr_valid (unsigned long addr
 # define VMALLOC_END		vmalloc_end
   extern unsigned long vmalloc_end;
 #else
+#if defined(CONFIG_SPARSEMEM) && defined(CONFIG_SPARSE_VIRTUAL)
+/* SPARSE_VIRTUAL uses half of vmalloc... */
+# define VMALLOC_END		(RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 10)))
+#else
 # define VMALLOC_END		(RGN_BASE(RGN_GATE) + (1UL << (4*PAGE_SHIFT - 9)))
 #endif
+#endif
 
 /* fs/proc/kcore.c */
 #define	kc_vaddr_to_offset(v) ((v) - RGN_BASE(RGN_GATE))

--
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>