alphalinux.org high-perf list (1998-2001)
 help / color / mirror / Atom feed
* [High-perf] page granuality hints support for kernel-2.4.0-test1
@ 2000-06-14 12:03 Naohiko Shimizu
  0 siblings, 0 replies; only message in thread
From: Naohiko Shimizu @ 2000-06-14 12:03 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 10531 bytes --]

This is my first patch to the kernel to support Alpha's 

Page Granuality Hints. When complete, it will boost HPC applications

very much, I think.

I am not satisfied with this patch, because it only reduces the misses

in

a few seconds after the program start. I used "iprobe" to see the fact.

I must seek the reason why such things happened.

But someone in this mailing list will be interested in this patch.

Any comments or suggetions are appliciated.

I will attach two program, 1st is the patch itself, 2nd is the

benchmarking program that will fit to the patch. (As I menssioned

it is not fully reduce the TLB misses yet. )

Naohiko Shimizu.

Tokai Univ.

<nshimizu@et.u-tokai.ac.jp>

diff -urN linux-2.4.0-test1/Documentation/page_gh.txt linux/Documentation/page_gh.txt

--- linux-2.4.0-test1/Documentation/page_gh.txt	Thu Jan  1 09:00:00 1970

+++ linux/Documentation/page_gh.txt	Wed Jun 14 20:23:14 2000

@@ -0,0 +1,39 @@

+The Alpha architecture defines Granularity Hint(GH) bits in the

+Page Table Entry(PTE). If these bits are set to non-zero value,

+it supply a hint to translation buffer implementations that

+a block of pages can be treated as a single larger page.

+It means that even if we don't have variable length page mechanism,

+we will have some opportunity to reduce translation misses.

+For the large working set HPC applications the performance

+degradation caused by the translation misses are terrible.

+Then if we can use this feature, many HPC applications will be

+appreciated.

+

+To simplicity, my first patch is only experimental level.

+

+The idea is depend on the followings:

+  1) High performance applications should be memory resident. Then

+     we can expect them to call mlock_all system call with MCL_FUTURE.

+     Of course this call requires you are a root. You can use

+     "sudo" to get the privilege.

+  2) The static assigned memory area (heap) is manageable, and it will

+     be useful for C coded applications. malloc usually uses mmap, but

+     I only implement brk interface. Then you can use the feature with 

+     the sbrk call.

+

+The lacked features for release level are:

+  1) mmap interface will be required for normal "malloc" call.

+  2) No unmap routine for munlock. If someone expect to munlock the

+     space with GH bits set, processor should drop all the GH bits

+     of the block.

+  3) Allocated pages are not cleared. (I don't need it for benchmarking)

+  4) The stack and/or file mapped area is not supported.

+  5) We should drop the GH bits when brk system call is called to

+     shrink the locked area.

+  6) Someone in the kernel may detach the GH bits or something

+     happens. I found that TLB misses drastically decreased only in 

+     the first several seconds, then it increased again. I will seek

+     the reason later.

+

+

+Naohiko Shimizu<nshimizu@keyaki.cc.u-tokai.ac.jp>

diff -urN linux-2.4.0-test1/arch/alpha/config.in linux/arch/alpha/config.in

--- linux-2.4.0-test1/arch/alpha/config.in	Tue Mar 28 07:18:32 2000

+++ linux/arch/alpha/config.in	Tue Jun 13 16:42:29 2000

@@ -184,6 +184,8 @@

         bool 'Symmetric multi-processing support' CONFIG_SMP

 fi

 

+dep_bool 'PAGE Granularity Hint support' CONFIG_PAGE_GH $CONFIG_EXPERIMENTAL

+

 source drivers/pci/Config.in

 

 bool 'Support for hot-pluggable devices' CONFIG_HOTPLUG

diff -urN linux-2.4.0-test1/arch/alpha/mm/init.c linux/arch/alpha/mm/init.c

--- linux-2.4.0-test1/arch/alpha/mm/init.c	Tue Apr 25 05:39:34 2000

+++ linux/arch/alpha/mm/init.c	Tue Jun 13 16:42:29 2000

@@ -5,6 +5,7 @@

  */

 

 /* 2.3.x zone allocator, 1999 Andrea Arcangeli <andrea@suse.de> */

