*BSD News Article 6935


Return to BSD News archive

Path: sserve!manuel.anu.edu.au!munnari.oz.au!sgiblab!darwin.sura.net!Sirius.dfn.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!dkuug!dkuug!flshub!phk
From: phk@data.fls.dk (Poul-Henning Kamp)
Newsgroups: comp.unix.bsd
Subject: [386bsd] PATCH: performance of kernel improved 16.6%
Message-ID: <1992Oct22.194403.19713@data.fls.dk>
Date: 22 Oct 92 19:44:03 GMT
Organization: FLS Data A/S, Valby, Copenhagen, Denmark.
Lines: 200

What is does:
=============
	This patch cuts a quite large chunk of the processing in the kernel.
	For some unfortunate reasons pmap.c is a focal point from a performance
	point of view, this patch improves things a bit, but it is still the
	most used routine in the kernel.  The 16.6% is actually the percentage
	'system-time' is cut when doing a make kernel on my machine.

What to do:
===========
	Apply all of the applicable patches from the 'patch-kit'.
	Apply patch with:
		patch -d/ -p0 < patch_file

	rebuild your kernel.


enjoy,
	Poul-Henning
		

diff -r -C2 /ref/usr/src/sys.386bsd//i386/i386/pmap.c /usr/src/sys.386bsd//i386/i386/pmap.c
*** /ref/usr/src/sys.386bsd//i386/i386/pmap.c	Sun Jul 12 16:27:37 1992
--- /usr/src/sys.386bsd//i386/i386/pmap.c	Thu Oct 22 11:46:33 1992
***************
*** 537,551 ****
  void
  pmap_remove(pmap, sva, eva)
