Skip to contentSkip to conversation

powerpc: introduce "slices" (aka. meta-segments)

RFC/PATCH Benjamin Herrenschmidt 2 participants 3 messages Feb 15, 2007 PowerPC

lore
Share & tools
lore
#0 lore raw

Hi !

This is a very experimental non-tested probably doesn't even boot patch (I just had time to check it builds which isn't much at this point) but I'd like a bit of review/feedback on the approach.

(In fact, it -will- not work for some things, like the 64K->4K demotion on IO, as I still need to implement code to handle that case)

The basic issue is to be able to do what hugetlbfs does but with different page sizes for some other special filesystems, more specifically, my need is:

- SPE local store mappings using 64K pages on a 4K base page size
kernel on Cell

- Some special 4K segments in 64K pages kernels for mapping a dodgy
specie of powerpc specific infiniband hardware that requires 4K MMU mappings for various reasons I won't explain here.

The main issues are:

- To maintain/keep track of the page size per "segments" (as we can
only have one page size per segment on powerpc, which are 256MB divisions of the address space).

- To make sure special mappings stay within their alloted
"segments" (including MAP_FIXED crap)

- To make sure everybody else doesn't mmap/brk/grow_stack into a
"segment" that is used for a special mapping

The patch address these in various ways described quickly below that hijack some of the existing hugetlbfs callbacks.

The ideal solution requires some changes to the generic get_unmapped_area(), among others, to get rid of the hugetlbfs hacks in there, and instead, make sure that the fs and mm get_unmapped_area are also called for MAP_FIXED. We might also need to add an mm callback to validate a mapping.

I intend to do those changes separately and then adapt this work to use them.

So what is a slice ? Well, I re-used the mecanism used formerly by our hugetlbfs implementation which divides the address space in "meta-segments" which I called "slices". The division is done using 256MB slices below 4G, and 1T slices above. Thus the address space is divided currently into 16 "low" slices and 16 "high" slices. (Special
case: high slice 0 is the area between 4G and 1T).

Doing so simplifies significantly the tracking of segments and avoid having to keep track of all the 256MB segments in the address space.

While I used the "concepts" of hugetlbfs, I mostly re-implemented everything in a more generic way and "ported" hugetlbfs to it.

slices can have an associated page size, which is encoded in the mmu context and used by the SLB miss handler to set the segment sizes. The hash code currently doesn't care, it has a specific check for hugepages, though I might add a mecanism to provide per-slice hash mapping functions in the future.

The slice code provide a pair of "generic" get_unmapped_area() (bottomup and topdown) functions that should work with any slice size. There is some trickyness here so I would appreciate people to have a look at the implementation of these and let me know if I got something wrong.

Thanks in advance,
Ben.

 arch/powerpc/Kconfig              |    5
 arch/powerpc/kernel/asm-offsets.c |   16 -
 arch/powerpc/mm/Makefile          |    1
 arch/powerpc/mm/hash_utils_64.c   |    4
 arch/powerpc/mm/hugetlbpage.c     |  514 -------------------------------------
 arch/powerpc/mm/mmu_context_64.c  |    4
 arch/powerpc/mm/slb.c             |   11
 arch/powerpc/mm/slb_low.S         |   50 ++-
 arch/powerpc/mm/slice.c           |  517 ++++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/mmu.h         |   12
 include/asm-powerpc/paca.h        |    2
 include/asm-powerpc/page_64.h     |   83 ++----
 12 files changed, 625 insertions(+), 594 deletions(-)
arch/powerpc/Kconfig +5 -0
Index: linux-cell/arch/powerpc/Kconfig
===================================================================
@@ -318,6 +318,11 @@ config PPC_STD_MMU_32
 	def_bool y
 	depends on PPC_STD_MMU && PPC32
 
+config PPC_MM_SLICES
+	bool
+	default y if HUGETLB_PAGE
+	default n
+
 config VIRT_CPU_ACCOUNTING
 	bool "Deterministic task and CPU time accounting"
 	depends on PPC64
include/asm-powerpc/mmu.h +7 -5
Index: linux-cell/include/asm-powerpc/mmu.h
===================================================================
@@ -355,15 +355,17 @@ typedef unsigned long mm_context_id_t;
 
 typedef struct {
 	mm_context_id_t id;
-	u16 user_psize;			/* page size index */
-	u16 sllp;			/* SLB entry page size encoding */
-#ifdef CONFIG_HUGETLB_PAGE
-	u16 low_htlb_areas, high_htlb_areas;
+	u16 user_psize;		/* base page size index */
+
+#ifdef CONFIG_PPC_MM_SLICES
+	u64 low_slices_psize;	/* SLB page size encodings */
+	u64 high_slices_psize;  /* 4 bits per slice for now */
+#else
+	u16 sllp;		/* SLB page size encoding */
 #endif
 	unsigned long vdso_base;
 } mm_context_t;
 
