Skip to contentSkip to conversation

powerpc/mm: Rename variable to reflect start address of a section

RFC In review Anshuman Khandual 3 participants 15 messages Feb 17, 2016 – Feb 19, 2016 PowerPC

lore
Share & tools
lore
#0 lore raw

RFC 1/4 powerpc/mm: Rename variable to reflect start address of a section

The commit (16a05bff1: powerpc: start loop at section start of start in vmemmap_populated()) reused 'start' variable to compute the starting address of the memory section where the given address belongs. Then the same variable is used for iterating over starting address of all memory sections before reaching the 'end' address. Renaming it as 'section_start' makes the logic more clear.

Fixes 16a05bff1 ("powerpc: start loop at section start of start in vmemmap_populated()")
---
 arch/powerpc/mm/init_64.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/powerpc/mm/init_64.c +8 -4
index 379a6a9..d6b9b4d 100644
@@ -170,11 +170,15 @@ static unsigned long __meminit vmemmap_section_start(unsigned long page)
  */
 static int __meminit vmemmap_populated(unsigned long start, int page_size)
 {
-	unsigned long end = start + page_size;
-	start = (unsigned long)(pfn_to_page(vmemmap_section_start(start)));
+	unsigned long end, section_start;
 
-	for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page)))
-		if (pfn_valid(page_to_pfn((struct page *)start)))
+	end = start + page_size;
+	section_start = (unsigned long)(pfn_to_page
+					(vmemmap_section_start(start)));
+
+	for (; section_start < end; section_start
+				+= (PAGES_PER_SECTION * sizeof(struct page)))
+		if (pfn_valid(page_to_pfn((struct page *)section_start)))
 			return 1;
 
 	return 0;
Signature · 1 line
2.1.0
#5 lore raw

RFC 3/4 powerpc/mm: Rename the vmemmap_backing struct and its elements

The structure to track single virtual to physical mapping has been renamed from vmemmap_backing to vmemmap_hw_map which sounds more appropriate. This forms a single entry of the global linked list tracking all of the vmemmap physical mapping. The changes are as follows.

	vmemmap_backing.list -> vmemmap_hw_map.link
	vmemmap_backing.phys -> vmemmap_hw_map.paddr
	vmemmap_backing.virt_addr -> vmemmap_hw_map.vaddr
---
 arch/powerpc/include/asm/pgalloc-64.h | 16 +++++++---
 arch/powerpc/kernel/machine_kexec.c   |  8 ++---
 arch/powerpc/mm/init_64.c             | 58 +++++++++++++++++------------------
 3 files changed, 44 insertions(+), 38 deletions(-)
arch/powerpc/include/asm/pgalloc-64.h +11 -5
index 69ef28a..e03b41c 100644
@@ -11,12 +11,18 @@
 #include <linux/cpumask.h>
 #include <linux/percpu.h>
 