+/* PAGE_GH support, 2000 Naohiko Shimizu <nshimizu@keyaki.cc.u-tokai.ac.jp> */

 

 #include <linux/config.h>

 #include <linux/signal.h>

@@ -30,6 +31,11 @@

 #include <asm/hwrpb.h>

 #include <asm/dma.h>

 #include <asm/mmu_context.h>

+

+#ifdef CONFIG_PAGE_GH

+int page_gh_order[] = {0,3,6,9};

+pgprot_t page_gh_prot[] = {0x0000,0x0020,0x0040,0x0060};

+#endif

 

 static unsigned long totalram_pages;

 

diff -urN linux-2.4.0-test1/include/asm-alpha/pgtable.h linux/include/asm-alpha/pgtable.h

--- linux-2.4.0-test1/include/asm-alpha/pgtable.h	Wed Mar 22 03:46:21 2000

+++ linux/include/asm-alpha/pgtable.h	Wed Jun 14 10:26:40 2000

@@ -183,6 +183,17 @@

 #define PHYS_TWIDDLE(phys) (phys)

 #endif

 

+/* 

+ *  PAGE_GH support added by Naohiko Shimizu

+	<nshimizu@keyaki.cc.u-tokai.ac.jp>

+ */

+#if defined(CONFIG_PAGE_GH)

+#define PAGE_GH_MASK 0x0060

+#define PAGE_GH_NR 4

+extern int page_gh_order[];

+extern pgprot_t page_gh_prot[];

+#endif

+

 /*

  * Conversion functions:  convert a page and protection to a page entry,

  * and a page entry and page directory to the page they refer to.

diff -urN linux-2.4.0-test1/include/linux/mm.h linux/include/linux/mm.h

--- linux-2.4.0-test1/include/linux/mm.h	Thu May 25 11:52:42 2000

+++ linux/include/linux/mm.h	Wed Jun 14 14:06:41 2000

@@ -406,6 +406,7 @@

 extern void vmtruncate(struct inode * inode, loff_t offset);

 extern int handle_mm_fault(struct mm_struct *mm,struct vm_area_struct *vma, unsigned long address, int write_access);

 extern int make_pages_present(unsigned long addr, unsigned long end);

+extern int make_new_pages_present(unsigned long addr, unsigned long end);

 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);

 extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char *dst, int len);

 extern int ptrace_writedata(struct task_struct *tsk, char * src, unsigned long dst, int len);

diff -urN linux-2.4.0-test1/mm/memory.c linux/mm/memory.c

--- linux-2.4.0-test1/mm/memory.c	Tue May 16 04:00:33 2000

+++ linux/mm/memory.c	Wed Jun 14 19:24:58 2000

@@ -34,6 +34,8 @@

  *

  * 16.07.99  -  Support of BIGMEM added by Gerhard Wichert, Siemens AG

  *		(Gerhard.Wichert@pdb.siemens.de)

+ * 13.06.00  -  Support of PAGE_GH added by Naohiko Shimizu, Tokai Univ.

+                <nshimizu@keyaki.cc.u-tokai.ac.jp>

  */

 

 #include <linux/mm.h>

@@ -53,6 +55,12 @@

 void * high_memory;

 struct page *highmem_start_page;

 

+#ifndef CONFIG_PAGE_GH

+#define PAGE_GH_MASK (pgprot_t)0

+int page_gh_order[] = {0};

+pgprot_t page_gh_prot[] = {0};

+#endif

+

 /*

  * We special-case the C-O-W ZERO_PAGE, because it's such

  * a common occurrence (no need to read the page to know

@@ -716,8 +724,10 @@

                 pte_clear(pte);

 

                 mapnr = MAP_NR(__va(phys_addr));

-		if (mapnr >= max_mapnr || PageReserved(mem_map+mapnr))

+		if (mapnr >= max_mapnr || PageReserved(mem_map+mapnr) ||

+(pgprot_val(prot) & PAGE_GH_MASK)) {

                          set_pte(pte, mk_pte_phys(phys_addr, prot));

+		}

                 forget_pte(oldpage);

                 address += PAGE_SIZE;

                 phys_addr += PAGE_SIZE;

@@ -1226,6 +1236,31 @@

 }

 

 /*

+ * We will allocate phyical memory from the zone list, and map the

+ * pages to the PTEs with PAGE_GH bits. It will reduce the TLB miss and

+ * help the HPC applications. This routine is only called on the

+ * VM_LOCKED, then there is no need for COW/COA.

+ */