! 	register struct pmap *pmap;
! 	vm_offset_t sva, eva;
  {
! 	register vm_offset_t pa, va;
! 	register pt_entry_t *pte;
! 	register pv_entry_t pv, npv;
! 	register int ix;
! 	pmap_t ptpmap;
! 	int *pde, s, bits;
! 	boolean_t firstpage = TRUE;
! 	boolean_t flushcache = FALSE;
  #ifdef DEBUG
  	pt_entry_t opte;
--- 537,551 ----
  void
  pmap_remove(pmap, sva, eva)
! 	struct pmap *pmap;
! 	register vm_offset_t sva;
! 	register vm_offset_t eva;
  {
! 	register pt_entry_t *ptp,*ptq;
! 	vm_offset_t va;
! 	vm_offset_t pa;
! 	pt_entry_t *pte;
! 	pv_entry_t pv, npv;
! 	int ix;
! 	int s, bits;
  #ifdef DEBUG
  	pt_entry_t opte;
***************
*** 558,565 ****
  		return;
  
  #ifdef DEBUG
  	remove_stats.calls++;
  #endif
! 	for (va = sva; va < eva; va += PAGE_SIZE) {
  		/*
  		 * Weed out invalid mappings.
--- 558,586 ----
  		return;
  
+ 	/* are we current address space or kernel? */
+ 	if (pmap->pm_pdir[PTDPTDI].pd_pfnum == PTDpde.pd_pfnum
+ 		|| pmap == kernel_pmap)
+ 		ptp=PTmap;
+ 
+ 	/* otherwise, we are alternate address space */
+ 	else {
+ 		if (pmap->pm_pdir[PTDPTDI].pd_pfnum
+ 			!= APTDpde.pd_pfnum) {
+ 			APTDpde = pmap->pm_pdir[PTDPTDI];
+ 			tlbflush();
+ 		}
+ 		ptp=APTmap;
+ 	     }
  #ifdef DEBUG
  	remove_stats.calls++;
  #endif
! 	
! 	/* this is essential since we must check the PDE(sva) for precense */
! 	while (sva <= eva && !pmap_pde_v(pmap_pde(pmap, sva)))
! 		sva = (sva & PD_MASK) + (1<<PD_SHIFT);
! 	sva = i386_btop(sva);
! 	eva = i386_btop(eva);
! 
! 	for (; sva < eva; sva++) {
  		/*
  		 * Weed out invalid mappings.
***************
*** 567,579 ****
  	 	 * always allocated, and in kernel virtual.
  		 */
! 		if (!pmap_pde_v(pmap_pde(pmap, va)))
! 			continue;
  
! 		pte = pmap_pte(pmap, va);
! 		if (pte == 0)
  			continue;
  		pa = pmap_pte_pa(pte);
! 		if (pa == 0)
! 			continue;
  #ifdef DEBUG
  		opte = *pte;
--- 588,615 ----
  	 	 * always allocated, and in kernel virtual.
  		 */
! 		ptq=ptp+sva;
! 		while((sva & 0x3ff) && !pmap_pte_pa(ptq))
! 		    {
! 		    if(++sva >= eva)
! 		        return;
! 		    ptq++;
! 		    }		    
! 
  
! 		if(!(sva & 0x3ff)) /* Only check once in a while */
!  		    {
! 		    if (!pmap_pde_v(pmap_pde(pmap, i386_ptob(sva))))
! 			{
! 			/* We can race ahead here, straight to next pde.. */
! 			sva = (sva & 0xffc00) + (1<<10) -1 ;
  			continue;
+ 			}
+ 		    }
+ 	        if(!pmap_pte_pa(ptp+sva))
+ 		    continue;
+ 
+ 		pte = ptp + sva;
  		pa = pmap_pte_pa(pte);
! 		va = i386_ptob(sva);
  #ifdef DEBUG
  		opte = *pte;
***************
*** 744,747 ****
--- 780,784 ----
  	int i386prot;
  	boolean_t firstpage = TRUE;
+ 	register pt_entry_t *ptp;
  
  #ifdef DEBUG
***************
*** 759,762 ****
--- 796,813 ----
  		return;
  
+ 	/* are we current address space or kernel? */
+ 	if (pmap->pm_pdir[PTDPTDI].pd_pfnum == PTDpde.pd_pfnum
+ 		|| pmap == kernel_pmap)
+ 		ptp=PTmap;
+ 
+ 	/* otherwise, we are alternate address space */
+ 	else {
+ 		if (pmap->pm_pdir[PTDPTDI].pd_pfnum
+ 			!= APTDpde.pd_pfnum) {
+ 			APTDpde = pmap->pm_pdir[PTDPTDI];
+ 			tlbflush();
+ 		}
+ 		ptp=APTmap;
+ 	     }
  	for (va = sva; va < eva; va += PAGE_SIZE) {
  		/*
***************
*** 773,778 ****
  		}
  
! 		pte = pmap_pte(pmap, va);
! 		if (pte == 0) panic("pmap_protect: cannot happen");
  
  		/*
--- 824,828 ----
  		}
  
! 		pte = ptp + i386_btop(va);
  
  		/*
diff -r -C2 /ref/usr/src/sys.386bsd//vm/vm_pager.c /usr/src/sys.386bsd//vm/vm_pager.c
*** /ref/usr/src/sys.386bsd//vm/vm_pager.c	Tue Dec 24 14:24:23 1991
--- /usr/src/sys.386bsd//vm/vm_pager.c	Thu Oct 22 11:42:03 1992
***************
*** 233,237 ****
  	m = PHYS_TO_VM_PAGE(pmap_extract(vm_map_pmap(pager_map), kva));
  #endif
- 	pmap_remove(vm_map_pmap(pager_map), kva, kva + PAGE_SIZE);
  	kmem_free_wakeup(pager_map, kva, PAGE_SIZE);
  #ifdef DEBUG
--- 233,236 ----
-- 
phk@data.fls.dk		  || 			$HOME
Poul-Henning Kamp	  ||	
FLS DATA A/S		  ||			sweet
Phone: (+45) 36 18 12 35  ||