-struct vmemmap_backing {
-	struct vmemmap_backing *list;
-	unsigned long phys;
-	unsigned long virt_addr;
+/*
+ * This structure tracks a single virtual page mapping from
+ * the vmemmap ddress space. This element is required to
+ * track virtual to physical mapping of page structures in
+ * absense of a page table at boot time.
+ */
+struct vmemmap_hw_map {
+	struct vmemmap_hw_map *link;
+	unsigned long paddr;
+	unsigned long vaddr;
 };
-extern struct vmemmap_backing *vmemmap_list;
+extern struct vmemmap_hw_map *vmemmap_list;
 
 /*
  * Functions that deal with pagetables that could be at any level of
arch/powerpc/kernel/machine_kexec.c +4 -4
index 015ae55..0d90798 100644
@@ -80,10 +80,10 @@ void arch_crash_save_vmcoreinfo(void)
 	VMCOREINFO_SYMBOL(vmemmap_list);
 	VMCOREINFO_SYMBOL(mmu_vmemmap_psize);
 	VMCOREINFO_SYMBOL(mmu_psize_defs);
-	VMCOREINFO_STRUCT_SIZE(vmemmap_backing);
-	VMCOREINFO_OFFSET(vmemmap_backing, list);
-	VMCOREINFO_OFFSET(vmemmap_backing, phys);
-	VMCOREINFO_OFFSET(vmemmap_backing, virt_addr);
+	VMCOREINFO_STRUCT_SIZE(vmemmap_hw_map);
+	VMCOREINFO_OFFSET(vmemmap_hw_map, link);
+	VMCOREINFO_OFFSET(vmemmap_hw_map, paddr);
+	VMCOREINFO_OFFSET(vmemmap_hw_map, vaddr);
 	VMCOREINFO_STRUCT_SIZE(mmu_psize_def);
 	VMCOREINFO_OFFSET(mmu_psize_def, shift);
 #endif
arch/powerpc/mm/init_64.c +29 -29

151 lines not on this page · raw message

Signature · 1 line
2.1.0
#8 lore raw

RFC 4/4 powerpc/mm: Rename global tracker for virtual to physical mapping

In reply to Anshuman Khandual

This renames the global list which tracks all the virtual to physical mapping and also the global list which tracks all the available unused vmemmap_hw_map node structures. It also attempts to explain the purpose of these global linked lists and points out a possible race condition.

---
 arch/powerpc/include/asm/pgalloc-64.h |  2 +-
 arch/powerpc/kernel/machine_kexec.c   |  2 +-
 arch/powerpc/mm/init_64.c             | 82 +++++++++++++++++++++--------------
 3 files changed, 52 insertions(+), 34 deletions(-)
arch/powerpc/include/asm/pgalloc-64.h +1 -1
index e03b41c..6e21a2a 100644
@@ -22,7 +22,7 @@ struct vmemmap_hw_map {
 	unsigned long paddr;
 	unsigned long vaddr;
 };
-extern struct vmemmap_hw_map *vmemmap_list;
+extern struct vmemmap_hw_map *vmemmap_global;
 
 /*
  * Functions that deal with pagetables that could be at any level of
arch/powerpc/kernel/machine_kexec.c +1 -1
index 0d90798..eb6876c 100644
@@ -77,7 +77,7 @@ void arch_crash_save_vmcoreinfo(void)
 	VMCOREINFO_SYMBOL(contig_page_data);
 #endif
 #if defined(CONFIG_PPC64) && defined(CONFIG_SPARSEMEM_VMEMMAP)
-	VMCOREINFO_SYMBOL(vmemmap_list);
+	VMCOREINFO_SYMBOL(vmemmap_global);
 	VMCOREINFO_SYMBOL(mmu_vmemmap_psize);
 	VMCOREINFO_SYMBOL(mmu_psize_defs);
 	VMCOREINFO_STRUCT_SIZE(vmemmap_hw_map);
arch/powerpc/mm/init_64.c +50 -32

156 lines not on this page · raw message

Signature · 1 line
2.1.0
#1 lore raw

RFC 2/4 powerpc/mm: Add comments to the vmemmap layout

In reply to Anshuman Khandual

Add some explaination to the layout of vmemmap virtual address space and how physical page mapping is only used for valid PFNs present at any point on the system.

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 41 ++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +41 -0
index 8d1c41d..9db4a86 100644
@@ -26,6 +26,47 @@
 #define IOREMAP_BASE	(PHB_IO_END)
 #define IOREMAP_END	(KERN_VIRT_START + KERN_VIRT_SIZE)
 
+/*
+ * Starting address of the virtual address space where all page structs
+ * for the system physical memory are stored under the vmemmap sparse
+ * memory model. All possible struct pages are logically stored in a
+ * sequence in this virtual address space irrespective of the fact
+ * whether any given PFN is valid or even the memory section is valid
+ * or not. During boot and memory hotplug add operation when new memory
+ * sections are added, real physical allocation and hash table bolting
+ * will be performed. This saves precious physical memory when the system
+ * really does not have valid PFNs in some address ranges.
+ *
+ *  vmemmap +--------------+
+ *     +    |  page struct +----------+  PFN is valid
+ *     |    +--------------+          |
+ *     |    |  page struct |          |  PFN is invalid
+ *     |    +--------------+          |
+ *     |    |  page struct +------+   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct +--+   |   |
+ *     |    +--------------+  |   |   |
+ *     |    |  page struct |  |   |   |       +-------------+
+ *     |    +--------------+  |   |   +-----> |     PFN     |
+ *     |    |  page struct |  |   |           +-------------+
+ *     |    +--------------+  |   +---------> |     PFN     |
+ *     |    |  page struct |  |               +-------------+
+ *     |    +--------------+  +-------------> |     PFN     |
+ *     |    |  page struct |                  +-------------+
+ *     |    +--------------+           +----> |     PFN     |
+ *     |    |  page struct |           |      +-------------+
+ *     |    +--------------+           |    Bolted in hash table
+ *     |    |  page struct +-----------+
+ *     v    +--------------+
+ *
+ * VMEMMAP_BASE (0xf000000000000000) region has a total range of 64TB but
+ * then it uses NR_MEM_SECTIONS * PAGES_PER_SECTION * sizeof(page struct)
+ * amount of virtual memory from it.
+ */
 #define vmemmap			((struct page *)VMEMMAP_BASE)
 
 /* Advertise special mapping type for AGP */
Signature · 1 line
2.1.0
Reviewed-by on v1 2/4
#2 lore raw

Re: [RFC 2/4] powerpc/mm: Add comments to the vmemmap layout

Quoted 4 lines · Anshuman Khandual

Add some explaination to the layout of vmemmap virtual address space and how physical page mapping is only used for valid PFNs present at any point on the system.

Quoted 59 lines
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 41 ++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +41 -0
index 8d1c41d..9db4a86 100644
@@ -26,6 +26,47 @@
 #define IOREMAP_BASE	(PHB_IO_END)
 #define IOREMAP_END	(KERN_VIRT_START + KERN_VIRT_SIZE)
 
+/*
+ * Starting address of the virtual address space where all page structs
+ * for the system physical memory are stored under the vmemmap sparse
+ * memory model. All possible struct pages are logically stored in a
+ * sequence in this virtual address space irrespective of the fact
+ * whether any given PFN is valid or even the memory section is valid
+ * or not. During boot and memory hotplug add operation when new memory
+ * sections are added, real physical allocation and hash table bolting
+ * will be performed. This saves precious physical memory when the system
+ * really does not have valid PFNs in some address ranges.
+ *
+ *  vmemmap +--------------+
+ *     +    |  page struct +----------+  PFN is valid
+ *     |    +--------------+          |
+ *     |    |  page struct |          |  PFN is invalid
+ *     |    +--------------+          |
+ *     |    |  page struct +------+   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct +--+   |   |
+ *     |    +--------------+  |   |   |
+ *     |    |  page struct |  |   |   |       +-------------+
+ *     |    +--------------+  |   |   +-----> |     PFN     |
+ *     |    |  page struct |  |   |           +-------------+
+ *     |    +--------------+  |   +---------> |     PFN     |
+ *     |    |  page struct |  |               +-------------+
+ *     |    +--------------+  +-------------> |     PFN     |
+ *     |    |  page struct |                  +-------------+
+ *     |    +--------------+           +----> |     PFN     |
+ *     |    |  page struct |           |      +-------------+
+ *     |    +--------------+           |    Bolted in hash table
+ *     |    |  page struct +-----------+
+ *     v    +--------------+
+ *
+ * VMEMMAP_BASE (0xf000000000000000) region has a total range of 64TB but
+ * then it uses NR_MEM_SECTIONS * PAGES_PER_SECTION * sizeof(page struct)
+ * amount of virtual memory from it.
+ */
 #define vmemmap			((struct page *)VMEMMAP_BASE)
 
 /* Advertise special mapping type for AGP */
Signature · 1 line
2.1.0
#6 lore raw

Re: [RFC 3/4] powerpc/mm: Rename the vmemmap_backing struct and its elements

In reply to Anshuman Khandual
Quoted 10 lines · Anshuman Khandual

The structure to track single virtual to physical mapping has been renamed from vmemmap_backing to vmemmap_hw_map which sounds more appropriate. This forms a single entry of the global linked list tracking all of the vmemmap physical mapping. The changes are as follows.

	vmemmap_backing.list -> vmemmap_hw_map.link
	vmemmap_backing.phys -> vmemmap_hw_map.paddr
	vmemmap_backing.virt_addr -> vmemmap_hw_map.vaddr

I am not sure this helps. If we are going to take these renames, can you wait till th book3s p9 preparation patches [1] hit upstream ?

[1] http://mid.gmane.org/[email protected]
-aneesh

#3 lore raw

Re: [RFC 2/4] powerpc/mm: Add comments to the vmemmap layout

In reply to Anshuman Khandual
Quoted 14 lines · Anshuman Khandual

Add some explaination to the layout of vmemmap virtual address space and how physical page mapping is only used for valid PFNs present at any point on the system.

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 41 ++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +0 -0
index 8d1c41d..9db4a86 100644

arch/powerpc/include/asm/book3s/64/pgtable.h line 30

Quoted 5 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +2 -0
@@ -26,6 +26,47 @@
 #define IOREMAP_BASE	(PHB_IO_END)
 #define IOREMAP_END	(KERN_VIRT_START + KERN_VIRT_SIZE)
 
+/*
+ * Starting address of the virtual address space where all page structs

This is so far from the variable it's referring to that it's not clear what it refers to. So you should say "vmemmap is the starting ..."

arch/powerpc/include/asm/book3s/64/pgtable.h line 31

Quoted 1 line
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -0
+ * for the system physical memory are stored under the vmemmap sparse

^
, when using the SPARSEMEM_VMEMMAP

arch/powerpc/include/asm/book3s/64/pgtable.h

Quoted 4 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +4 -0
+ * memory model. All possible struct pages are logically stored in a
+ * sequence in this virtual address space irrespective of the fact
+ * whether any given PFN is valid or even the memory section is valid
+ * or not.

I know what you mean but I think that could be worded better. But it's too late for me to reword it :)

The key point is that we allocate space for a page struct for each PFN that could be present in the system, including holes in the address space (hence sparse). That has the nice property of meaning there is a constant relationship between the address of a struct page and it's PFN.

arch/powerpc/include/asm/book3s/64/pgtable.h line 36

Quoted 1 line
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -0
+ * During boot and memory hotplug add operation when new memory
                  ^                               ^
		  or				  ,

arch/powerpc/include/asm/book3s/64/pgtable.h line 36

Quoted 1 line
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -0
+ * sections are added, real physical allocation and hash table bolting

^
of struct pages

Quoted 20 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +18 -0
+ * will be performed. This saves precious physical memory when the system
+ * really does not have valid PFNs in some address ranges.
 
 
+ *
+ *  vmemmap +--------------+
+ *     +    |  page struct +----------+  PFN is valid
+ *     |    +--------------+          |
+ *     |    |  page struct |          |  PFN is invalid
+ *     |    +--------------+          |
+ *     |    |  page struct +------+   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct +--+   |   |
+ *     |    +--------------+  |   |   |
+ *     |    |  page struct |  |   |   |       +-------------+
+ *     |    +--------------+  |   |   +-----> |     PFN     |

arch/powerpc/include/asm/book3s/64/pgtable.h line 64

Quoted 10 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +10 -0
+ *     |    |  page struct |  |   |           +-------------+
+ *     |    +--------------+  |   +---------> |     PFN     |
+ *     |    |  page struct |  |               +-------------+
+ *     |    +--------------+  +-------------> |     PFN     |
+ *     |    |  page struct |                  +-------------+
+ *     |    +--------------+           +----> |     PFN     |
+ *     |    |  page struct |           |      +-------------+
+ *     |    +--------------+           |    Bolted in hash table
+ *     |    |  page struct +-----------+
+ *     v    +--------------+

The things on the right are not PFNs, they're struct pages. Each one corresponds to a PFN, but that relationship is derived from the vmemap layout, not the physical layout.

I think it's more like:

	f000000000000000		  c000000000000000 (and also 0x0)
vmemmap +--------------+                  +--------------+
   +    |  page struct | +--------------> |  page struct |
   |    +--------------+                  +--------------+
   |    |  page struct | +--------------> |  page struct |
   |    +--------------+ |                +--------------+
   |    |  page struct | +       +------> |  page struct |
   |    +--------------+         |        +--------------+
   |    |  page struct |         |   +--> |  page struct |
   |    +--------------+         |   |    +--------------+
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct | +-------+   |
   |    +--------------+             |
   |    |  page struct | +-----------+
   |    +--------------+
   |    |  page struct | No mapping
   |    +--------------+
   |    |  page struct | No mapping
   v    +--------------+

Then there's the relationship between struct pages and PFNs:

                           page_to_pfn
                           +--------->
  vmemmap +--------------+             +-------------+
     +    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |              |
     |    +--------------+
     |    |              |
     |    +--------------+
     |    |              |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |              |
     |    +--------------+
     |    |              |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     v    +--------------+             +-------------+

cheers

#7 lore raw

Re: [RFC 3/4] powerpc/mm: Rename the vmemmap_backing struct and its elements

In reply to Aneesh Kumar K.V
Quoted 9 lines · Aneesh Kumar K.V
Quoted 6 lines · Anshuman Khandual

The structure to track single virtual to physical mapping has been renamed from vmemmap_backing to vmemmap_hw_map which sounds more appropriate. This forms a single entry of the global linked list tracking all of the vmemmap physical mapping. The changes are as follows.

Quoted 6 lines
Quoted 3 lines
	vmemmap_backing.list -> vmemmap_hw_map.link
	vmemmap_backing.phys -> vmemmap_hw_map.paddr
	vmemmap_backing.virt_addr -> vmemmap_hw_map.vaddr

I am not sure this helps. If we are going to take these renames, can you wait till th book3s p9 preparation patches [1] hit upstream ?

I don't see why the new names are any better, and it's a lot of churn for minimal if any benefit. So I'm not going to take this one.

cheers

#13 lore raw
In reply to Anshuman Khandual
Quoted 8 lines · Anshuman Khandual

The commit (16a05bff1: powerpc: start loop at section start of start in vmemmap_populated()) reused 'start' variable to compute the starting address of the memory section where the given address belongs. Then the same variable is used for iterating over starting address of all memory sections before reaching the 'end' address. Renaming it as 'section_start' makes the logic more clear.

Fixes 16a05bff1 ("powerpc: start loop at section start of start in vmemmap_populated()")

It's not a fix, just a cleanup. Fixes lines should be reserved for actual bug fixes.

Quoted 19 lines
---
 arch/powerpc/mm/init_64.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/powerpc/mm/init_64.c +1 -4
index 379a6a9..d6b9b4d 100644
@@ -170,11 +170,15 @@ static unsigned long __meminit vmemmap_section_start(unsigned long page)
  */
 static int __meminit vmemmap_populated(unsigned long start, int page_size)
 {
-	unsigned long end = start + page_size;
-	start = (unsigned long)(pfn_to_page(vmemmap_section_start(start)));
+	unsigned long end, section_start;
 
-	for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page)))
-		if (pfn_valid(page_to_pfn((struct page *)start)))

arch/powerpc/mm/init_64.c static unsigned long __meminit vmemmap_section_start(unsigned long page) · line 184

Quoted 10 lines
arch/powerpc/mm/init_64.c +7 -0
+	end = start + page_size;
+	section_start = (unsigned long)(pfn_to_page
+					(vmemmap_section_start(start)));
+
+	for (; section_start < end; section_start
+				+= (PAGES_PER_SECTION * sizeof(struct page)))
+		if (pfn_valid(page_to_pfn((struct page *)section_start)))
 			return 1;
 
 	return 0;

That's not a big improvement.

But I think this code could be improved. There's a lot of casts, it seems to be confused about whether it's iterating over addresses or struct pages.

cheers

#9 lore raw

Re: [RFC 4/4] powerpc/mm: Rename global tracker for virtual to physical mapping

In reply to Anshuman Khandual
Quoted 3 lines · Anshuman Khandual

This renames the global list which tracks all the virtual to physical mapping and also the global list which tracks all the available unused vmemmap_hw_map node structures.

But why? Why are the new names *so* much better that we would want to go through all this churn?

Quoted 2 lines

It also attempts to explain the purpose
of these global linked lists and points out a possible race condition.

I'm happy to take the comments.

cheers

#14 lore raw
In reply to Michael Ellerman
Quoted 9 lines · Michael Ellerman
Quoted 7 lines · Anshuman Khandual

The commit (16a05bff1: powerpc: start loop at section start of start in vmemmap_populated()) reused 'start' variable to compute the starting address of the memory section where the given address belongs. Then the same variable is used for iterating over starting address of all memory sections before reaching the 'end' address. Renaming it as 'section_start' makes the logic more clear.

Quoted 4 lines
Quoted 1 line
Fixes 16a05bff1 ("powerpc: start loop at section start of start in vmemmap_populated()")

It's not a fix, just a cleanup. Fixes lines should be reserved for actual bug fixes.

Sure, got it.

Quoted 29 lines
Quoted 29 lines
---
 arch/powerpc/mm/init_64.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/powerpc/mm/init_64.c +8 -4
index 379a6a9..d6b9b4d 100644
@@ -170,11 +170,15 @@ static unsigned long __meminit vmemmap_section_start(unsigned long page)
  */
 static int __meminit vmemmap_populated(unsigned long start, int page_size)
 {
-	unsigned long end = start + page_size;
-	start = (unsigned long)(pfn_to_page(vmemmap_section_start(start)));
+	unsigned long end, section_start;
 
-	for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page)))
-		if (pfn_valid(page_to_pfn((struct page *)start)))
+	end = start + page_size;
+	section_start = (unsigned long)(pfn_to_page
+					(vmemmap_section_start(start)));
+
+	for (; section_start < end; section_start
+				+= (PAGES_PER_SECTION * sizeof(struct page)))
+		if (pfn_valid(page_to_pfn((struct page *)section_start)))
 			return 1;
 