-
 static inline unsigned long vsid_scramble(unsigned long protovsid)
 {
 #if 0
include/asm-powerpc/paca.h +1 -1
Index: linux-cell/include/asm-powerpc/paca.h
===================================================================
@@ -82,8 +82,8 @@ struct paca_struct {
 
 	mm_context_t context;
 	u16 vmalloc_sllp;
-	u16 slb_cache[SLB_CACHE_ENTRIES];
 	u16 slb_cache_ptr;
+	u16 slb_cache[SLB_CACHE_ENTRIES];
 
 	/*
 	 * then miscellaneous read-write fields
include/asm-powerpc/page_64.h +39 -44

97 lines not on this page · raw message

arch/powerpc/mm/Makefile +1 -0
Index: linux-cell/arch/powerpc/mm/Makefile
===================================================================
@@ -18,4 +18,5 @@ obj-$(CONFIG_40x)		+= 4xx_mmu.o
 obj-$(CONFIG_44x)		+= 44x_mmu.o
 obj-$(CONFIG_FSL_BOOKE)		+= fsl_booke_mmu.o
 obj-$(CONFIG_NEED_MULTIPLE_NODES) += numa.o
+obj-$(CONFIG_PPC_MM_SLICES)	+= slice.o
 obj-$(CONFIG_HUGETLB_PAGE)	+= hugetlbpage.o
arch/powerpc/mm/slice.c new file +517 -0

517 lines not on this page · raw message

arch/powerpc/kernel/asm-offsets.c +11 -5
Index: linux-cell/arch/powerpc/kernel/asm-offsets.c
===================================================================
@@ -123,12 +123,18 @@ int main(void)
 	DEFINE(PACASLBCACHE, offsetof(struct paca_struct, slb_cache));
 	DEFINE(PACASLBCACHEPTR, offsetof(struct paca_struct, slb_cache_ptr));
 	DEFINE(PACACONTEXTID, offsetof(struct paca_struct, context.id));
-	DEFINE(PACACONTEXTSLLP, offsetof(struct paca_struct, context.sllp));
 	DEFINE(PACAVMALLOCSLLP, offsetof(struct paca_struct, vmalloc_sllp));
-#ifdef CONFIG_HUGETLB_PAGE
-	DEFINE(PACALOWHTLBAREAS, offsetof(struct paca_struct, context.low_htlb_areas));
-	DEFINE(PACAHIGHHTLBAREAS, offsetof(struct paca_struct, context.high_htlb_areas));
-#endif /* CONFIG_HUGETLB_PAGE */
+#ifdef CONFIG_PPC_MM_SLICES
+	DEFINE(PACALOWSLICESPSIZE, offsetof(struct paca_struct,
+					    context.low_slices_psize));
+	DEFINE(PACAHIGHSLICEPSIZE, offsetof(struct paca_struct,
+					    context.high_slices_psize));
+	DEFINE(MMUPSIZEDEFSIZE, sizeof(struct mmu_psize_def));
+	DEFINE(MMUPSIZESLLP, offsetof(struct mmu_psize_def, sllp));
+#else
+	DEFINE(PACACONTEXTSLLP, offsetof(struct paca_struct, context.sllp));
+
+#endif /* CONFIG_PPC_MM_SLICES */
 	DEFINE(PACA_EXGEN, offsetof(struct paca_struct, exgen));
 	DEFINE(PACA_EXMC, offsetof(struct paca_struct, exmc));
 	DEFINE(PACA_EXSLB, offsetof(struct paca_struct, exslb));
arch/powerpc/mm/hugetlbpage.c +7 -507

557 lines not on this page · raw message

arch/powerpc/mm/mmu_context_64.c +4 -0
Index: linux-cell/arch/powerpc/mm/mmu_context_64.c
===================================================================
@@ -51,8 +51,12 @@ again:
 
 	mm->context.id = index;
 	mm->context.user_psize = mmu_virtual_psize;
+#ifdef CONFIG_PPC_MM_SLICES
+	slice_init_context(mm);
+#else
 	mm->context.sllp = SLB_VSID_USER |
 		mmu_psize_defs[mmu_virtual_psize].sllp;
+#endif
 
 	return 0;
 }
arch/powerpc/mm/slb_low.S +31 -19

62 lines not on this page · raw message

arch/powerpc/mm/hash_utils_64.c +2 -2
Index: linux-cell/arch/powerpc/mm/hash_utils_64.c
===================================================================
@@ -635,7 +635,7 @@ int hash_page(unsigned long ea, unsigned
 		local = 1;
 
 	/* Handle hugepage regions */
-	if (unlikely(in_hugepage_area(mm->context, ea))) {
+	if (unlikely(get_slice_psize(mm, ea) == mmu_huge_psize)) {
 		DBG_LOW(" -> huge page !\n");
 		return hash_huge_page(mm, access, ea, vsid, local, trap);
 	}
@@ -727,7 +727,7 @@ void hash_preload(struct mm_struct *mm, 
 
 	/* We don't want huge pages prefaulted for now
 	 */
-	if (unlikely(in_hugepage_area(mm->context, ea)))
+	if (unlikely(get_slice_psize(mm, ea) == mmu_huge_psize))
 		return;
 
 	DBG_LOW("hash_preload(mm=%p, mm->pgdir=%p, ea=%016lx, access=%lx,"
arch/powerpc/mm/slb.c +0 -11
Index: linux-cell/arch/powerpc/mm/slb.c
===================================================================
@@ -198,12 +198,6 @@ void slb_initialize(void)
 	static int slb_encoding_inited;
 	extern unsigned int *slb_miss_kernel_load_linear;
 	extern unsigned int *slb_miss_kernel_load_io;
-#ifdef CONFIG_HUGETLB_PAGE
-	extern unsigned int *slb_miss_user_load_huge;
-	unsigned long huge_llp;
-
-	huge_llp = mmu_psize_defs[mmu_huge_psize].sllp;
-#endif
 
 	/* Prepare our SLB miss handler based on our page size */
 	linear_llp = mmu_psize_defs[mmu_linear_psize].sllp;
@@ -220,11 +214,6 @@ void slb_initialize(void)
 
 		DBG("SLB: linear  LLP = %04x\n", linear_llp);
 		DBG("SLB: io      LLP = %04x\n", io_llp);
-#ifdef CONFIG_HUGETLB_PAGE
-		patch_slb_encoding(slb_miss_user_load_huge,
-				   SLB_VSID_USER | huge_llp);
-		DBG("SLB: huge    LLP = %04x\n", huge_llp);
-#endif
 	}
 
 	get_paca()->stab_rr = SLB_NUM_BOLTED;
#1 lore raw
Quoted 5 lines · Benjamin Herrenschmidt

=A0arch/powerpc/Kconfig =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A05 =A0arch/powerpc/kernel/asm-offsets.c | =A0 16 - =A0arch/powerpc/mm/Makefile =A0 =A0 =A0 =A0 =A0| =A0 =A01 =A0arch/powerpc/mm/hash_utils_64.c =A0 | =A0 =A04 =A0arch/powerpc/mm/hugetlbpage.c =A0 =A0 | =A0514 -----------------------=

=2D-------------

Quoted 4 lines

=A0arch/powerpc/mm/mmu_context_64.c =A0| =A0 =A04 =A0arch/powerpc/mm/slb.c =A0 =A0 =A0 =A0 =A0 =A0 | =A0 11 =A0arch/powerpc/mm/slb_low.S =A0 =A0 =A0 =A0 | =A0 50 ++- =A0arch/powerpc/mm/slice.c =A0 =A0 =A0 =A0 =A0 | =A0517 +++++++++++++++++=

+++++++++++++++++++++

Quoted 4 lines

=A0include/asm-powerpc/mmu.h =A0 =A0 =A0 =A0 | =A0 12 =A0include/asm-powerpc/paca.h =A0 =A0 =A0 =A0| =A0 =A02 =A0include/asm-powerpc/page_64.h =A0 =A0 | =A0 83 ++---- =A012 files changed, 625 insertions(+), 594 deletions(-)

I tried to review your patch, but I found it hard because of the amount of code that that just gets moved from hugetlbpage.c to slice.c. Could you send the next version of as two patches, with one of them only moving the code without changing it?

	Arnd <><
#2 lore raw
Quoted 15 lines · Arnd Bergmann
Quoted 5 lines · Benjamin Herrenschmidt
 arch/powerpc/Kconfig              |    5
 arch/powerpc/kernel/asm-offsets.c |   16 -
 arch/powerpc/mm/Makefile          |    1
 arch/powerpc/mm/hash_utils_64.c   |    4
 arch/powerpc/mm/hugetlbpage.c     |  514 -------------------------------------
Quoted 8 lines
 arch/powerpc/mm/mmu_context_64.c  |    4
 arch/powerpc/mm/slb.c             |   11
 arch/powerpc/mm/slb_low.S         |   50 ++-
 arch/powerpc/mm/slice.c           |  517 ++++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/mmu.h         |   12
 include/asm-powerpc/paca.h        |    2
 include/asm-powerpc/page_64.h     |   83 ++----
 12 files changed, 625 insertions(+), 594 deletions(-)
Quoted 4 lines

I tried to review your patch, but I found it hard because of the amount of code that that just gets moved from hugetlbpage.c to slice.c. Could you send the next version of as two patches, with one of them only moving the code without changing it?

There is not that much code that gets moved. It mostly gets rewritten.

Ben.