+int handle_mm_fault_pages(struct mm_struct *mm, struct vm_area_struct * vma,

+	unsigned long address, int write_access, int step)

+{

+	struct page *page;

+

+	if(step == 0)

+		return (handle_mm_fault(mm, vma, address, write_access) );

+	page = alloc_pages(GFP_HIGHUSER, page_gh_order[step]);

+	if (page == NULL)

+		return -1;

+	remap_page_range(address, (page - mem_map) << PAGE_SHIFT, 

+		         PAGE_SIZE << page_gh_order[step], 

+                         _PAGE_NORMAL(pgprot_val(page_gh_prot[step])));

+	flush_tlb_page(vma, address);

+	mm->rss += 1 << page_gh_order[step];

+/* you must clear the pages for the release level kernel */

+	return 0;

+}

+

+/*

  * Simplistic page force-in..

  */

 int make_pages_present(unsigned long addr, unsigned long end)

@@ -1242,6 +1277,47 @@

                 if (handle_mm_fault(mm, vma, addr, write) < 0)

                         return -1;

                 addr += PAGE_SIZE;

+	} while (addr < end);

+	return 0;

+}

+/*

+ * Simplistic new page allocation for sys_brk..

+ * On the case of VM_LOCKED, we will map the allocated pages into the

+ * coarse grain TLB entries(PAGE_GH).

+ */

+int make_new_pages_present(unsigned long addr, unsigned long end)

+{

+	int write;

+	struct mm_struct *mm = current->mm;

+	struct vm_area_struct * vma;

+

+	vma = find_vma(mm, addr);

+	write = (vma->vm_flags & VM_WRITE) != 0;

+	if (addr >= end)

+		BUG();

+	do { 

+		int i;

+		unsigned long rem;

+		for (i = 0; i< PAGE_GH_NR - 1; i++) {

+			rem = (~addr + 1) & ((PAGE_SIZE << page_gh_order[i+1]) - 1);

+			while (rem &&

+			    (addr & ((PAGE_SIZE << page_gh_order[i]) - 1)) == 0UL &&

+                            ((end - addr ) >= (PAGE_SIZE << page_gh_order[i]))) {

+				if (handle_mm_fault_pages(mm, vma, addr, write, i) < 0)

+					return -1;

+				addr += PAGE_SIZE << page_gh_order[i];

+				rem  -= PAGE_SIZE << page_gh_order[i];

+			};

+		}

+		for (i = PAGE_GH_NR - 1; i >= 0; i--) {

+			while (

+			    (addr & ((PAGE_SIZE << page_gh_order[i]) - 1)) == 0UL &&

+                            ((end - addr ) >= (PAGE_SIZE << page_gh_order[i]))) {

+				if (handle_mm_fault_pages(mm, vma, addr, write, i) < 0)

+					return -1;

+				addr += PAGE_SIZE << page_gh_order[i];

+			};

+		}

         } while (addr < end);

         return 0;

 }

diff -urN linux-2.4.0-test1/mm/mmap.c linux/mm/mmap.c

--- linux-2.4.0-test1/mm/mmap.c	Thu Apr 27 01:11:32 2000

+++ linux/mm/mmap.c	Tue Jun 13 16:42:29 2000

@@ -817,7 +817,12 @@

         mm->total_vm += len >> PAGE_SHIFT;

         if (flags & VM_LOCKED) {

                 mm->locked_vm += len >> PAGE_SHIFT;

-		make_pages_present(addr, addr + len);

+	/*

+	 * brk provide new pages and we have the chance to set the

+         * PAGE_GH bits for TLB, then we call make_new_pages_present

+	 * instead of make_pages_present. <N.Shimizu>

+	 */

+		make_new_pages_present(addr, addr + len);

         }

         return addr;

 }

image/x-xbitmap attachment: gemm-gh.c

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-06-14 12:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-06-14 12:03 [High-perf] page granuality hints support for kernel-2.4.0-test1 Naohiko Shimizu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox