Skip to contentSkip to conversation

sparc64: vmemmap boot sizing

PATCH In review Bob Picco 2 participants 4 messages Sep 16, 2014 – Sep 18, 2014 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore

Bob Picco

author
#0 lore raw

PATCH 1/1 sparc64: vmemmap boot sizing

From: bob picco <[email protected]>

This patch attempts to accomodate the coarse grain memory controller unit (MCU) in Niagara5 and later generations. This is achieved by having a root array which is array of pointers to arrays of TTE-s for vmemmap. The ktlb paths are patched when using the root array.

Older sparc64 should have the net effect of being treated similar to before the introduction of Niagara5 and Athena which caused an increase in memory footprint of static sparc64 related memory management items.

---
 arch/sparc/include/asm/page_64.h |   20 +++
 arch/sparc/kernel/ktlb.S         |   29 ++++-
 arch/sparc/kernel/vmlinux.lds.S  |   10 ++
 arch/sparc/mm/init_64.c          |  278 +++++++++++++++++++++++++++++---------
 arch/sparc/mm/init_64.h          |    2 +-
 5 files changed, 267 insertions(+), 72 deletions(-)
arch/sparc/include/asm/page_64.h +20 -0
index 93f6508..172733f 100644
@@ -138,6 +138,26 @@ extern unsigned long PAGE_OFFSET;
  */
 #define	MAX_PHYS_ADDRESS_LOBITS	41
 
+#define NR_PHYS_ADDRESS_LOBITS_PAGES \
+		(1UL << (MAX_PHYS_ADDRESS_LOBITS - PAGE_SHIFT))
+#define	NR_VMEMMAP_ROOT_ENTRIES	\
+		(1UL << (MAX_PHYS_ADDRESS_BITS - MAX_PHYS_ADDRESS_LOBITS))
+/* Virtual space covered by this number of chunks in vmemmap terms.
+ * This assumes sizeof (struct page) = 1<<6.
+ */
+#define	NR_CHUNKS_BITS	(MAX_PHYS_ADDRESS_BITS - MAX_PHYS_ADDRESS_LOBITS)
+#define NR_CHUNKS_SHIFT	(MAX_PHYS_ADDRESS_LOBITS - PAGE_SHIFT + 6)
+#define	NR_CHUNKS_MASK	(~((1UL << NR_CHUNKS_SHIFT) - 1))
+
+/* We align the memblock allocation to 1Mb. We form the address with
+ * a right shift physical address of NR_VMEMMAP_ROOT_SHIFT, deposit into a
+ * sethi with imm22 which and then left shift the imm22 NR_VMEMMAP_ROOT_SHIFT.
+ */
+#define	NR_VMEMMAP_ROOT_ALIGN	(1UL << 20)
+#define NR_VMEMMAP_ROOT_SHIFT	10
+#define NR_VMEMMAP_ROOT_MAXADDR (1UL << 42)
+
+
 /* These two shift counts are used when indexing sparc64_valid_addr_bitmap
  * and kpte_linear_bitmap.
  */
arch/sparc/kernel/ktlb.S +24 -5
index d613648..70f823b 100644
@@ -281,14 +281,30 @@
 	 mov		%g5, %g3
 
 #ifdef CONFIG_SPARSEMEM_VMEMMAP
-kvmap_vmemmap:
+	.globl		kvmap_vmemmap_long
+	/* Should you move the label below, then move the sethi. */
+kvmap_vmemmap_long:
+	sethi		0, %g1
 	sub		%g4, %g5, %g5
-	srlx		%g5, ILOG2_4MB, %g5
+	sllx		%g1, NR_VMEMMAP_ROOT_SHIFT, %g1
+	srlx		%g5, (NR_CHUNKS_SHIFT-3), %g2
+	andn		%g2, 7, %g2
+	sllx		%g5, (64 - NR_CHUNKS_SHIFT), %g5
+	srlx		%g5, (64 - NR_CHUNKS_SHIFT + ILOG2_4MB - 3), %g5
+	ba,pt		%xcc, 1f
+	ldxa		[%g1 + %g2] ASI_PHYS_USE_EC, %g1
+kvmap_vmemmap:
 	sethi		%hi(vmemmap_table), %g1
-	sllx		%g5, 3, %g5
 	or		%g1, %lo(vmemmap_table), %g1
+	sub		%g4, %g5, %g5
+	srlx            %g5, ILOG2_4MB - 3, %g5
+1:	andn		%g5, 7, %g5
 	ba,pt		%xcc, kvmap_dtlb_load
-	 ldx		[%g1 + %g5], %g5
+661:	 ldx		[%g1 + %g5], %g5
+	.section	.kvmap_vmemmap_phys_load_patch, "ax"
+	.word		661b
+	 ldxa		[%g1 + %g5] ASI_PHYS_USE_EC, %g5
+	.previous
 #endif
 
 kvmap_dtlb_nonlinear:
@@ -303,7 +319,10 @@
 	mov		(VMEMMAP_BASE >> 40), %g5
 	sllx		%g5, 40, %g5
 	cmp		%g4,%g5
-	bgeu,pn		%xcc, kvmap_vmemmap
+661:	bgeu,pn		%xcc, kvmap_vmemmap
+	.section	.kvmap_vmemmap_root_patch, "ax"
+	.word		661b
+	.previous
 	 nop
 #endif
 
arch/sparc/kernel/vmlinux.lds.S +10 -0
index 422ead9..b8e6e0d 100644
@@ -137,6 +137,16 @@ SECTIONS
 		*(.phys_max_ilog2_patch)
 		__phys_max_ilog2_patch_end = .;
 	}
+	.kvmap_vmemmap_phys_load_patch :{
+		__kvmap_vmemmap_phys_load_patch = .;
+		*(.kvmap_vmemmap_phys_load_patch)
+		__kvmap_vmemmap_phys_load_patch_end = .;
+	}
+	.kvmap_vmemmap_root_patch :{
+		__kvmap_vmemmap_root_patch = .;
+		*(.kvmap_vmemmap_root_patch)
+		__kvmap_vmemmap_root_patch_end = .;
+	}
 	.swapper_phys_low_1mb_patch : {
 		__swapper_phys_low_1mb_patch = .;
 		*(.swapper_phys_low_1mb_patch)
arch/sparc/mm/init_64.c +212 -65

295 lines not on this page · raw message

arch/sparc/mm/init_64.h +1 -1
index 5c86c14..9b70c23 100644
@@ -43,7 +43,7 @@ void prom_world(int enter);
 #define VMEMMAP_CHUNK_MASK	~(VMEMMAP_CHUNK - 1UL)
 #define VMEMMAP_ALIGN(x)	(((x)+VMEMMAP_CHUNK-1UL)&VMEMMAP_CHUNK_MASK)
 
-#define VMEMMAP_SIZE	((((1UL << MAX_PHYSADDR_BITS) >> PAGE_SHIFT) * \
+#define VMEMMAP_SIZE	((((1UL << MAX_PHYS_ADDRESS_LOBITS) >> PAGE_SHIFT) * \
 			  sizeof(struct page)) >> VMEMMAP_CHUNK_SHIFT)
 extern unsigned long vmemmap_table[VMEMMAP_SIZE];
 #endif
Signature · 1 line
1.7.1
maintainer
#1 lore raw

From: Bob Picco <[email protected]>
Date: Tue, 16 Sep 2014 12:53:24 -0400

Quoted 7 lines

From: bob picco <[email protected]>

This patch attempts to accomodate the coarse grain memory controller unit (MCU) in Niagara5 and later generations. This is achieved by having a root array which is array of pointers to arrays of TTE-s for vmemmap. The ktlb paths are patched when using the root array.

Quoted 6 lines

Older sparc64 should have the net effect of being treated similar to before the introduction of Niagara5 and Athena which caused an increase in memory footprint of static sparc64 related memory management items.

We already have a rather nice data structure for storing sparse mappings of the virtual address space, in the form of the Linux page tables, so let's just use that. :-)

This also shrinks the kernel BSS by 2MB.

==========
[PATCH] sparc64: Use kernel page tables for vmemmap.

For sparse memory configurations, the vmemmap array behaves terribly and it takes up an inordinate amount of space in the BSS section of the kernel image unconditionally.

Just build huge PMDs and look them up just like we do for TLB misses in the vmalloc area.

Align debugging logs with what x86-64 does.

Kernel BSS shrinks by about 2MB.

---
 arch/sparc/include/asm/tsb.h | 19 ++++++++++++++++
 arch/sparc/kernel/ktlb.S     | 11 +++++----
 arch/sparc/mm/init_64.c      | 53 ++++++++++++++++++++++++++++----------------
 arch/sparc/mm/init_64.h      | 11 ---------
 4 files changed, 58 insertions(+), 36 deletions(-)
arch/sparc/include/asm/tsb.h +19 -0
index def62ed4..56acef9 100644
@@ -155,6 +155,25 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
 	andn		REG2, 0x7, REG2; \
 	add		REG1, REG2, REG1;
 
+	/* Do a 4MB kernel page table walk.  Leaves large PMD value in
+	 * REG1.  Jumps to FAIL_LABEL on early page table walk termination.
+	 * VADDR will not be clobbered, but REG2 will.
+	 */
+#define KERN_4M_PGTABLE_WALK(VADDR, REG1, REG2, FAIL_LABEL)	\
+	sethi		%hi(swapper_pg_dir), REG1; \
+	or		REG1, %lo(swapper_pg_dir), REG1; \
+	sllx		VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \
+	srlx		REG2, 64 - PAGE_SHIFT, REG2; \
+	andn		REG2, 0x7, REG2; \
+	ldx		[REG1 + REG2], REG1; \
+	brz,pn		REG1, FAIL_LABEL; \
+	 sllx		VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \
+	srlx		REG2, 64 - PAGE_SHIFT, REG2; \
+	andn		REG2, 0x7, REG2; \
+	ldxa		[REG1 + REG2] ASI_PHYS_USE_EC, REG1; \
+	brz,pn		REG1, FAIL_LABEL; \
+	 nop;
+
 	/* PMD has been loaded into REG1, interpret the value, seeing
 	 * if it is a HUGE PMD or a normal one.  If it is not valid
 	 * then jump to FAIL_LABEL.  If it is a HUGE PMD, and it
arch/sparc/kernel/ktlb.S +5 -6
index 7036a65..92762f1 100644
@@ -247,13 +247,12 @@ kvmap_dtlb_load:
 
 #ifdef CONFIG_SPARSEMEM_VMEMMAP
 kvmap_vmemmap:
-	sub		%g4, %g5, %g5
-	srlx		%g5, ILOG2_4MB, %g5
-	sethi		%hi(vmemmap_table), %g1
-	sllx		%g5, 3, %g5
-	or		%g1, %lo(vmemmap_table), %g1
+	KERN_4M_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
+	sethi		%hi(4 * 1024 * 1024), %g2
+	andn		%g5, %g2, %g5
+	and		%g4, %g2, %g2
 	ba,pt		%xcc, kvmap_dtlb_load
-	 ldx		[%g1 + %g5], %g5
+	 or		%g5, %g2, %g5
 #endif
 
 kvmap_dtlb_nonlinear:
arch/sparc/mm/init_64.c +34 -18

80 lines not on this page · raw message

arch/sparc/mm/init_64.h +0 -11
index bdef0a6..0718582 100644
@@ -35,15 +35,4 @@ extern unsigned long kern_locked_tte_data;
 
 void prom_world(int enter);
 
-#ifdef CONFIG_SPARSEMEM_VMEMMAP
-#define VMEMMAP_CHUNK_SHIFT	22
-#define VMEMMAP_CHUNK		(1UL << VMEMMAP_CHUNK_SHIFT)
-#define VMEMMAP_CHUNK_MASK	~(VMEMMAP_CHUNK - 1UL)
-#define VMEMMAP_ALIGN(x)	(((x)+VMEMMAP_CHUNK-1UL)&VMEMMAP_CHUNK_MASK)
-
-#define VMEMMAP_SIZE	((((1UL << MAX_PHYSADDR_BITS) >> PAGE_SHIFT) * \
-			  sizeof(struct page)) >> VMEMMAP_CHUNK_SHIFT)
-extern unsigned long vmemmap_table[VMEMMAP_SIZE];
-#endif
-
 #endif /* _SPARC64_MM_INIT_H */
Signature · 1 line
1.8.1.2
author
#2 lore raw
In reply to Bob Picco

Hi,
David Miller wrote: [Thu Sep 18 2014, 12:45:38AM EDT]

Quoted 14 lines

From: Bob Picco <[email protected]>
Date: Tue, 16 Sep 2014 12:53:24 -0400

Quoted 11 lines

From: bob picco <[email protected]>

This patch attempts to accomodate the coarse grain memory controller unit (MCU) in Niagara5 and later generations. This is achieved by having a root array which is array of pointers to arrays of TTE-s for vmemmap. The ktlb paths are patched when using the root array.

Older sparc64 should have the net effect of being treated similar to before the introduction of Niagara5 and Athena which caused an increase in memory footprint of static sparc64 related memory management items.

Quoted 8 lines
Quoted 2 lines

We already have a rather nice data structure for storing sparse mappings of the virtual address space, in the form of the Linux page tables, so let's just use that. :-)

This also shrinks the kernel BSS by 2MB.

This looks good too! I wasn't about to make the decision for sun4u.

Let me first test all three on my T5-2 local to me. Well, review some too.

Then I'll hit the M7-4 again.

Oh please remind me to mention percpu chunk allocator. Quickly we need need to enlarge VMALLOC space significantly but this is old data.

thanx!

maintainer
#3 lore raw
In reply to Bob Picco

From: Bob Picco <[email protected]>
Date: Thu, 18 Sep 2014 08:52:06 -0400

Quoted 2 lines

Oh please remind me to mention percpu chunk allocator. Quickly we need need to enlarge VMALLOC space significantly but this is old data.

That's easy, we can enlarge it as much as we want.

You just have to move the VMEMMAP base forward, but that's trivial too.

Do some calculations and let me know the order of how much more space we need.