Quoted 6 lines

arch/powerpc/mm/init_64.c static unsigned long __meminit vmemmap_section_start(unsigned long page) · line 184

Quoted 1 line
arch/powerpc/mm/init_64.c +0 -0
 	return 0;

That's not a big improvement.

But I think this code could be improved. There's a lot of casts, it seems to be confused about whether it's iterating over addresses or struct pages.

Right, this patch just tries to clear on such confusion. Thats all.

#10 lore raw

Re: [RFC 4/4] powerpc/mm: Rename global tracker for virtual to physical mapping

In reply to Michael Ellerman
Quoted 8 lines · Michael Ellerman
Quoted 3 lines · Anshuman Khandual

This renames the global list which tracks all the virtual to physical mapping and also the global list which tracks all the available unused vmemmap_hw_map node structures.

But why? Why are the new names *so* much better that we would want to go through all this churn?

Hmm, okay. Its kind of subjective but then its upto you.

Quoted 5 lines
Quoted 3 lines

It also attempts to explain the purpose
of these global linked lists and points out a possible race condition.

I'm happy to take the comments.

Sure, will send across next time around separately.

#4 lore raw

Re: [RFC 2/4] powerpc/mm: Add comments to the vmemmap layout

In reply to Michael Ellerman
Quoted 137 lines · Michael Ellerman
Quoted 14 lines · Anshuman Khandual

Add some explaination to the layout of vmemmap virtual address space and how physical page mapping is only used for valid PFNs present at any point on the system.

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 41 ++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +0 -0
index 8d1c41d..9db4a86 100644

arch/powerpc/include/asm/book3s/64/pgtable.h line 30

Quoted 5 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +2 -0
@@ -26,6 +26,47 @@
 #define IOREMAP_BASE	(PHB_IO_END)
 #define IOREMAP_END	(KERN_VIRT_START + KERN_VIRT_SIZE)
 
+/*
+ * Starting address of the virtual address space where all page structs

This is so far from the variable it's referring to that it's not clear what it refers to. So you should say "vmemmap is the starting ..."

arch/powerpc/include/asm/book3s/64/pgtable.h line 31

Quoted 1 line
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -0
+ * for the system physical memory are stored under the vmemmap sparse

^
, when using the SPARSEMEM_VMEMMAP

arch/powerpc/include/asm/book3s/64/pgtable.h

Quoted 4 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +4 -0
+ * memory model. All possible struct pages are logically stored in a
+ * sequence in this virtual address space irrespective of the fact
+ * whether any given PFN is valid or even the memory section is valid
+ * or not.

I know what you mean but I think that could be worded better. But it's too late for me to reword it :)

The key point is that we allocate space for a page struct for each PFN that could be present in the system, including holes in the address space (hence sparse). That has the nice property of meaning there is a constant relationship between the address of a struct page and it's PFN.

arch/powerpc/include/asm/book3s/64/pgtable.h line 36

Quoted 1 line
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -0
+ * During boot and memory hotplug add operation when new memory
                  ^                               ^
		  or				  ,

arch/powerpc/include/asm/book3s/64/pgtable.h line 36

Quoted 1 line
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -0
+ * sections are added, real physical allocation and hash table bolting

^
of struct pages

Quoted 20 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +18 -0
+ * will be performed. This saves precious physical memory when the system
+ * really does not have valid PFNs in some address ranges.
 
 
+ *
+ *  vmemmap +--------------+
+ *     +    |  page struct +----------+  PFN is valid
+ *     |    +--------------+          |
+ *     |    |  page struct |          |  PFN is invalid
+ *     |    +--------------+          |
+ *     |    |  page struct +------+   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct |      |   |
+ *     |    +--------------+      |   |
+ *     |    |  page struct +--+   |   |
+ *     |    +--------------+  |   |   |
+ *     |    |  page struct |  |   |   |       +-------------+
+ *     |    +--------------+  |   |   +-----> |     PFN     |

arch/powerpc/include/asm/book3s/64/pgtable.h line 64

Quoted 10 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +10 -0
+ *     |    |  page struct |  |   |           +-------------+
+ *     |    +--------------+  |   +---------> |     PFN     |
+ *     |    |  page struct |  |               +-------------+
+ *     |    +--------------+  +-------------> |     PFN     |
+ *     |    |  page struct |                  +-------------+
+ *     |    +--------------+           +----> |     PFN     |
+ *     |    |  page struct |           |      +-------------+
+ *     |    +--------------+           |    Bolted in hash table
+ *     |    |  page struct +-----------+
+ *     v    +--------------+

The things on the right are not PFNs, they're struct pages. Each one corresponds to a PFN, but that relationship is derived from the vmemap layout, not the physical layout.

I think it's more like:

	f000000000000000		  c000000000000000 (and also 0x0)
vmemmap +--------------+                  +--------------+
   +    |  page struct | +--------------> |  page struct |
   |    +--------------+                  +--------------+
   |    |  page struct | +--------------> |  page struct |
   |    +--------------+ |                +--------------+
   |    |  page struct | +       +------> |  page struct |
   |    +--------------+         |        +--------------+
   |    |  page struct |         |   +--> |  page struct |
   |    +--------------+         |   |    +--------------+
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct |         |   |
   |    +--------------+         |   |
   |    |  page struct | +-------+   |
   |    +--------------+             |
   |    |  page struct | +-----------+
   |    +--------------+
   |    |  page struct | No mapping
   |    +--------------+
   |    |  page struct | No mapping
   v    +--------------+

Then there's the relationship between struct pages and PFNs:

                           page_to_pfn
                           +--------->
  vmemmap +--------------+             +-------------+
     +    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |              |
     |    +--------------+
     |    |              |
     |    +--------------+
     |    |              |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
Quoted 8 lines
     |    |              |
     |    +--------------+
     |    |              |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     |    +--------------+             +-------------+
     |    |  page struct | +---------> |     PFN     |
     v    +--------------+             +-------------+

Awesome, this conveys the message better. Will change it next time around. Thanks !

#11 lore raw

Re: [RFC 4/4] powerpc/mm: Rename global tracker for virtual to physical mapping

In reply to Anshuman Khandual
Quoted 11 lines · Anshuman Khandual
Quoted 8 lines · Michael Ellerman
Quoted 3 lines · Anshuman Khandual

This renames the global list which tracks all the virtual to physical mapping and also the global list which tracks all the available unused vmemmap_hw_map node structures.

But why? Why are the new names *so* much better that we would want to go through all this churn?

Hmm, okay. Its kind of subjective but then its upto you.

Yeah it is of course. I'm not saying your names aren't better, but they're not obviously better to me, and so it's a lot of code churn for not much benefit IMHO.

But you can try and convince me if you really feel strongly about it.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It also attempts to explain the purpose
of these global linked lists and points out a possible race condition.

I'm happy to take the comments.

Sure, will send across next time around separately.

Thanks.

cheers

#12 lore raw

Re: [RFC 4/4] powerpc/mm: Rename global tracker for virtual to physical mapping

Quoted 11 lines · Michael Ellerman
Quoted 10 lines · Anshuman Khandual
Quoted 10 lines · Michael Ellerman
Quoted 8 lines
Quoted 8 lines · Anshuman Khandual
Quoted 4 lines
Quoted 4 lines

This renames the global list which tracks all the virtual to physical mapping and also the global list which tracks all the available unused vmemmap_hw_map node structures.

But why? Why are the new names *so* much better that we would want to go through all this churn?

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Hmm, okay. Its kind of subjective but then its upto you.

Yeah it is of course. I'm not saying your names aren't better, but they're not obviously better to me, and so it's a lot of code churn for not much benefit IMHO.

But you can try and convince me if you really feel strongly about it.

Agreed, its not worth the churn. Thanks !